DNB5brims
DNB5brims

Reputation: 30578

Why I can't use XPath to query the required node?

Here is the XML:

<VDWSDirectoriesResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Success>true</Success>
<TotalResult>6</TotalResult>
<PageResult>6</PageResult>
<Summary/>
<DirectoriesResult>...</DirectoriesResult>
</VDWSDirectoriesResult>

I would like to get the Success node, I tried /VDWSDirectoriesResult/Success or Success, but I still can't get the value of Success node...What Did I do wrong? Thanks.

Upvotes: 0

Views: 134

Answers (1)

O. R. Mapper
O. R. Mapper

Reputation: 20731

Your root node declares a default namespace:

xmlns="http://tempuri.org/"

This means, your <Success> node is actually in that namespace, and not in the anonymous namespace assumed by XPath if you just write Success in your XPath expression.

Depending on the XPath library you are using, there will be some way of mapping a namespace prefix to the namespace URI http://tempuri.org/, which you can then use in your XPath expression.

For example, let's assume that you map the namespace prefix tmp to that URI, your XPath should read:

/tmp:VDWSDirectoriesResult/tmp:Success

Upvotes: 4

Related Questions