日期:2014-05-20  浏览次数:20882 次

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)));