Home Page › Forums › BizTalk 2004 – BizTalk 2010 › xpath expression inside a loop to pull records/nodes out
- This topic has 4 replies, 1 voice, and was last updated 9 years, 2 months ago by
community-content.
-
AuthorPosts
-
-
July 18, 2014 at 7:23 PM #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” ResponseVersion=”1.1″ xmlns=”http://www.MyResponseFile”> <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.
-
July 18, 2014 at 11:45 PM #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.
-
July 21, 2014 at 4:06 PM #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>
-
July 28, 2014 at 2:05 AM #26425
How to pick particular record from xml document by using xpath expression?
guys pls give ur suggested answers regarding these issue?
-
July 30, 2014 at 9:27 AM #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
-
-
-
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.