Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

libxml2 - How do I return '' for an empty node's text() in XPath?

<td></td><td>foo</td>

I would like to return ['', 'foo'] but libxml's xpath //td/text() returns just ['foo']. How do I find the empty tag as '' instead of (not matched)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

While @Tomalak is perfectly right, in XPath 2.0 one can use:

//td/string(.)

and this produces a sequence of strings -- each one containing the string value of a corresponding td element.

So, in your case the result will be the desired one:

"", "foo"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...