note 105917 added to class.domnode
| From: | alastair dot dallas at gmail dot com | Date: | Sun, 25 Sep 2011 15:44:35 +0000 |
| Subject: | note 105917 added to class.domnode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183419@lists.php.net to get a copy of this message | ||
The issues around mixed content took me some experimentation to remember, so I thought I'd add
this note to save others time.
When your markup is something like: <div><p>First
text.</p><ul><li><p>First
bullet</p></li></ul></div>, you'll get XML_ELEMENT_NODEs that are quite
regular. The <div> has children <p> and <ul> and the nodeValue for both <p>s
yields the text you expect.
But when your markup is more like <p>This is <b>bold</b> and this is
<i>italic</i>.</p>, you realize that the nodeValue for XML_ELEMENT_NODEs is not
reliable. In this case, you need to look at the <p>'s child nodes. For this example, the
<p> has children: #text, <b>, #text, <i>, #text.
In this example, the nodeValue of <b> and <i> is the same as their #text children. But
you could have markup like: <p>This <b>is bold and <i>bold
italic</i></b>, you see?</p>. In this case, you need to look at the children of
<b>, which will be #text, <i>, because the nodeValue of <b> will not be
sufficient.
XML_TEXT_NODEs have no children and are always named '#text'. Depending on how whitespace
is handled, your tree may have "empty" #text nodes as children of <body> and
elsewhere.
Attributes are nodes, but I had forgotten that they are not in the tree expressed by childNodes.
Walking the full tree using childNodes will not visit any attribute nodes.
----
Server IP: 64.71.164.2
Probable Submitter: 71.116.103.211
----
Manual Page -- http://www.php.net/manual/en/class.domnode.php
Edit -- https://master.php.net/note/edit/105917
Del: integrated -- https://master.php.net/note/delete/105917/integrated
Del: useless -- https://master.php.net/note/delete/105917/useless
Del: bad code -- https://master.php.net/note/delete/105917/bad+code
Del: spam -- https://master.php.net/note/delete/105917/spam
Del: non-english -- https://master.php.net/note/delete/105917/non-english
Del: in docs -- https://master.php.net/note/delete/105917/in+docs
Del: other reasons-- https://master.php.net/note/delete/105917
Reject -- https://master.php.net/note/reject/105917
Search -- https://master.php.net/manage/user-notes.php