有没有一种方法可以将 XML 模式转换为 Java 对象树,同时考虑 type
、ref
等?我的意思是,拿这个
<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>
并创建一棵树:根元素“root”和子元素“elem”(标记为 min 和 maxOccurs)。 “elem”还有子“A”、“B”、“C”和“any”。
有这样的办法吗?也许是某个图书馆?
如果没有,除了 type
和 ref
之外,我应该考虑什么来自己编写这样的线性化东西?
最佳答案
是的,这是可能的。这个实现设计得非常好 - 我自己使用过它:http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.emf.doc%2Ftutorials%2Fxlibmod%2Fxlibmod.html
它基于 Eclipse Modeling Framework,但您不必安装所有 Eclipse 才能使用它。
关于java - 从 XSD 获取完整的 XML 结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33657414/