Link to home
Start Free TrialLog in
Avatar of charlesgates22
charlesgates22Flag for United States of America

asked on

XPath find an empty attribute

Hello group,

How can I find the node <b> that contains the empty name attribute?
 <a>
   <b name="" code="0">
 </a>
 <a>
   <b name="somename" code="0">
 </a>
 
I'm using XPath with XMLDocument
 DOMNode := RXMLDoc.SelectNode('//a/b[@name=""']');

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of charlesgates22

ASKER

thank you very much for your response,
yes, it's working now.

so you like using string-length(normalize-space(@name)) = 0]'
how come? what's the danger in just using "" ?
what if I have one common code and I pass the atttribute name to find, so sometime this parameter can be empty and sometime can actually contain a string, either way I need to find the correspondent node, what's the best practice?
e.g.:
DOMNode := RXMLDoc.SelectNode('//a/b[@name="' + parpassed + '"']');
parpassed can be "" or "somename"

> how come? what's the danger in just using "" ?

there is no danger, but I explicitely exclude attributes containing only whitespace as well this way

your example with parpassed should work
Gertone, BTW congrats for your annual EE award!