Wednesday, 23 January 2019

Why do I get adjacent Text nodes

Why do I get adjacent Text nodes?

Answer:

The DOM structure model that is created by whatever it is that creates it has one Text node per block of text when it starts. The only way you can have adjacent Text nodes is as a result of user operations; it is not an option for the DOM implementation when it first presents its structure model to the user. The normalizemethod (on the Element interface in level 1, but moved to Node for Level 2) will merge all the adjacent Text nodes into one again, so they will have the same form as if you wrote out the XML or HTML and then read it in again. Note that this will have no effect on CDATA Sections.

A filtered view of a document, such as that obtained through use of TreeWalker, may have adjacent Text nodes because the intervening Nodes are not seen in that view.

No comments:

Post a Comment