Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
解析XML模式中的类型。JAVA_Java_Xml_Xsd_Jaxb - Fatal编程技术网

解析XML模式中的类型。JAVA

解析XML模式中的类型。JAVA,java,xml,xsd,jaxb,Java,Xml,Xsd,Jaxb,在我面前有一个问题——完整的模式解析(包含、导入、重定义)。问题甚至不是解析模式,而是从这个模式解析类型。 为了解释这个问题,下面是一个例子: schema.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

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

schema.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>
<?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>

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

使用xjc编译器;它接受一个有效的xsd&创建POJOs@Zaki,可以链接这些方法或示例的文档吗?
{
    "ServiceCode": {"string", String.class, "Service code"},
    "MessageClass": {"string", {"REQUEST":"Request from client","RESPONSE":"Response to client"}, ""}
}