5

I am trying to get the complete address using XPath. I am new to XPath. This is what I have done so far:

<p class="adr" prop1="address">
<span class="street-address" name="streetname">2222 Warnar Ave</span>
<span class="country" name="country">USA, </span>
<span name="State">CA</span>
<span name="zip">1111</span>
</p>

My XPath

/p/span/text()

Result like an array:

Text='2222 Warnar Ave'
Text='USA,'
Text='CA'
Text='1111'

And I want the result as a complete one line address

2222 Warnar Ave USA, CA 1111

I have used concat() in my XPath but nothing is showing!

kjhughes
  • 98,039
  • 18
  • 159
  • 218
Mtaly
  • 903
  • 2
  • 8
  • 23

1 Answers1

10

XPath 1.0 Solution

concat(/p/span[1],' ',/p/span[2],' ',/p/span[3],' ',/p/span[4])

Of course, instead of /p/span[1] you could specify /p/span[@class='street-address'] etc.

XPath 2.0 Solution

string-join(/p/span, ' ')
kjhughes
  • 98,039
  • 18
  • 159
  • 218