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
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|