I need to locate the node within an xml file by its value using XPath. The problem araises when the node to find contains value with whitespaces inside. F.e.:
<Root>
<Child>value</Child>
<Child>value with spaces</Child>
</Root>
I can not construct the XPath locating the second Child node.
Simple XPath /Root/Child perfectly works for both children, but /Root[Child=value with spaces] returns an empty collection.
I have already tried masking spaces with %20, & #20;, & nbsp; and using quotes and double quotes.
Still no luck.
Does anybody have an idea?
All of the above solutions didn't really work for me. However, there's a much simpler solution.
When you create the XMLDocument, make sure you set PreserveWhiteSpace property to true;
did you try #x20 ?
i've googled this up like on the second link:
try to replace the space using "x0020"
this seems to work for the guy.
"x0020" worked for me on a jackrabbit based CQ5/AEM repository in which the property names had spaces. Below would work for a property "Record ID"-
Locating the Attribute by value containing whitespaces using XPath
I have a input type element with value containing white space.
eg:
I solved this by using this xpath expression.
Hope this will help you guys.
Try either this:
or
or (since it looks like your test value may be the issue)
Haven't actually executed any of these so the syntax may be wonky.