搜索带有complexType节点的嵌套XSD

2024-09-27 09:25:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的XSD文件,我想使用Python遍历元素J67a下的所有节点,并检查name='Text\u MSG\u 35x\u Type'的标记,如果找到,则返回元素J67a的第一个子元素,在本例中,它应该是J67D。元素使用complexType和simpleType引用进行嵌套。有没有一种方法可以使用Python搜索这些节点?怎么做?你知道吗

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:info="xsd:appInfo" xmlns="xsd:2018" targetNamespace="xsd:2018" elementFormDefault="qualified">
    <xs:element name="Document" type="Document"/>
    <xs:complexType name="mt" abstract="true"/>
    <xs:complexType name="Sequence" abstract="true"/>
    <xs:complexType name="Choice" abstract="true"/>
    <xs:complexType name="Document">
        <xs:sequence>
            <xs:element name="mt1" type="MT1_Type"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="MT1_Type">
        <xs:complexContent>
            <xs:extension base="mt">
                <xs:sequence>
                    <xs:element name="J67a" type="MT1_J67a_Type" minOccurs="0"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="MT1_J67a_Type">
        <xs:complexContent>
            <xs:extension base="MTField">
                <xs:choice>
                    <xs:element name="J67A" type="J67A_Type">
                        <xs:annotation>
                            <xs:appinfo>
                                <info:Tag value="58A"/>
                            </xs:appinfo>
                        </xs:annotation>
                    </xs:element>
                    <xs:element name="J67D" type="J67D_Type">
                        <xs:annotation>
                            <xs:appinfo>
                                <info:Tag value="58D"/>
                            </xs:appinfo>
                        </xs:annotation>
                    </xs:element>
                </xs:choice>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="J67A_Type">
        <xs:complexContent>
            <xs:extension base="FieldOption">
                <xs:sequence>
                    <xs:element name="PartyIdentifier" type="Text_PartyId_Type" minOccurs="0">
                        <xs:annotation>
                            <xs:appinfo>
                                <info:SepSuffix value="&#x0d;&#x0a;"/>
                            </xs:appinfo>
                        </xs:annotation>
                    </xs:element>
                    <xs:element name="IdentifierCode" type="Identifier_BICFI_Type"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="J67D_Type">
        <xs:complexContent>
            <xs:extension base="FieldOption">
                <xs:sequence>
                    <xs:element name="PartyIdentifier" type="Text_PartyId_Type" minOccurs="0">
                        <xs:annotation>
                            <xs:appinfo>
                                <info:SepSuffix value="&#x0d;&#x0a;"/>
                            </xs:appinfo>
                        </xs:annotation>
                    </xs:element>
                    <xs:element name="NameAndAddress" type="Text_MSG_4M35x_Type"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:simpleType name="Text_PartyId_Type">
        <xs:annotation>
            <xs:appinfo>
                <info:MetaType value="Text"/>
                <info:MSGFormat value="[/1!a][/34x]"/>
            </xs:appinfo>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:minLength value="2"/>
            <xs:maxLength value="37"/>
            <xs:pattern value="/(C/|D/)?[0-9a-zA-Z/\-\?:\(\)\.,&apos;\+ ]{1,34}"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="Identifier_BICFI_Type">
        <xs:annotation>
            <xs:appinfo>
                <info:MetaType value="Identifier"/>
                <info:MSGFormat value="4!a2!a2!c[3!c]"/>
            </xs:appinfo>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:minLength value="8"/>
            <xs:maxLength value="11"/>
            <xs:pattern value="[A-Z]{4}[A-Z]{2}[0-9A-Z]{2}([0-9A-Z]{3})?"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:complexType name="Text_MSG_4M35x_Type">
        <xs:complexContent>
            <xs:extension base="ComplexDataType">
                <xs:sequence>
                    <xs:annotation>
                        <xs:appinfo>
                            <info:Separator value="&#x0d;&#x0a;"/>
                        </xs:appinfo>
                    </xs:annotation>
                    <xs:element name="Line" type="Text_MSG_35x_Type" maxOccurs="4"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:simpleType name="Text_MSG_35x_Type">
        <xs:annotation>
            <xs:appinfo>
                <info:MetaType value="Text"/>
                <info:MSGFormat value="35x"/>
            </xs:appinfo>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:minLength value="1"/>
            <xs:maxLength value="35"/>
            <xs:pattern value="[0-9a-zA-Z/\-\?:\(\)\.,&apos;\+ ]{1,35}"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

Tags: textnameinfobasevaluetypeextensionannotation

热门问题