当前位置: 代码迷 >> J2EE >> XMLBeans 输出XML文本的格式有关问题
  详细解决方案

XMLBeans 输出XML文本的格式有关问题

热度:233   发布时间:2016-04-22 03:37:14.0
XMLBeans 输出XML文本的格式问题
使用过XMLBeans的朋友: 

在调用XXXType.toString 或 XXXType.XmlText()的时候,生成的XML包含了URI等信息,如下所示: 
<InputField Name="TroubleDescription" GetFunction="getTroubleDescription" xmlns="http://hp.com/ism/ovsc/jsr91/fm/objectmapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/> 

我想要的效果应该是不包括URI的: 
<InputField Name="TroubleDescription" GetFunction="getTroubleDescription"> 

请问该如何调整输出XML的格式? thx so much

------解决方案--------------------
用String xmlText(XmlOptions options)
Just like xmlText() but with options. Options map may be null. 
Note that this method does not produce XML with the XML declaration, including the encoding information. 


 XmlOptions opts = new XmlOptions();
 opts.setSavePrettyPrint();
 opts.setSavePrettyPrintIndent(4);
 System.out.println(xobj.xmlText(opts));

 The alternative is single-line usage: 
 System.out.println(xobj.xmlText(new XmlOptions().setSavePrettyPrint().setSavePrettyPrintIndent(4)));