note 61602 deleted from ref.dom by didou
| From: | didou@php.net | Date: | Mon, 13 Mar 2006 00:06:34 +0000 |
| Subject: | note 61602 deleted from ref.dom by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-105404@lists.php.net to get a copy of this message | ||
Note Submitter: kermodebear at kermodebear dot org
----
For those of you suffering with extra DOMText objects in your DOM Tree, set preserveWhiteSpace to
false before loading your XML. This doesn't seem to be explicitly stated in the manual.
Example:
<?php
$dom = new DOMDocument();
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<node1>
<node2 />
</node1>
';
$dom->loadXML( $xml );
$nodeList = $dom->getElementsByTagName( 'node1' );
$node1 = $nodeList->item(0);
foreach ( $node1->childNodes as $node ) {
echo 'Class: ' . get_class( $node ) . "\n";
}
?>
Will result in:
Class: DOMText
Class: DOMElement
Class: DOMText
If you add:
<?php
$dom->preserveWhiteSpace = false;
?>
You will get:
Class: DOMElement