开发者

PHP DOM: Get Nodevalue without descendant nodes

i am using the php dom function nodeValue to extract the text of content. B开发者_如何学Cut it returns the descendant values too:

<example>
<inhalt>123<more>45</more></inhalt>
</example>

return for inhalt 12345 and 123 as i prefer. I know that is not the sense and not very well to have text inside inhalt but how i check that there is no text in inhalt like hasNodeValue?


As Phil mentioned text is also organized in nodes. Therefore your node inhalt has two children: A text node ("123") and an element node named more, which also has a text node ("45").

If you just want to know, if there is text before the element more, test if there is at least one element and then test if the first element is text (should be DOMText as far as I remember).

If you like to know, if there is at least one element "at the root", iterate over all children and make the same tests.

http://www.php.net/manual/en/class.domtext.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜