读书人

jdom建xml有关问题

发布时间: 2012-04-16 16:20:04 作者: rapoo

jdom建xml问题
受不了了,下面段代码,报缺少root,各位帮我看看哪里出问题了,谢谢!
response.setContentType( "application/xml ");
Document doc = new Document();
Element root = new Element( "dataschemas ");

Element table1=new Element( "customer ");
table1.addContent(new Element( "1 ").addContent( "id:Integer "));
table1.addContent(new Element( "2 ").addContent( "name:varchar(30) "));
table1.addContent(new Element( "3 ").addContent( "tel:varchar(32) "));

Element table2=new Element( "employee ");
table2.addContent(new Element( "1 ").addContent( "id:Integer "));
table2.addContent(new Element( "2 ").addContent( "name:varchar(30) "));
table2.addContent(new Element( "3 ").addContent( "tel:varchar(32) "));


Element schema1=new Element( "iit ");

schema1.addContent(table1);
schema1.addContent(table2);


root.addContent(schema1);

doc.addContent(root);

XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setEncoding( "ISO8859-1 "));

outputter.output(doc,response.getWriter());



[解决办法]
doc.addContent(root);改成 doc.setRootElement(root);试试看
[解决办法]
table1.addContent(new Element( "1 ").addContent( "id:Integer "));
这些是错的。XML元素不能以数字开头。

读书人网 >XML SOAP

热点推荐