locked
Adding xsi:type explicitly in the xml node RRS feed

Answers

  • You have two choices set the xsi:type attribute in a map or manipulate the resulting xml message.

    Using a map:
    1. Add a scripting functoid, using Inline XSLT Template
    2. Paste this code

    <xsl:template name="specifytype">
      <xsl:param name="value" />
      <Value xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <xsl:attribute name="xsi:type">
        <xsl:value-of select="'xs:string'" />
       </xsl:attribute>
       <xsl:value-of select="." />
      </Value>
     </xsl:template>
    

    3. Connect the input node to this functoid
    4. Connect this functoid to the Value node in the output

    Thursday, December 16, 2010 1:50 AM
    Answerer
  • Hi Amit,

    Please use below script.

    <xsl:template name="specifytype" xmlns:ns0="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09">
      <xsl:param name="Value" />
      <ns0:Value xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <xsl:attribute name="xsi:type">
        <xsl:value-of select="'xs:string'" />
       </xsl:attribute>
       <xsl:value-of select="Value" />
      </ns0:Value>
     </xsl:template>


    Ayaz Shaikh
    Thursday, February 3, 2011 9:08 AM

All replies

  • according to me as you have the xml file, there is a provision in BizTalk where you can generate a schema out of xml file.  After you retrieve the Schema change the datatype of the node you want in the properties.

    Hope this helps.

    -D

     

    Friday, December 10, 2010 5:32 AM
  • Hi singaraju,

    Changing the type in the schema does not work. It does not add type (i.e. xsi:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema" ) in the node. I need to explicitly add the type while transforming input xml to output xml (i.e. xml given as above) using map.


    Ayaz Shaikh
    Friday, December 10, 2010 9:07 AM
  • Hi,

    Below is my input xml

    <ns0:Request xmlns:ns0="http://MDSAddRecord.ClientRequest_Create">
      <MemberIdentification>
        <Name>Test1</Name>
        <Code>2020</Code>
      </MemberIdentification>
      <EntityMember>
        <Entity>Unit</Entity>
        <Model>ConnectMDM</Model>
        <Version>VERSION_1</Version>
      </EntityMember>
      <Attributes>
        <Attribute>
          <Name>Address1</Name>
          <Value>ABC</Value>
        </Attribute>
        <Attribute>
          <Name>Address2</Name>
          <Value>XYZ</Value>
        </Attribute>
      </Attributes>
    </ns0:Request>

    Now I need to convert this xml into below format so that it include " xsi:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema" " in the Value node.

    <ns0:EntityMembersCreateRequest xmlns:ns1="http://schemas.datacontract.org/2004/07/Microsoft.MasterDataServices.Services.DataContracts" xmlns:ns0="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09" xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <ns0:Members>
        <ns0:EntityId xsi:type="ns0:Identifier">
          <ns0:Name>Unit</ns0:Name>
        </ns0:EntityId>
        <ns0:Members>
          <ns0:Member>
            <ns0:Attributes>
              <ns0:Attribute>
                <ns0:Identifier xsi:type="ns0:Identifier">
                  <ns0:Name>Address1</ns0:Name>
                </ns0:Identifier>
                <ns0:Value  xsi:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema">ABC</ns0:Value>
              </ns0:Attribute>
              <ns0:Attribute>
                <ns0:Identifier xsi:type="ns0:Identifier">
                  <ns0:Name>Address2</ns0:Name>
                </ns0:Identifier>
                <ns0:Value  xsi:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema">XYZ</ns0:Value>
              </ns0:Attribute>
            </ns0:Attributes>
            <ns0:MemberId>
              <ns0:Name>Test1</ns0:Name>
              <ns0:Code>1010</ns0:Code>
              <ns0:MemberType>Leaf</ns0:MemberType>
            </ns0:MemberId>
          </ns0:Member>
        </ns0:Members>
        <ns0:ModelId xsi:type="ns0:Identifier">
          <ns0:Name>ConnectMDM</ns0:Name>
        </ns0:ModelId>
        <ns0:VersionId xsi:type="ns0:Identifier">
          <ns0:Name>VERSION_1</ns0:Name>
        </ns0:VersionId>
      </ns0:Members>
    </ns0:EntityMembersCreateRequest>

    So can I do this using Map or is there any other way to achieve this in BizTalk?


    Ayaz Shaikh
    Monday, December 13, 2010 12:11 PM
  • Hi,

    Actually if you are adding new node in your xml then you are changing the message and in BizTalk message are immutable . Better use contruct shape to create new message of new schema type.

     

    Thanks

     

     

    Monday, December 13, 2010 2:06 PM
  • Hi TanmoySarkar,

    I am not adding new node in xml. Value node is already there in targe schema as well. I need to add only xsi:type in the Value node.


    Ayaz Shaikh
    Monday, December 13, 2010 2:15 PM
  • Did u try using stylesheet for the map?

    see this link , this might help

    http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/201001/msg00166.html

    Monday, December 13, 2010 9:01 PM
  • Hi Amareswari,

    It doesn't help me. Please let me help to find the solution.


    Ayaz Shaikh
    Tuesday, December 14, 2010 8:52 AM
  • You have two choices set the xsi:type attribute in a map or manipulate the resulting xml message.

    Using a map:
    1. Add a scripting functoid, using Inline XSLT Template
    2. Paste this code

    <xsl:template name="specifytype">
      <xsl:param name="value" />
      <Value xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <xsl:attribute name="xsi:type">
        <xsl:value-of select="'xs:string'" />
       </xsl:attribute>
       <xsl:value-of select="." />
      </Value>
     </xsl:template>
    

    3. Connect the input node to this functoid
    4. Connect this functoid to the Value node in the output

    Thursday, December 16, 2010 1:50 AM
    Answerer
  • Hi  Greg

    It's working fine but my node is loosing the namespace information after the mapping.

     

    So the output comes like this :  < Value xsi:type =" xs:string " xmlns:xs =" http://www.w3.org/2001/XMLSchema " > 5000  </ Value

    Though the expected o/p should be : <ns0 : Value xsi:type =" xs:string " xmlns:xs =" http://www.w3.org/2001/XMLSchema " > 5000 < /ns0: Value

     

    Any suggestions
    Thursday, February 3, 2011 8:38 AM
  • Hi Amit,

    Please use below script.

    <xsl:template name="specifytype" xmlns:ns0="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09">
      <xsl:param name="Value" />
      <ns0:Value xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <xsl:attribute name="xsi:type">
        <xsl:value-of select="'xs:string'" />
       </xsl:attribute>
       <xsl:value-of select="Value" />
      </ns0:Value>
     </xsl:template>


    Ayaz Shaikh
    Thursday, February 3, 2011 9:08 AM
  • Worked like charm !!!....thanks Ayaz for a prompt reply
    Thursday, February 3, 2011 9:14 AM
  • Try this:

    <xsl:template name="specifytype">
      <xsl:param name="value" />
      <ns0:Value xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09">
       <xsl:attribute name="xsi:type">
        <xsl:value-of select="'xs:string'" />
       </xsl:attribute>
       <xsl:value-of select="'value'" />
      </ns0:Value>
     </xsl:template>
    
    Thursday, February 3, 2011 9:24 AM
    Answerer