Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath: select node value with local-name()

Tags:

xml

xpath

biztalk

I want get the value between the open/close tags.

In this example all the field are inside the tag "PARAM " where the name is different.

Following, one of the xml examples. in this particular case, my objective is read the "21" in name="project_id".

XML sctructure:

<test>
    <MESSAGE type="Update" />
    <PARAMETERS>
        <PARAM name="project_id">21</PARAM>
        <PARAM name="project_name">000000003|teste name project</PARAM>
        <PARAM name="enabled">true</PARAM>
        <PARAM name="start_time">2019,02,01,00,00,00</PARAM>
        <PARAM name="end_time">2020,09,30,00,00,00</PARAM>
        <PARAM name="created_in">admin</PARAM>
    </PARAMETERS>
</test>

At this moment i have this xPath:

/*[local-name()='ULM' and namespace-uri()='']/*[local-name()='PARAMETERS' and namespace-uri()='']/*[local-name()='PARAM' and namespace-uri()=''][1]/@*[local-name()='name'and namespace-uri()='']

This xPath, only returns "project_id" but i need the value.

I already try using several xPaths, but only return the "project_id"(text).

Can someone give me a tip or indicate some article?

Thanks

xPath-Tester : https://www.freeformatter.com/xpath-tester.html#ad-output

Can someone give a tip?

like image 892
bruno rafael Avatar asked Nov 30 '25 02:11

bruno rafael


1 Answers

From your sample, the following XPath expression work :

//*[name()="PARAM" and @*[name()="name"]="project_id"]/text()

Output : 21

Replace name() with local-name() if errors occur.

like image 129
E.Wiest Avatar answered Dec 01 '25 19:12

E.Wiest