Namespace support in XPath

Idea ID 2777662

Namespace support in XPath

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

Tags (3)
3 Comments
Micro Focus Expert
Micro Focus Expert
Status changed to: Waiting for Votes
 
Commander
Commander

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.

Commander
Commander

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 @Id = '0x11f53']

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

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.