Okay, so I haven't worked with XPath in a version or two, but the command I used to use to parse XML files via an expression doesn't work. I even copied the syntax from the help page and it still gives me an error. I'm sure it must be something that I don't remember, or didn't write down in my notes. Could someone please look at the attached screenshot and tell me what I'm doing wrong?
XPath expression issue
Re: XPath expression issue
Have you tried with XML location path selected Instead
Re: XPath expression issue
Wouldn't the XPath for that just be //JobGang/JobID/@text ?
Re: XPath expression issue
As you are not using an XPath expression the option to work with "XML location path" is indeed easier. When choosing that way of working you can click your way through the structure of the XML and the XPath will build itself. For easy XMLs like the one you have that is more than good enough.
Re: XPath expression issue
I tried just following down the XPath and it gave me a correct value. I can use that process for the rest of the XML values.
Any reason(s) why my original expression wouldn't work? I know I've used it before and I copied it right out of the Switch Help doc on XPath.
Any reason(s) why my original expression wouldn't work? I know I've used it before and I copied it right out of the Switch Help doc on XPath.
Re: XPath expression issue
Well the doc states:
//field[name="JobID"]/value
selects all value elements in the document that have a parent field element and a sibling name element with string-value equal to JobID
That would work if the structure would be somehow similar to:
Code: Select all
<job>
<field>
<name>JobID</name>
<value>123</value>
</field>
</job>
//JobGang[name="JobID"]/Amount
Loïc Aigon
Enfocus PitStop Manager
Enfocus PitStop Manager
Re: XPath expression issue
Can you explain more clearly how to write XPath correctly if the XML has more complex nesting levels than this example?loicaigon wrote: ↑Tue Feb 11, 2025 11:17 pm
Well the doc states:
//field[name="JobID"]/value
selects all value elements in the document that have a parent field element and a sibling name element with string-value equal to JobID
That would work if the structure would be somehow similar to:Now your XML structure is structured in a different way. So the XPath you want to use must adapt to that. I am not sure here what you need to catch but if that was the Amount, you could indeed get to use something similar to the doc example:Code: Select all
<job> <field> <name>JobID</name> <value>123</value> </field> </job>
//JobGang[name="JobID"]/Amount
Re: XPath expression issue
Hello,
XPath is very rich and my post alone won't be sufficient to give you all the keys.
Might be best that you have a look at teh numerous tutorials you can find online:
https://www.w3schools.com/xml/xpath_intro.asp
Jump here if you are already familiar with basics:
https://www.w3schools.com/xml/xpath_syntax.asp
You have this one as well:
https://devhints.io/xpath
And this can be used to test expressions online:
https://xpather.com/
XPath is very rich and my post alone won't be sufficient to give you all the keys.
Might be best that you have a look at teh numerous tutorials you can find online:
https://www.w3schools.com/xml/xpath_intro.asp
Jump here if you are already familiar with basics:
https://www.w3schools.com/xml/xpath_syntax.asp
You have this one as well:
https://devhints.io/xpath
And this can be used to test expressions online:
https://xpather.com/
Loïc Aigon
Enfocus PitStop Manager
Enfocus PitStop Manager