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

筅森魡賤 提交于 2019-11-27 15:33:14

As long as you are selecting text nodes specifically, you can't. Because there simply is no text node in the first <td>.

When you change your XPath expression to '//td', you get the two <td> nodes. Use their text value in further processing.

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"

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!