Forum Discussion

marting's avatar
10 months ago
Solved

Xpath woes

Hey all,

Been trying to figure out why this Xpath syntax is not working and I’m at a point where it seems like it’s an issue specific to LM… hoping someone knows of a fix/workaround.

Abridged XML response that I’m getting from a device we want to monitor:

<?xml version="1.0" ?>
<BACrest:GetValue xmlns:BACrest="urn:BACrestService">
[...]
<BACrest:return>75.034996</BACrest:return>
</BACrest:GetValue >

I’m trying to get the value inside BACrest:return.  Using the XML section of this article as reference.  Also using freeformatter.com as suggested here to validate my Xpath syntax.

I’ve tried a bunch of various syntax options that all work largely as expected in freeformatter but don’t work in LM: I get either NaN or 0.  I have verified that I’m getting the expected XML in the body of the response.

Various syntaxes I’ve tried:

BACrest:GetValue/BACrest:return
/BACrest:GetValue/BACrest:return
/BACrest:GetValue/BACrest:return/text()
number(/BACrest:GetValue/BACrest:return)
string(/BACrest:GetValue/BACrest:return)

...etc.

Then I thought maybe LM needs to have an integer (is that a thing?) so I tried this:

substring-before(/BACrest:GetValue/BACrest:return, '.')

...which returns just 75 in freeformatter.

Ideas?

Thanks!

  • Hey @marting 

    I wanted to reach out and see if you have reached out to support for this behavior you are seeing?  There may be something we need to get our internal teams to review if there is an issue with parsing XML properly, but to do that we would need you to open up a support ticket. 

    As an aside, I did attempt to reproduce the issue you are seeing, and I am able to using a script to hardcode your XML and then attempting to parse it.  However, since you may be doing something different I would still want to take a look at your exact setup.  If you do open a support ticket please do DM me your ticket number so I can take a look!

3 Replies

  • Hey @marting 

    I wanted to reach out and see if you have reached out to support for this behavior you are seeing?  There may be something we need to get our internal teams to review if there is an issue with parsing XML properly, but to do that we would need you to open up a support ticket. 

    As an aside, I did attempt to reproduce the issue you are seeing, and I am able to using a script to hardcode your XML and then attempting to parse it.  However, since you may be doing something different I would still want to take a look at your exact setup.  If you do open a support ticket please do DM me your ticket number so I can take a look!

  • Support was able to get me going on this.  Not sure why but this is the syntax that works:

    /*[local-name()='GetValue']/*[local-name()='return']

    And, to follow up on my own question, LM has no problem dealing with non-integer (decimal) values.

    @LMjosephBrett thanks for your help with getting this solved!

  • Thanks @LMjosephBrett and sorry about the delayed response.  Ticket created; DM sent.