2011-08-09 46 views
2

我想问一下,如何打印XML模式。我在运行时创建我的xsd模式并进行测试,我希望看到生成的xml模式。目前我与org.apache.ws.commons.schema.XmlSchema工作,我找不到任何东西可以打印XML模式。如何打印XML模式

有没有人知道如何打印出我的XmlSchema

回答

3

尝试:

XMLOutputter outputter = new XMLOutputter(); 
     try { 
      String outputString = outputter.outputString(loXMLDoc); 
     } 

loXMLDoc是大教堂的XML模式

+1

可能会使用一个漂亮的格式: 的XMLOutputter输出器=新的XMLOutputter(Format.getPrettyFormat()); –

+0

我不知道我怎么样,我没有看到org.apache.ws.commons.schema.XmlSchema中的方法写(OutputStream)。这种方法正是我需要的。 ** xmlSchema.write(System.out); ** – moohkooh

1

如果你如果你正在使用的XmlSchema 1.x的

XmlSchema schema = ... 
... 
schema.write(System.out, null) 
使用的XmlSchema 2.0

XmlSchema schema = ... 
... 
schema.write(System.out) 

另外,如果你要写入字符串

StringWriter schemaWriter = new StringWriter(); 
schema.write(schemaWriter); 
String schemaString = schemaWriter.toString();