virgopassionate
virgopassionate

Reputation: 13

XPATH help needed for text()

<div class="from"> 
  <span class="label">Reported by: Rhjj, 
    <span class="ocation">US</span>
  </span> <span class="dat">  </span> </div>

Here I just want the output as "Reported by :Rhjj". But when i use the XPATH as //div[contains(@class,"from")]//span[contains(@class,"label")] "US" also gets selected. Is there any other way to select only Reported by: Rhjj, other than using text() and using substring_before comma. Even this is not consistent

//div[contains(@class,"fromTime")]//span[contains(@class,"label")]/text()

Upvotes: 0

Views: 35

Answers (1)

chrisis
chrisis

Reputation: 1993

The text you want is the first node under the span element with an attribute named class (note I've taken the names from the XML, not your code.). This works for the snippet of XML you've provided.

/div[@class="from"]/span[@class="label"]/node()[1]

Upvotes: 0

Related Questions