none
Fetching xml node nth value using Xpath RRS feed

  • Question

  • 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

    Tuesday, January 27, 2015 12:51 PM

Answers

  • 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.

    Tuesday, January 27, 2015 1:21 PM
  • 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()='DATE'])


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.


    Tuesday, January 27, 2015 1:23 PM

All replies

  • 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.

    Tuesday, January 27, 2015 1:21 PM
  • 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()='DATE'])


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.


    Tuesday, January 27, 2015 1:23 PM
  • Thank you Shanky and Ashwin for your quick respone..thanks a lot..
    Tuesday, January 27, 2015 2:03 PM