Idea ID: 2777662

Namespace support in XPath

Status : Waiting for Votes
over 1 year ago

If you have any XML result from REST API which has xmlns in resulted XML, you can't use standard XPath Query operation.

Example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<model-response-list xmlns="http://www.ca.com/spectrum/restful/schema/response" total-models="2" throttle="2"

error="EndOfResults">

<model-responses>

<model mh="0x29e42d">

<attribute id="0x1006e">Something</attribute>

<attribute id="0x12d7f">IP2</attribute>

<attribute id="0x10000">Something2</attribute>

</model>

<model mh="0x29e82f">

<attribute id="0x1006e">something</attribute>

<attribute id="0x12d7f">ip</attribute>

<attribute id="0x10000">Something</attribute>

</model>

</model-responses>

</model-response-list>

 

You can't just do following xpath:

/model-response-list/model-responses/model[@mh ='0x29e82f']/attribute[@id='0x10000']

 

I would suggest to add option in parsingFeatures to be able to just write this type of xpath (without selecting xlmns) or add option where you would select the xmlns.

 

Regards Dejan

  • Yeah,

    I found this is working, but it is not straight forward and easy maintainable:

    /*[local-name()='alarm-response-list']/*[local-name()='alarm-responses']/*[local-name()='alarm']/*[local-name() = 'attribute' and = '0x11f53']

    this local-name() would check for any xmlns, not just the one I had, but at least it was shorter

  • This would be such a great addition! We ran into a similar problem trying to use XPath queries and in the end we had to Frankenstein a mixture of regular expressions, string manipulations and XPath to get it working as we wanted.