Avery Richardson
Avery Richardson

Reputation: 277

Using xpath to accessing the text between non-text children of a node

 <div>
    foo
    <br />
    bar
    <br />
    baz
 </div>
  1. What technical terms describe the relationships between bar, baz and the div?
  2. How do I use xpath to get bar and baz out of the div?

Upvotes: 1

Views: 160

Answers (3)

LarsH
LarsH

Reputation: 28004

  1. The text nodes bar and baz are siblings of each other, and children of the <div> element.

2 has already been answered correctly.

Upvotes: 2

Spredzy
Spredzy

Reputation: 5174

First Question :

bar and baz are text nodes of the element div.

Second question :

The following XPath expression.

/div/text()[not(contains(., "foo"))]

This would work and leave foo out of the retrieved data.

Upvotes: 4

jasso
jasso

Reputation: 13986

Use node test text() to to select text nodes.

/div/text()

Selects "foo", "bar" and "baz" (and the whitespace) text node children of <div>.

Upvotes: 2

Related Questions