Gaurav Thantry
Gaurav Thantry

Reputation: 803

Target name space is being printed in the xpath output

I am trying to write an xpath which shows only the tag and the value.

This is the xml file:

<v11:root xmlns:v11="http://example.com">
<v11:Four-Sided>
<v11:SquareName>ABCD</v11:SquareName> 
<v11:RectangleName>EFGH</v11:RectangleName> 
<v11:ParallelName>WXYZ</v11:ParallelName> 
</v11:Four-Sided>
</v11:root>

And my xpath is:

//v11:SquareName

Desired Output:

<v11:SquareName>ABCD</v11:SquareName>

Actual output:

<v11:SquareName xmlns:v11="http://example.com">ABCD</v11:SquareName>

Upvotes: 0

Views: 51

Answers (1)

Michael Kay
Michael Kay

Reputation: 163262

It's not the XPath engine that's serializing the value to lexical XML, it's some other bit of software to which you pass the XPath results. (XPath is used to select nodes, anything that happens to the nodes subsequently is out of XPath's control).

Having said that, most XML serialization libraries, given an element node, will output it as a well-formed XML document containing all required namespace declarations. Without the namespace declaration, how can you know what "v11" means, or do anything useful with it?

Upvotes: 2

Related Questions