如何从XSD解析根元素

时间:2018-11-30 09:52:44

标签: java xml parsing xsd schema

我对XSD解析有疑问。

如何使用Java解析XSD的根元素?

这里是一个例子:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns="http://beep2000/client/beep.de" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://beep2000/client/beep.de">

....

<xsd:complexType name="RequestEnvelope">
                <xsd:sequence>
                    <xsd:element name="Title" type="xsd:string" minOccurs="0"/>
                    <xsd:element name="Forename" type="xsd:string" minOccurs="0"/>
                    <xsd:element name="Surname" type="xsd:string" minOccurs="1"/>
                    <xsd:element name="PersonalID" minOccurs="0">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:string">
                                <xsd:maxLength value="20"/>
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:element>
                    <xsd:element name="Adress" type="AdressType" minOccurs="0"/>
                    <xsd:element name="Body" type="BodyType" minOccurs="0"/>
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="ResponseEnvelope">
                <xsd:sequence>
                    <xsd:element name="Result" minOccurs="1">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:string">
                                <xsd:maxLength value="3"/>
                                <xsd:enumeration value="OK"/>
                                <xsd:enumeration value="NOK"/>
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:element>
                    <xsd:element name="Errorcode" type="xsd:integer" minOccurs="0"/>
                    <xsd:element name="Errortext" minOccurs="0">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:string">
                                <xsd:maxLength value="255"/>
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:element>
                    <xsd:element name="Comment" type="TextType" minOccurs="0"/>
                </xsd:sequence>
            </xsd:complexType>
            <xsd:element name="MsgResponse" type="ResponseEnvelope"/>
            <xsd:element name="MsgRequest" type="RequestEnvelope"/>
   </xsd:schema>

我想解析“ MsgRequest”和“ MsgResponse”。

我该如何解决?

亲切的问候

谢谢!

0 个答案:

没有答案