1

我写了一个Scribe Insight作业,将数据从文件传输Sage ERP MASXML文件。它运行成功。现在,这项工作又增加了一项要求。

我当前的 XML 文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>

<Entries>

<Organization MemberName="00-1234567" Comments="XYZ " FullName="XYZ  Name" OrgIdType="XYZ Type">

    <RelatedTo RelationType="PART_OF">

        <Group MemberName="00-1234567"/>

    </RelatedTo>

    <MemberInfo DynamicEntryType="CustomerInfo" InfoType="CustomerInfo.Independent" InternalSOR="FALSE" PaymentMethod="Credit"/>

    <MemberStatus StatusEnumValue="ACTIVE" EffectiveStartDate="2000-01-01" EffectiveEndDate="4700-12-31"/>

    <Address ImportAction="addModify" AddrType="SHIP_TO" AddrLine1="1234 Main Street" AddrLine2="" AddrCity="XYZ  City" AddrState="NY" AddrZip="11111" AddrCountry="US" AddrFlags="PRIMARY_ADDRESS"/>

    <AssociatedToOrg Name="Default"/>

    <OrganizationId ImportAction="addModify" Type="GLN" Identifier="" Primary="false" StartDate="2000-01-01"/>

</Organization>

<Organization MemberName="00-1234568" Comments=" " FullName="ABC Name" OrgIdType="ABC Type">

    <RelatedTo RelationType="PART_OF">

        <Group MemberName="00-1234568"/>

    </RelatedTo>

    <MemberInfo DynamicEntryType="CustomerInfo" InfoType="CustomerInfo.Independent" InternalSOR="FALSE" PaymentMethod="Credit"/>

    <MemberStatus StatusEnumValue="ACTIVE" EffectiveStartDate="2000-01-01" EffectiveEndDate="4700-12-31"/>

    <Address ImportAction="addModify" AddrType="SHIP_TO" AddrLine1="10 Main St" AddrLine2="" AddrCity="ABC City" AddrState="NY" AddrZip="11111" AddrCountry="US" AddrFlags="PRIMARY_ADDRESS"/>

    <AssociatedToOrg Name="Default"/>

    <OrganizationId ImportAction="addModify" Type="GLN" Identifier="1234567890123" Primary="false" StartDate="2000-01-01"/>

</Organization>

</Entries> 

现在,如果您正确地注意到第一个<Organization>节点,您会发现Identifier=""<OrganizationId>元素中,而在第二个节点中,Identifier属性(<OrganizationId>元素中)具有 13 位数值。

因此,根据新要求,如果Identifier具有 13 位数值以外的任何值,则不要<OrganizationId>在该节点中包含元素。

<OrganizationId>现在,如果元素Identifier具有 13 位数值以外的任何值,我该如何删除(在创建 XML 时或创建 XML 之后) ?

XSD的当前是:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Entries">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Organization" maxOccurs="unbounded" minOccurs="0">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="RelatedTo">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element name="Group">
                                        <xs:complexType>
                                            <xs:simpleContent>
                                                <xs:extension base="xs:string">
                                                    <xs:attribute type="xs:string" name="MemberName" use="optional"/>
                                                </xs:extension>
                                            </xs:simpleContent>
                                        </xs:complexType>
                                    </xs:element>
                                </xs:sequence>
                                <xs:attribute type="xs:string" name="RelationType" use="optional"/>
                            </xs:complexType>
                        </xs:element>
                        <xs:element name="MemberInfo">
                            <xs:complexType>
                                <xs:simpleContent>
                                    <xs:extension base="xs:string">
                                        <xs:attribute type="xs:string" name="DynamicEntryType" use="optional"/>
                                        <xs:attribute type="xs:string" name="InfoType" use="optional"/>
                                        <xs:attribute type="xs:string" name="InternalSOR" use="optional"/>
                                        <xs:attribute type="xs:string" name="PaymentMethod" use="optional"/>
                                    </xs:extension>
                                </xs:simpleContent>
                            </xs:complexType>
                        </xs:element>
                        <xs:element name="MemberStatus">
                            <xs:complexType>
                                <xs:simpleContent>
                                    <xs:extension base="xs:string">
                                        <xs:attribute type="xs:string" name="StatusEnumValue" use="optional"/>
                                        <xs:attribute type="xs:date" name="EffectiveStartDate" use="optional"/>
                                        <xs:attribute type="xs:date" name="EffectiveEndDate" use="optional"/>
                                    </xs:extension>
                                </xs:simpleContent>
                            </xs:complexType>
                        </xs:element>
                        <xs:element name="Address">
                            <xs:complexType>
                                <xs:simpleContent>
                                    <xs:extension base="xs:string">
                                        <xs:attribute type="xs:string" name="ImportAction" use="optional"/>
                                        <xs:attribute type="xs:string" name="AddrType" use="optional"/>
                                        <xs:attribute type="xs:string" name="AddrLine1" use="optional"/>
                                        <xs:attribute type="xs:string" name="AddrLine2" use="optional"/>
                                        <xs:attribute type="xs:string" name="AddrCity" use="optional"/>
                                        <xs:attribute type="xs:string" name="AddrState" use="optional"/>
                                        <xs:attribute type="xs:string" name="AddrZip" use="optional"/>
                                        <xs:attribute type="xs:string" name="AddrCountry" use="optional"/>
                                        <xs:attribute type="xs:string" name="AddrFlags" use="optional"/>
                                    </xs:extension>
                                </xs:simpleContent>
                            </xs:complexType>
                        </xs:element>
                        <xs:element name="AssociatedToOrg">
                            <xs:complexType>
                                <xs:simpleContent>
                                    <xs:extension base="xs:string">
                                        <xs:attribute type="xs:string" name="Name" use="optional"/>
                                    </xs:extension>
                                </xs:simpleContent>
                            </xs:complexType>
                        </xs:element>
                        <xs:element name="OrganizationId">
                            <xs:complexType>
                                <xs:simpleContent>
                                    <xs:extension base="xs:string">
                                        <xs:attribute type="xs:string" name="ImportAction" use="optional"/>
                                        <xs:attribute type="xs:string" name="Type" use="optional"/>
                                        <xs:attribute name="Identifier">
                                            <xs:simpleType>
                                                <xs:restriction base="xs:integer">
                                                    <xs:pattern value="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"/>
                                                </xs:restriction>
                                            </xs:simpleType>
                                        </xs:attribute>
                                        <xs:attribute type="xs:string" name="Primary" use="optional"/>
                                        <xs:attribute type="xs:date" name="StartDate" use="optional"/>
                                    </xs:extension>
                                </xs:simpleContent>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                    <xs:attribute type="xs:string" name="MemberName" use="optional"/>
                    <xs:attribute type="xs:string" name="Comments" use="optional"/>
                    <xs:attribute type="xs:string" name="FullName" use="optional"/>
                    <xs:attribute type="xs:string" name="OrgIdType" use="optional"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

4

0 回答 0