1

摆在我面前的是一个问题——完整的模式解析(包含、导入、重新定义)。问题甚至不是解析方案,而是从这个模式中解析类型。为了解释这个问题,这里有一个例子:

架构.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:myprefix="http://myhost.ru/service/" xmlns:anprefix="http://anotherhost.ru/pub-service/" targetNamespace="http://myhost.ru/service/">
    <xs:import namespace="http://anotherhost.ru/pub-service/" schemaLocation="anotherhost_schema.xsd"/>

    <xs:complexType>
        <xs:sequence>
            <xs:element name="ServiceCode" type="anprefix:ServiceCodeType">
                <xs:annotation>
                    <xs:documentation>Service code</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="MessageClass" type="myprefix:MessageClassType"/>
        </xs:sequence>
    </xs:complexType>

    <xs:simpleType name="MessageClassType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="REQUEST">
                <xs:annotation>
                    <xs:documentation>Request from client
                    </xs:documentation>
                </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="RESPONSE">
                <xs:annotation>
                    <xs:documentation>Response to client</xs:documentation>
                </xs:annotation>
            </xs:enumeration>
        </xs:restriction>
    </xs:simpleType>

</xs:schema>

另一个host_schema.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:anprefix="http://anotherhost.ru/pub-service/" targetNamespace="http://anotherhost.ru/pub-service/">
    <xs:simpleType name="ServiceCodeType">
        <restriction base="xs:string">
        </restriction>
    </xs:simpleType>
</xs:schema>

例子不是很难,真正的问题要大得多。我的问题是解析模式并创建它的内部表示(表单生成器和请求处理程序将使用),例如,如下所示:

{
    "ServiceCode": {"string", String.class, "Service code"},
    "MessageClass": {"string", {"REQUEST":"Request from client","RESPONSE":"Response to client"}, ""}
}

内部表示可以是多种多样的,但在 Java 中使用起来很简单。有这样的图书馆吗?我知道,有一个名为 JAXB 的库,专门为 XML 解析而创建,但我不明白如何将它绑定到我的问题。

4

0 回答 0