首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

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

2012-02-27 
XMLBeans 输出XML文本的格式问题使用过XMLBeans的朋友:在调用XXXType.toString 或 XXXType.XmlText()的时

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

热点排行