【发布时间】:2010-08-04 07:23:56
【问题描述】:
我一直在尝试解析一个(实际上 - 许多)xsd 文件以写出元素名称列表、相应的元素类型和文档。
我研究了 XSOM、SAXParser、Xerces、JAXP - 所有这些都使读取 xml 和读取节点变得容易。在不等同于元素名称的情况下读取 xsd(以获取所有元素名称的列表)似乎很困难。 parser.parse 与我尝试过的大多数库都可以正常工作(因为 XSD 是格式良好的 xml),但我无法超越(提取所有元素名称)。
我错过了什么吗?有人遇到过类似问题吗?
以下是 xsd 示例:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://abc.mycompany.com/dto/address" targetNamespace="http://abc.mycompany.com/sdo/address">
<xs:complexType name="Address">
<xs:sequence>
<xs:element name="address1" minOccurs="0">
<xs:annotation>
<xs:documentation>USPS standardized address: building number, street name, apartment/suite number, and directionals (e.g., NE, SE, NW, SW).</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:normalizedString">
<xs:maxLength value="100" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="address2" minOccurs="0">
<xs:annotation>
<xs:documentation>Additional field for wrapping long addresses.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:normalizedString">
<xs:maxLength value="100" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="city" minOccurs="0">
<xs:annotation>
<xs:documentation>Name of the city, town or village.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:normalizedString">
<xs:maxLength value="26" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="state" type="xs:normalizedString" minOccurs="0" >
<xs:annotation>
<xs:documentation>A pick list of two-letter abbreviations representing US states,
military post offices, US protectorates, and Canadian provinces.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="zipCode" type="xs:normalizedString" minOccurs="0" >
<xs:annotation>
<xs:documentation>The first 5 digits of a 9-digit (Zip+4) zip code,
used to geographically locate a US address.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
【问题讨论】: