XPath expression issue

Post Reply
mclarke
Member
Posts: 56
Joined: Thu Feb 28, 2013 5:29 pm
Location: Syracuse, NY

XPath expression issue

Post by mclarke »

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 Define single-line text with variables_ Copies-right.png
XPATH Define single-line text with variables_ Copies-right.png (29.25 KiB) Viewed 32238 times
jan_suhr
Advanced member
Posts: 687
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: XPath expression issue

Post by jan_suhr »

Have you tried with XML location path selected Instead
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
cstevens
Member
Posts: 106
Joined: Tue Feb 12, 2013 8:42 pm

Re: XPath expression issue

Post by cstevens »

Wouldn't the XPath for that just be //JobGang/JobID/@text ?
freddyp
Advanced member
Posts: 1129
Joined: Thu Feb 09, 2012 3:53 pm

Re: XPath expression issue

Post by freddyp »

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.
mclarke
Member
Posts: 56
Joined: Thu Feb 28, 2013 5:29 pm
Location: Syracuse, NY

Re: XPath expression issue

Post by mclarke »

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.
loicaigon
Advanced member
Posts: 631
Joined: Wed Jul 10, 2013 10:22 am

Re: XPath expression issue

Post by loicaigon »

mclarke wrote: Tue Feb 11, 2025 5:30 pm 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.
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>
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:
//JobGang[name="JobID"]/Amount
Loïc Aigon
Enfocus PitStop Manager
RoseBL
Newbie
Posts: 1
Joined: Wed Apr 02, 2025 9:07 am
Contact:

Re: XPath expression issue

Post by RoseBL »

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:

Code: Select all

<job>
  <field>
    <name>JobID</name>
    <value>123</value>
  </field>
</job>
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:
//JobGang[name="JobID"]/Amount
Can you explain more clearly how to write XPath correctly if the XML has more complex nesting levels than this example?
loicaigon
Advanced member
Posts: 631
Joined: Wed Jul 10, 2013 10:22 am

Re: XPath expression issue

Post by loicaigon »

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/
Loïc Aigon
Enfocus PitStop Manager
Post Reply