Reply to Re: PHP saving embedded HTML in XML

Your name:

Reply:


Posted by Ian Taylor on 02/21/07 17:37

dcrackel@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.
> &lt;b&gt;test&lt;/b&gt;
>
> 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') )

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация