locked
How To Get Rid Of Wrapper Root Node From Mapped XML Output RRS feed

  • Question

  • Hello,

    I am trying to map xml files in biztalk server 2009. Both the input and output schema are in xml format. The requirement is to get only repeating nods in the output xml, but the xml I received as an output always have one wrapper root node.

    Is there any way to get rid of this root node from XML output file??

     

    Friday, July 2, 2010 2:37 PM

Answers

  • You have to write a custom pipeline component on assembler stage. Think about it as a flatfile assembler, but matching you needs.

    Information regarding pipeline component development you can find here: http://msdn.microsoft.com/en-us/library/aa559443(v=BTS.70).aspx


    If you like my post or consider it as a valid answer, please use the buttons to show me - Oliver

    http://biztalk.hauth.me

    Monday, July 5, 2010 7:31 AM
  • Hi,

    As Greg points out removing xml root node results in not-well formed xml! You can use BizTalk Pipeline Component Wizard (V2.10) to add in building a custom pipeline to remove the root nodes.  

    HTH

    Regards,

    Steef-Jan Wiggers
    MCTS BizTalk Server
    http://soa-thoughts.blogspot.com/
    If this answers your question please mark it accordingly

     


    BizTalk
    Monday, July 5, 2010 8:21 AM
    Moderator
  • Typically in Xslt you would output a root node then iterate over the nodes
    <xsl:template match="/">
       <xsl:element name="root">
           <xsl:for-each select="/root/childnode">
               <xsl:element name="node"/>
           </xsl:for-each>
       </xsl:element>
    </xsl:template>

    To remove the root node simply remove the <xsl:element> for the root node:
    <xsl:template match="/">
        <xsl:for-each select="/root/childnode">
            <xsl:element name="node"/>
        </xsl:for-each>
    </xsl:template>

    This will produce the output you require, but will not be valid Xml. You will not be able to use maps, xpath functions or anything that will manipulate this message as Xml.

    Can you explain a bit more about your process. Why do you wish to remove the root node?

    Monday, July 5, 2010 8:37 AM
    Answerer
  • Are you using the SendPipelineService to  aggregate the Xml messages. If so then this will probably fail if you strip the root node and pass it bad Xml.

    A better approach would be to aggregate the Xml messages into a wrapped message:
    <aggregatedRoot>
       <message>
           <node1/>
           <node2/>
       </message>
       <message>
           <node3/>
           <node4/>
       </message>
    </aggregatedRoot>

    And then use a map to transform this message back into the original format
     <message>
         <node1/>
         <node2/>
         <node3/>
         <node4/>
     </message>

    Monday, July 5, 2010 11:24 AM
    Answerer

All replies

  • Not with standard tools during orchestration as this identifies the message type in BizTalk (message type = namespace#rootnode). The only chance is to write a custom send pipeline with a custom pipeline component that cuts off this rootnode just before writing the file to disk.

    If you like my post or consider it as a valid answer, please use the buttons to show me - Oliver

    http://biztalk.hauth.me

    Friday, July 2, 2010 3:05 PM
  • You will not be able to do this with a BizTalk map, however you can do this with custom Xslt.

    Be aware, that without a root node you message will no longer be well formed Xml.

    Sunday, July 4, 2010 9:10 PM
    Answerer
  • You will not be able to do this with a BizTalk map, however you can do this with custom Xslt.

    Be aware, that without a root node you message will no longer be well formed Xml.


    Greg, Can you please explain more on how can I remove root node using custom XSLT, I want to do this as an intermediate process, later I will wrap all the repeating nodes with root node and add a header.
    Monday, July 5, 2010 4:28 AM
  • Not with standard tools during orchestration as this identifies the message type in BizTalk (message type = namespace#rootnode). The only chance is to write a custom send pipeline with a custom pipeline component that cuts off this rootnode just before writing the file to disk.

    If you like my post or consider it as a valid answer, please use the buttons to show me - Oliver

    http://biztalk.hauth.me


    Oliver, If you think this can be done in custom pipeline, can you please throw some light on how can I remove root node from the fetched message using send pipeline.
    Monday, July 5, 2010 4:32 AM
  • You have to write a custom pipeline component on assembler stage. Think about it as a flatfile assembler, but matching you needs.

    Information regarding pipeline component development you can find here: http://msdn.microsoft.com/en-us/library/aa559443(v=BTS.70).aspx


    If you like my post or consider it as a valid answer, please use the buttons to show me - Oliver

    http://biztalk.hauth.me

    Monday, July 5, 2010 7:31 AM
  • Hi,

    As Greg points out removing xml root node results in not-well formed xml! You can use BizTalk Pipeline Component Wizard (V2.10) to add in building a custom pipeline to remove the root nodes.  

    HTH

    Regards,

    Steef-Jan Wiggers
    MCTS BizTalk Server
    http://soa-thoughts.blogspot.com/
    If this answers your question please mark it accordingly

     


    BizTalk
    Monday, July 5, 2010 8:21 AM
    Moderator
  • Typically in Xslt you would output a root node then iterate over the nodes
    <xsl:template match="/">
       <xsl:element name="root">
           <xsl:for-each select="/root/childnode">
               <xsl:element name="node"/>
           </xsl:for-each>
       </xsl:element>
    </xsl:template>

    To remove the root node simply remove the <xsl:element> for the root node:
    <xsl:template match="/">
        <xsl:for-each select="/root/childnode">
            <xsl:element name="node"/>
        </xsl:for-each>
    </xsl:template>

    This will produce the output you require, but will not be valid Xml. You will not be able to use maps, xpath functions or anything that will manipulate this message as Xml.

    Can you explain a bit more about your process. Why do you wish to remove the root node?

    Monday, July 5, 2010 8:37 AM
    Answerer
  • Typically in Xslt you would output a root node then iterate over the nodes
    <xsl:template match="/">
       <xsl:element name="root">
           <xsl:for-each select="/root/childnode">
               <xsl:element name="node"/>
           </xsl:for-each>
       </xsl:element>
    </xsl:template>

    To remove the root node simply remove the <xsl:element> for the root node:
    <xsl:template match="/">
        <xsl:for-each select="/root/childnode">
            <xsl:element name="node"/>
        </xsl:for-each>
    </xsl:template>

    This will produce the output you require, but will not be valid Xml. You will not be able to use maps, xpath functions or anything that will manipulate this message as Xml.

    Can you explain a bit more about your process. Why do you wish to remove the root node?


    Thanks Greg,

    Actually I am trying to merge multiple xml files of the same type.

    http://social.msdn.microsoft.com/Forums/en-US/biztalkesb/thread/c4cd632e-eca1-4987-9797-dd29e6c558fc

    As a part of this I am able to merge all the xml files but each file repeats with their root element in merged file. I was thinking if I can be able to remove root element than my merged file will have only child elements as a whole and then I will wrap the entire file with single root node.

    Do suggest.

    Monday, July 5, 2010 10:29 AM
  • Are you using the SendPipelineService to  aggregate the Xml messages. If so then this will probably fail if you strip the root node and pass it bad Xml.

    A better approach would be to aggregate the Xml messages into a wrapped message:
    <aggregatedRoot>
       <message>
           <node1/>
           <node2/>
       </message>
       <message>
           <node3/>
           <node4/>
       </message>
    </aggregatedRoot>

    And then use a map to transform this message back into the original format
     <message>
         <node1/>
         <node2/>
         <node3/>
         <node4/>
     </message>

    Monday, July 5, 2010 11:24 AM
    Answerer