0

I am new XML and struggling to find an answer to this problem. I have the following code (see below) and would like to extract the value 3400.0000000000 from it.

How do I do this using Xpath?

<SpindleSpeed dataItemId="c2" name="Sspeed" sequence="351828725" subType="ACTUAL" timestamp="2014-12-01T21:51:32.834494">3400.0000000000</SpindleSpeed>

3 Answers 3

1

XPath has two parts - locations paths and functions. A location path will always return a list of nodes (an empty one if it can not find a matching node).

Here are three possible location paths in your XML:

/SpindleSpeed for the SpindleSpeed element node that is the document element

//SpindleSpeed for any SpindleSpeed element node in the document

//SpindleSpeed/text() for any text nodes inside any SpindleSpeed element node in the document

If you have a list you can cast it

number(//SpindleSpeed) is the content of the first node in the list (from the location path) as a number - 0.0 if the list was empty.

string(//SpindleSpeed) is the content of the first node in the list (from the location path) as a string - an empty string for an empty list.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you guys for your help, I have implemented your suggestions and it is working now. Your help is very much appreciated
0

Try this :

//SpindleSpeed/text()

Comments

0

If X is an expression that selects the SpindleSpeed element, then string(X) is an expression that returns its string value, that is "3400.0000000000"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.