You are here: Re: PHP saving embedded HTML in XML « PHP Programming Language « IT news, forums, messages
Re: PHP saving embedded HTML in XML

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.
> > &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') )

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]


Удаленная работа для программистов  •  Как заработать на 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

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