locked
Read value of repeating node in XML RRS feed

  • Question

  • Hello,

    my XML has some repeating nodes as:

    <Page ImportFileName="F:\Email_Import\CHI\10A2_0_memo.pdf" />

      <Page ImportFileName="F:\Email_Import\CHI\10A2_1_1749295799.pdf" />
    I need to read the values of each of these nodes either in orchestration or using C# componenet.
    What is the best way to do that?
    Friday, July 15, 2011 9:55 PM

Answers

  • You need to use the string function as shown below:

    sdocXpath= System.String.Format("string(/*[local-name()='DocImport' and namespace-uri()='']/*[local-name()='Document' and namespace-uri()='']/*[local-name()='DocumentName' and namespace-uri()=''][{0}]/text())",documentCount);


    Please mark as answer or vote as helpful if my reply does [Regards-Rohit Sharma http://rohitbiztalk.blogspot.com/]
    Wednesday, July 20, 2011 4:07 AM
    Moderator

All replies

  • Hello Rachana, I would try and use the orchestration first, let BizTalk tackle the work, other wise you will be looking at a component function, In the past I was involved in a implementation of documents, named similar to yours, (customer id, item id, unique id.doc = 723A1234A123.doc)  we ended up having the dev team write a component that used a set of regular expressions to standardize the attachement names and parse them and write them out in a unified standard.
    Friday, July 15, 2011 10:03 PM
  • You can use XPath to access the repaeting element see this post for more details.

     

    à sXPath = System.String.Format("//Item[{0}]",nCount);

    à xDoc = xpath(InXML, sXPath);

     


    Please mark as answer or vote as helpful if my reply does [Regards-Rohit Sharma http://rohitbiztalk.blogspot.com/]
    • Proposed as answer by bharatsahani Tuesday, October 2, 2012 9:29 AM
    • Unproposed as answer by bharatsahani Tuesday, October 2, 2012 9:29 AM
    • Proposed as answer by bharatsahani Tuesday, October 2, 2012 9:29 AM
    Saturday, July 16, 2011 5:57 AM
    Moderator
  • The ImportFileName is an attribute of the repeating element Page. So xpath would have @ for fetching the attribute value.

    strXpath = System.String.Format("//Page[{0}]/@ImportFileName", index);

    strImportFileName = xpath(Msg, strXpath);


    Abdul Rafay - MVP & MCTS BizTalk Server
    blog: http://abdulrafaysbiztalk.wordpress.com/
    Please indicate "Mark as Answer" if this post has answered the question.
    • Proposed as answer by bharatsahani Tuesday, October 2, 2012 9:29 AM
    Sunday, July 17, 2011 5:43 AM
  • Ok, this is my XML structure with repeating elements:

    <Document>

    <DocumentName>C:\Users\Administrator\Desktop\Release\Images\INV1642011391658522043.tif</DocumentName>

    <DocumentName>C:\Users\Administrator\Desktop\Release\Images\INV1642011391658522902.tif</DocumentName>

    <DocumentName>C:\Users\Administrator\Desktop\Release\Images\INV1642011391658523586.tif</DocumentName>

    </Document>

    In my orchestration, I get the correct count of repeating nodes. I then use a looping share to loop through all the Document Name nodes and try to extract the DocumentName Value. However it retiuns blank.

    This is my xpath:documentCount is the value of the DocumentName elements.

    sdocXpath= System.String.Format("/*[local-name()='DocImport' and namespace-uri()='']/*[local-name()='Document' and namespace-uri()='']/*[local-name()='DocumentName' and namespace-uri()=''][1]/text()",documentCount);
    DocumentNames=xpath(msgFESInternal.FESInternalMessage,sdocXpath);
     

    What am I doing wrong here?The xpath editor returns correct value of the node.


    Monday, July 18, 2011 8:12 PM
  • If you want to use C# then try this...

    Assign your xml message to xml document.

    use oXml.SelectNodes(//Page...)

    then get the count and do whatever is needed to be done with that collection.

     

    Cheers.


    Hemant Bhadane MCTS - BizTalk Server
    Tuesday, July 19, 2011 1:35 AM
  • Ok, this is my XML structure with repeating elements:

    <Document>

    <DocumentName>C:\Users\Administrator\Desktop\Release\Images\INV1642011391658522043.tif</DocumentName>

    <DocumentName>C:\Users\Administrator\Desktop\Release\Images\INV1642011391658522902.tif</DocumentName>

    <DocumentName>C:\Users\Administrator\Desktop\Release\Images\INV1642011391658523586.tif</DocumentName>

    </Document>

    In my orchestration, I get the correct count of repeating nodes. I then use a looping share to loop through all the Document Name nodes and try to extract the DocumentName Value. However it retiuns blank.

    This is my xpath:documentCount is the value of the DocumentName elements.

    sdocXpath= System.String.Format("/*[local-name()='DocImport' and namespace-uri()='']/*[local-name()='Document' and namespace-uri()='']/*[local-name()='DocumentName' and namespace-uri()=''][1]/text()",documentCount);
    DocumentNames=xpath(msgFESInternal.FESInternalMessage,sdocXpath);

    What am I doing wrong here?The xpath editor returns correct value of the node.


     

    Construct your xPath like this you have missed the curly braces (i.e. {}) and as you have only 1 parameter to replace the parameter count starts with '0':

    sdocXpath= System.String.Format("/*[local-name()='DocImport' and namespace-uri()='']/*[local-name()='Document' and namespace-uri()='']/*[local-name()='DocumentName' and namespace-uri()=''][{0}]/text()",documentCount);


    Please mark as answer or vote as helpful if my reply does [Regards-Rohit Sharma http://rohitbiztalk.blogspot.com/]
    Tuesday, July 19, 2011 3:29 AM
    Moderator
  • xpath index does not start from zero to fetch the first repeating record the index must be 1.

    You can try this xpath with indexing I have checked it with XMLSpy and it is returning the correct record with index.

    sdocXpath= System.String.Format("//Document/DocumentName[{0}],documentCount);

    DocumentNames=xpath(msgFESInternal.FESInternalMessage,sdocXpath);


    Abdul Rafay - MVP & MCTS BizTalk Server
    blog: http://abdulrafaysbiztalk.wordpress.com/
    Please indicate "Mark as Answer" if this post has answered the question.
    Tuesday, July 19, 2011 5:19 AM
  • I tried with the xpath and I agree that both mine and the xpath you have provided returns correct values in XMLSpy. however, the same xpath returns an emplty value in Biztalk orchestration. I have logging the vlaue of the returned field as well as the xpath message in the event log
    Tuesday, July 19, 2011 6:34 PM
  • You need to use the string function as shown below:

    sdocXpath= System.String.Format("string(/*[local-name()='DocImport' and namespace-uri()='']/*[local-name()='Document' and namespace-uri()='']/*[local-name()='DocumentName' and namespace-uri()=''][{0}]/text())",documentCount);


    Please mark as answer or vote as helpful if my reply does [Regards-Rohit Sharma http://rohitbiztalk.blogspot.com/]
    Wednesday, July 20, 2011 4:07 AM
    Moderator