2011-08-09 54 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();