xpath expression inside a loop to pull records/nodes out

Home Page Forums BizTalk 2004 – BizTalk 2010 xpath expression inside a loop to pull records/nodes out

Viewing 1 reply thread
  • Author
    Posts
    • #26421

      Hello,

      I have an xml file with multiple records that I want to insert to a database one by one.  My orchestration receives the file as a whole, then I loop through the transactions, insert the transaction, loops through the encounters and inserts the encounters one by one for that transaction.  Inside my encounter loop I have constructMessage shape, with a MsgAssign shape and a transform shape.  In the MsgAssign shape I have an xpath expression to pull out each encounter one by one and even though my counter is incrementing I still get only the first record.  So in the example below it’s inserting the first encounter 3 times.  I know I could debatch it by changing the schema to have evelope=true, etc, it but I want to do this as a batch as I need to associate all the records to main file.

      this is my xpath in in my MsgAssign shape:

      strEncounterIncrement  is incrementing as I loop.

      MsgEncounterAdd = xpath(MsgXMLResponse, “/*[local-name()=’EncounterValidationResponse’]/*[local-name()=’Transactions’]/*[local-name()=’Transaction’]/*[local-name()=’Encounters’]/*[local-name()=’Encounter’][” + strEncounterIncrement + “]”);

      If strEncounterIncrement = 2 how can I get the second Encounter record (xxxxx14020702597748)?

      This is the structure of my xml file:

      <?xml version=”1.0″ encoding=”utf-8″?>

      <EncounterValidationResponse xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; ResponseVersion=”1.1″ xmlns=”http://www.MyResponseFile”&gt; <EncounterFileName>MyFileName.dat</EncounterFileName> <EncounterSubmitterName>MySubmitter</EncounterSubmitterName> <EncounterSubmissionDate>2014-07-16T16:08:03.0000000-07:00</EncounterSubmissionDate> <ValidationStatus>Rejected</ValidationStatus>

      <Transactions>

      <Transaction Status=”Rejected”> <IdentifierName>TransactionControlNumber</IdentifierName> <TransactionNumber>999</TransactionNumber> <Identifiers> <Envelope IdentifierName=”ISAControlNumber” IdentifierValue=”xxxxx”/> <Envelope IdentifierName=”GroupControlNumber” IdentifierValue=”yyy”/> </Identifiers> <TransactionResponses> <Response Severity=”Error”> <Id>0x810034</Id> <IsSNIP>true</IsSNIP> </Response> </TransactionResponses>

      <Encounters>

      <Encounter Status=”Rejected”> <IdentifierType>SubmitterClaimIdentifier</IdentifierType> <EncounterReferenceNumber>xxxxx022302567359</EncounterReferenceNumber> <EncounterId xsi:nil=”true”/> </Encounter>

      <Encounter Status=”Rejected”> <IdentifierType>SubmitterClaimIdentifier</IdentifierType> <EncounterReferenceNumber>xxxxx14020702597748</EncounterReferenceNumber> <EncounterId xsi:nil=”true”/> </Encounter>

      <Encounter Status=”Rejected”> <IdentifierType>SubmitterClaimIdentifier</IdentifierType> <EncounterReferenceNumber>xxxxx14021802543871</EncounterReferenceNumber> <EncounterId xsi:nil=”true”/>

      </Encounter>

      </Encounters>

      </Transaction>

      </Transactions></EncounterValidationResponse>

      Thank you anybody for your help!  I have a hard time with xpath.  Especially inside of BizTalk.

    • #26422

      Hi,

        Try this line of code in your message assignment shape:

      MsgEncounterAdd = xpath(MsgXMLResponse, "/*[local-name()='EncounterValidationResponse']/*[local-name()='Transactions']/*[local-name()='Transaction']/*[local-name()='Encounters']/*[local-name()='Encounter'][" + strEncounterIncrement + "]/*[local-name()='EncounterReferenceNumber']");

        Good luck.

      • #26423

        But I need the whole Encounter node not just the EncounterReferenceNumber.  I tried removing the last nodename and using this below but it still will not work  It just keeps pulling out my first node even though my strEncounterIncrement is indeed incrementing and the xpath works when I put it in xmlspy xpath validator…

        MsgEncounterAdd = xpath(MsgXMLResponse, "/*[local-name()='EncounterValidationResponse']/*[local-name()='Transactions']/*[local-name()='Transaction']/*[local-name()='Encounters']/*[local-name()='Encounter'][" + strEncounterIncrement + "]);

        So I need this whole node pulled out of when strEncounterIncrement = 2…

        <Encounter Status="Rejected"> <IdentifierType>SubmitterClaimIdentifier</IdentifierType> <EncounterReferenceNumber>xxxxx14020702597748</EncounterReferenceNumber> <EncounterId xsi:nil="true"/> </Encounter>

        • #26425

          How to pick particular record from  xml document by using xpath expression?

          guys pls give ur suggested answers regarding these issue?

          • #26428

            use like

            string xpathstring = system.string.format("/parent/Child/RepeatingNode[position = {0}]", loppingcounter;

            xmldoc = (System.Xml.XmlDocument) xpath(Msg, xpathstring);

            this will get you the node, this is the implementation of the splitter pattern in the orchestration.

            Thanks

            [email protected]

Viewing 1 reply thread
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.