从XSD获取完整的XML结构
问题描述:
考虑到type
,ref
等,有没有办法将XML模式转换为Java对象树?我的意思是,借此从XSD获取完整的XML结构
<xs:element name="root">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="elem" type="type1">
</xs:all>
</xs:complexType>
</xs:element>
<xs:complexType name="type1">
<xs:sequence>
<xs:element name="A" type="xs:string"/>
<xs:element name="B" type="xs:string"/>
<xs:element name="C" type="xs:string"/>
<xs:any minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
,并作出树:根元素的“根”与孩子“ELEM”(具有显着的分和maxOccurs)。 “elem”也有孩子“A”,“B”,“C”和“任何”。
有没有这样的方式?有些图书馆可能? 如果不是,除了type
和ref
之外,我还应该考虑自己写这种线性化的东西吗?
答
是的,这是可能的。此实现设计得非常好 - 我自己使用它:http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.emf.doc%2Ftutorials%2Fxlibmod%2Fxlibmod.html
它基于Eclipse建模框架,但您不必安装所有的Eclipse以便使用它。
[从.XSD文件生成Java类...?]的可能重复(http://stackoverflow.com/questions/686453/generate-java-classes-from-xsd-files) – maraca
[** JAXB * *](https://jaxb.java.net/tutorial/) – kjhughes