tags:

views:

29

answers:

2

Can anybody suggest how can I solve this, there is XML document that I'm trying to append. I'm looking up nodes with xpath, the things is the software which generates this XML sometimes screws it up as following :

<element name="Element ">Element value</element>

So when I'm looking the node up with xpath using //element[@name="Element"] without a blank space I don't get a match. Naturally I get match with this //element[@name="Element "]

Is there something I can do to match this without blank space?Does xpath accept regular expressions or there is more smart way to do this, I can change the xml file as well after it has been generated by the sofware(with faulty user input).

+4  A: 

(untested).

Would

//element[normalize-space(@name)=="Element"]

work?

Thorbjørn Ravn Andersen
A+ for you, it actually worked, I've searched this for so long, can you recommend some useful resources for xpath?
London
The XPath specification? http://www.w3.org/TR/xpath/#section-String-Functions
Thorbjørn Ravn Andersen
+1  A: 

A more general (though less accurate) solution could be:

//element[contains(@name,"Element")]

However that would also catch things like name="Elements" and name="Elementary" etc.

can you recommend some useful resources for xpath

Unfortunately there aren't many great such resources in my experience - w3schools is probably your best bet, or the spec itself for more advanced stuff.

lucideer