|
Posted by Tim Hunt on 02/22/07 03:13
On Feb 21, 5:37 pm, Ian Taylor <m...@ocset.reverse.previous.word.net>
wrote:
> dcrac...@gmail.com wrote:
> > I hope there is a simple solution to this, but I've been unable to
> > find it.
>
> > $dom = new DomDocument();
> > $dom->load("test.xml");
>
> > $test = $dom->getElementsByTagName("test");
> > $test->nodeValue = "<b>test</b>";
> > $dom->save("test.xml");
>
> > I would like the node in the xml file to look like:
> > <test><b>test</b></test>
>
> > Rather than the encoded version.
> > <b>test</b>
>
> > What can be done to accomplish this task?
>
> > Thank you
> > dwain
>
> From what I can see, it's not really possible - if it was possible, and
> you tried to re-read the resulting xml file back, you would end up with
> something like:
>
> ...
> <test>
> <b>
> test
> </b>
> </test>
> ...
>
> where <b> is a child node of the <test> node, rather than part of the
> value of the <test> node.
>
> Therefore, entities like < and > do need to be encoded / decoded
> (possible with html_entity_decode()) when dealing with xml.
>
> If, however, you *are* looking to add <b> as a child node of <test>, I'm
> sure there are functions to handle that ( probably something like $child
> = $test->append_child('b') )
Hi
You can do it like Ian said:
$elem = $dom->createElement('b');
$elem->nodeValue = 'test';
$test->appendChild($elem);
Or using a document fragment
$fragment = $dom->createDocumentFragment();
$fragment->appendXml('<b>test</b>');
$test->appendChild($fragment);
Navigation:
[Reply to this message]
|