none
Xpath issue RRS feed

  • Question

  • Hi all,

    I am working on Xpath in and assigning the XPath value to local variable in Orchestation under Expression shape.

    Xpath is as =

    varDataCount = xpath(GetCatchResponseCDMMsg.Body,"count(/*[local-name()='USP_PSIC_(GetCatchResponseCDMFromCacheResponse' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo']/*[local-name()='USP_PSIC_GetCatchResponseCDMFromCacheResult' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo']/*[local-name()='DataSet' and namespace-uri()='http://schemas.datacontract.org/2004/07/System.Data']/*[local-name()='diffgram' and namespace-uri()='urn:schemas-microsoft-com:xml-diffgram-v1']/*[local-name()='NewDataSet' and namespace-uri()='']/*[local-name()='NewTable' and namespace-uri()='']/*[local-name()='CDMXML' and namespace-uri()=''])");

    In some cases element of CDMXML will not present e.g :

    varDataCount = xpath(GetCatchResponseCDMMsg.Body,"count(/*[local-name()='USP_PSIC_(GetCatchResponseCDMFromCacheResponse' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo']/*[local-name()='USP_PSIC_GetCatchResponseCDMFromCacheResult' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/Procedures/dbo']/*[local-name()='DataSet' and namespace-uri()='http://schemas.datacontract.org/2004/07/System.Data']/*[local-name()='diffgram' and namespace-uri()='urn:schemas-microsoft-com:xml-diffgram-v1']/*[local-name()='NewDataSet' and namespace-uri()='']/*[local-name()='NewTable' and namespace-uri()=''])");

    If CDMXML is not present i am getting error, and flow got break.

    What i am trying to do is check if CDMXML element is present in message then take a count of it if not then set varDataCount = 0.

    How can we implement it ?



    Thanks and Regards, Nitin.

    Tuesday, August 18, 2015 3:45 AM

Answers

  • Hi Vikas and Shankycheil,

    Sorry might be i not explained it correctly...

    i got solution for this....

    thanks for your helps...


    Thanks and Regards, Nitin.

    • Marked as answer by Nitin Surya Tuesday, August 18, 2015 6:57 AM
    Tuesday, August 18, 2015 6:57 AM

All replies

  • I do not know why this is such a big issue?

    a simple xpath(message, "count(//*[local-name()='CDMXML')") would give you the number of CDMXML elements in your message. This should not make a difference if it exists or not. Even if you want to use this to loop through it would work by using xpath(message, "string(//*[local-name()='CDMXML'][i])"

    NOTE: However you should ensure that the CDMXML nodes all occur on the same path.

    Regards.

    Tuesday, August 18, 2015 4:57 AM
  • Hi Nithin,

    Your xpath is correct, you can handle in the below.

    If the node is present then the xpath count returns            ->    actual count

    If the node is optional or absent then xpath count returns  ->      0

    xPathVar=xpathexpression;
    
    If(xPathVar > 0)
    {
     // Read the actual values
    }
    
    // Other case its null or absent in xml

    Thanks, SMSVikasK

    Tuesday, August 18, 2015 5:29 AM
    Answerer
  • Hi Vikas and Shankycheil,

    Sorry might be i not explained it correctly...

    i got solution for this....

    thanks for your helps...


    Thanks and Regards, Nitin.

    • Marked as answer by Nitin Surya Tuesday, August 18, 2015 6:57 AM
    Tuesday, August 18, 2015 6:57 AM