Fetching xml node nth value using Xpath

HI Experts ,

with reference to below question, i have one more doubt.

https://social.msdn.microsoft.com/Forums/en-US/f894e5e2-8926-4604-9171-616da3f00cd7/xpath-to-fetch-value-in-flatfile-schema?forum=biztalkgeneral

 

I used below xpath to fetch nth value of full repeating message nodes

indexStr = System.Convert.ToString(index);

DATE=xpath(In_FF, "string(//*[local-name() = 'Details']["+indexStr+"])/*[local-name()='DATE'])");

index=index + 1;


and i got below error, can any help me in this?

Exception thrown from: segment 2, progress 43
Inner exception: 'string(//*[local-name() = 'Details'][1])/*[local-name()='DATE'])' has an invalid token.

Exception type: XPathException
Source: System.Xml
Target Site: MS.Internal.Xml.XPath.AstNode ParseXPathExpresion(System.String)
The following is a stack trace that identifies the location where the exception occured

January 27th, 2015 3:51pm

your XPATH expression is WRONG.

it should be

DATE=xpath(In_FF, "string(//*[local-name() = 'Details']["+indexStr+"]/*[local-name()='DATE'])");

There is NO ")" after ["+indexStr+"].

The more reliable way is to use a string variable and use the System.String.Format() call as below

xPathExpr = System.String.Format("string(//*[local-name() = 'Details'][{0}]/*[local-name()='DATE'])", index);
DATE=xpath(In_FF, xPathExpr);
The "invalid token" is because of the mismatched ")" in your XPATH Expression.

Regards.

Free Windows Admin Tool Kit Click here and download it now
January 27th, 2015 4:21pm

Use the following statement:

DATE=xpath(In_FF, "string(//*[local-name() = 'Details']["+indexStr+"]/*[local-name()='DATE'])");

YOu have extra bracket next to the index..Just removed it. ABove one is after removing the extra bracket

Your wrong XPath:

string(//*[local-name() = 'Details'][1])/*[local-name()='D

January 27th, 2015 4:23pm

Thank you Shanky and Ashwin for your quick respone..thanks a lot..
Free Windows Admin Tool Kit Click here and download it now
January 27th, 2015 5:03pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics