DOM loses whitespace
| From: | Paul DuBois | Date: | Tue, 29 Feb 2000 22:14:57 +0000 |
| Subject: | DOM loses whitespace | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-11211@lists.php.net to get a copy of this message | ||
Can I tell the DOM routines to consider whitespace significant?
Here's a short script to demonstrate what I'm observing:
$xmlstr = "<?xml version='1.0'?>
<root xml:space="preserve">
a<x> </x> b <x> </x>c
</root>
";
$dom = xmldoc($xmlstr);
echo $dom->dumpmem ();
The script produces this output:
<?xml version="1.0"?>
<root>
a<x/> b <x/>c
</root>
Note how the whitespace between <x> and </x> is lost. It appears
that whitespace in text is preserved only if the text also includes
non-whitespace. (This can be a problem if, for example, you're
formatting an XML document into HTML -- if the whitespace is lost,
text that should be separated ends up glued together in the output
document.)
I tried adding the space-preserving attribute to the root element:
$xmlstr = "<?xml version='1.0'?>
<root xml:space="preserve">
a<x> </x> b <x> </x>c
</root>
";
However, then I get a parse error.
--
Paul DuBois, paul@snake.net