3

I am trying to understand the difference between

//*[.] and //*[*] 

These return different number of elements.

Also where I can use the dot instead of attribute

 //tag[@Attribute="value"] 

Not just in case of text? And what does the syntax look like? Because I tried

//tag[@.="value"] and //tag[.="value"] 

and the last one only worked in case of text but not instead of case

//tag[@id="value"] 

for example, so when can I change the dot instead of attribute?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
timothy
  • 97
  • 9

1 Answers1

3

//*[.] will select all elements. It is equivalent to //*.

//*[*] will select all elements that have at least one child element.

//tag[@.="value"] is syntactically invalid.

//tag[.="value"] will select all tag elements whose string value equals value. For example, for this XML,

<tag id="r">
  <tag id="a">value</tag>
  <tag id="b">val<br/>ue</tag>
  <tag id="c"><span>val</span><span>ue</span></tag>
  <tag id="f"> value</tag>
  <tag id="g">Value</tag>
</tag>

//tag[.="value"] will select

<tag id="a">value</tag>
<tag id="b">val<br/>ue</tag>
<tag id="c"><span>val</span><span>ue</span></tag>

See also Testing text() nodes vs string values in XPath

kjhughes
  • 106,133
  • 27
  • 181
  • 240