theta
theta

Reputation: 25611

Preserve spaces from attribute values with xpath

Please consider this file: http://www.w3schools.com/dom/books.xml where line:

<book category="children">

is replaced with:

<book category=" children ">

Executing xpath query in vbscript for category attribute value:

For Each n In objXML.selectNodes("//book/@category")
    WScript.Echo n.text
Next

returns result where leading and trailing spaces are removed:

children

This doesn't happen with any other xpath evaluator I have tried.

So is it possible MS to return attribute value as it is, without removing spaces?

Upvotes: 0

Views: 390

Answers (1)

Kul-Tigin
Kul-Tigin

Reputation: 16950

It's possible through value property instead text.
You'd like to know the differences between those two properties.
Please read the reference, especially Remarks sections.

value Property
text Property

As you can see, in this case main differences between value and text is that text normalizes, value doesn't.

For Each n In objXML.selectNodes("//book/@category")
    WScript.Echo n.text
    WScript.Echo n.value
Next

Upvotes: 1

Related Questions