Reputation: 6735
Using this xpath expression: //items/item[@key='NAME']/value/text()
on ..
<test>
<items>
<item key="USGAE">
<value xsi:type="ns9:string">SomeUse</value>
</item>
<item key="NAME">
<value xsi:type="ns9:string">TheName</value>
</item>
</items>
</test>
gives this error:
Error on line 4: The prefix "xsi" for attribute "xsi:type" associated with an element type "value" is not bound.
However using the same xpath on ..
<test>
<items>
<item key="USGAE">
<value>SomeUse</value>
</item>
<item key="NAME">
<value>TheName</value>
</item>
</items>
</test>
gives me the right value: TheName
Why is that so? The server actually returns the first snippet of XML
i.e with xsi
inside each value
Is there a way around this? I don't have access to the web service that generates this XML
Upvotes: 0
Views: 2098
Reputation: 89285
Short answer is, you need to add definition of xsi
prefix to your XML document somehow.
Normally, XML parser only works given well-formed XML document, and a well-formed XML has all namespace prefixes defined. Despite widely used, xsi
prefix is no exception, only xml
prefix assumed to be known (is the xsi: prefix assumed to be known in XML?).
Upvotes: 2