none
Mapping an unbounded node to a single node RRS feed

  • Question

  • I'm having problems mapping a repeating record to a single record.
    The Roles node may contain many records.
    If at least one of the Roles\RoleName is equal to "Client" I need to set the "IsClient" element to 'Y' (or 'N' if "Client" is not present)

    Here is the source schema:


    <?xml version="1.0" encoding="utf-16"?>
    <xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://Symphony.CompanyRequest.Schema1" targetNamespace="http://Symphony.CompanyRequest.Schema1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="Company">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="CompanyId" type="xs:string" />
            <xs:element name="CompanyName" type="xs:string" />
            <xs:element name="CompanyRoles">
              <xs:complexType>
                <xs:sequence>
                  <xs:element maxOccurs="unbounded" name="Roles">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="RoleName" type="xs:string" />
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>

    Here is the dest schema


    <?xml version="1.0" encoding="utf-16"?>
    <xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://Symphony.CompanyRequest.Schema2" targetNamespace="http://Symphony.CompanyRequest.Schema2" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="CompanyRecord">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="Name" type="xs:string" />
            <xs:element name="CompanyId" type="xs:string" />
            <xs:element name="IsClient" type="xs:string" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>

    If I send it this xml


    <ns0:Company xmlns:ns0="http://Symphony.CompanyRequest.Schema1">
      <CompanyId>2345</CompanyId>
      <CompanyName>John's Smoke Shop</CompanyName>
      <CompanyRoles>
        <Roles>
          <RoleName>Vendor</RoleName>
        </Roles>
        <Roles>
          <RoleName>Client</RoleName>
        </Roles>
      </CompanyRoles>
    </ns0:Company>

    I want it to come out like this


    <ns0:CompanyRecord xmlns:ns0="http://Symphony.CompanyRequest.Schema2">
      <Name>John's Smoke Shop</Name>
      <CompanyId>2345</CompanyId>
      <IsClient>Y</IsClient>
    </ns0:CompanyRecord>

    Any help on this problem is appreciated.
    • Edited by MillaT Wednesday, July 8, 2009 4:06 PM
    Wednesday, July 8, 2009 4:01 PM

Answers

  • Hi,

    There are couple ways you can do it. I would use Cumulative Concatenate functoid with scope "0" and accumulate all the RoleName and then in the scripting Functoid check if it contains "Client", if yes the return Y else N.

    Also can use separator between each RoleName. To do this use a String Concatenate and RoleName as 1st parameter and seperator as 2nd parameter say "|" and then connect to Cumulative Concatenate and then use the below script to check if Client is present in the string
    Script:

    public string GetIsClient(string RoleName)
    {
    RoleName=RoleName.ToUpper();
    if(RoleName.Contains("CLIENT"))
    return "Y";
    else
    return "N";
    }
    Ajeet Kumar
    • Marked as answer by MillaT Thursday, July 9, 2009 11:56 AM
    Thursday, July 9, 2009 6:27 AM

All replies

  • Hi,

    There are couple ways you can do it. I would use Cumulative Concatenate functoid with scope "0" and accumulate all the RoleName and then in the scripting Functoid check if it contains "Client", if yes the return Y else N.

    Also can use separator between each RoleName. To do this use a String Concatenate and RoleName as 1st parameter and seperator as 2nd parameter say "|" and then connect to Cumulative Concatenate and then use the below script to check if Client is present in the string
    Script:

    public string GetIsClient(string RoleName)
    {
    RoleName=RoleName.ToUpper();
    if(RoleName.Contains("CLIENT"))
    return "Y";
    else
    return "N";
    }
    Ajeet Kumar
    • Marked as answer by MillaT Thursday, July 9, 2009 11:56 AM
    Thursday, July 9, 2009 6:27 AM
  • I like it. It works perfectly.
    Thanks for your help.
    Thursday, July 9, 2009 11:56 AM