【发布时间】:2019-12-27 19:46:19
【问题描述】:
我想获取 XSD 的数据类型。它必须是静态的,因为 XSD 可能是变化的。 就我而言,我知道元素名称。
XSD 的小样本,但可以更深入:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Order">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:float" name="OrderNo"/>
<xs:element type="xs:string" name="OrderDate"/>
<xs:element type="xs:string" name="Name"/>
<xs:element type="xs:float" name="NameNo"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我尝试使用 org.apache.xerces.xs,但不知道如何从根 Elem 获取带有接口 XSElementDeclaration 的对象 XSParticleDecl
我希望每个单独元素名称的输出都是类型。
【问题讨论】:
-
XSD 就是 XML。查看有关如何处理 XML 的一些教程。一个简单的解决方案是制作一个对 XML 进行建模的 Pojo,然后将其反序列化。
-
@user489041 我知道 XSD 的定义,但搜索起来不一样。由于泛型,Pojo 不是解决方案。
-
@Faer 你能用
Xerces做到吗?我需要在我的应用程序中实现类似的东西。我需要从 XSD 中获取 XML 中对象的数据类型。如果有小代码sn-p可以发在这里吗?