1
votes

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?

2
If the namespace-uri is '', why do you need to use local-name()? Can't you just use //PARAM[@name='project_id']/text()? - Daniel Haley
I need user local-name(), because de program (biztalk) is given error when put an xPath without local-name(). The xPath ( /ULM/PARAMETERS/PARAM[@name='project_id']) work very well in the freeformatter.com, but when deploy this do biztalk, the server retrieve an error saying: "cannot recognize the xpath". - bruno rafael
Solution founded. /*[local-name()='ULM']/*[local-name()='PARAMETERS']/*[local-name()='PARAM' ][1]/text() - bruno rafael
Someone with other Solution to this problem? - bruno rafael

2 Answers

2
votes

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.

0
votes

First, you need to add condition on <PARAM> element based on your @name attribute equals to 'project_id', then you can get the resulting text() value based on this condition.

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

Since you are not using any namespaces based on your given xml, you can ignore and namespace-uri()=''.

/*[local-name()='ULM']/*[local-name()='PARAMETERS']/*[local-name()='PARAM'][@*[local-name()='name']='project_id'][1]/text()