Create XML (using XML Schema) with Scribe job: XML element must be omitted if specific attribute has value that does not fit the criteria

北城以北 提交于 2019-12-08 06:01:51

问题


I have written a Scribe Insight job, which transfers data from Sage ERP MAS to XML file. It runs successfully. Now, one more requirement got added to the job.

My current XML file looks like:

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

Now, if you notice the first <Organization> node properly, you will find out that Identifier="" in <OrganizationId> element, whereas in second node, Identifier attribute (in <OrganizationId> element) has 13-digit numeric value.

So, as per the new requirement, if Identifier has any value other than 13-digit numeric value, then do not include <OrganizationId> element in that node.

Now, how can I remove (at the time of creation of XML or after creating XML) the <OrganizationId> element, if Identifier has any value other than 13-digit numeric value?

My currrent XSD is:

<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>

来源:https://stackoverflow.com/questions/29807892/create-xml-using-xml-schema-with-scribe-job-xml-element-must-be-omitted-if-sp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!