Re: simplexml and CDATA




Gertjan Klein wrote:
mandric@xxxxxxxxx wrote:

Can someone please enlighten me on how to preserve the <![CDATA[]]>
element when parsing an xml file or string with simplexml. I'm using
libxml 2.6.16 and php 5.1.4.

As far as I've been able to find out this is not possible. However, I
don't think there is a *functional* difference between preserving the
CDATA and what simplexml does. In CDATA sections, you can include e.g.
<i>some</i> HTML elements as-is. They, when parsing, will not result in
separate nodes in the resulting DOM. The XML that $xml->asXML()
generates, escapes the reserved characters (<, >, &) instead. As far as
I can tell this results in functionally the same XML.

Of course, it would be nice if simplexml would remember that a given
element originally held CDATA contents and output it as such. Perhaps
you can file an enhancement request for this.


I think the answer is use DOM if your needs are not simple. ;)
Which should be available if SimpleXML is.
http://us3.php.net/manual/en/ref.dom.php

Thanks Gertjan.

.



Relevant Pages

  • Re: simplexml and CDATA
    ... element when parsing an xml file or string with simplexml. ... CDATA and what simplexml does. ... In CDATA sections, you can include e.g. ...
    (comp.lang.php)
  • Re: reading a XML file on every page execution - convert to PHP?
    ... into a simpleXML node every time index.php loads. ... Including a php file requires the file be read then parsed. ... modification date- and use the .xml only if it was newer. ... cannot load, ...
    (comp.lang.php)
  • Re: How to open and read "feed:" in PHP?
    ... Question: Is a URL that starts with feed: output XML? ... Question: How do I open a feed: URL in PHP and parse it? ... I looked at the example for simpleXML on the php.net web site. ... That's because SimpleXML alows you to navigate the xml tree as you wish, foroward and backwards how many times you like. ...
    (comp.lang.php)
  • Re: Interaction between SimpleXML & DOM
    ... The above is not well-formed XML. ... Give up using SimpleXML and use DOM for everything... ... $contentDOM = new DOMDocument; ...
    (comp.lang.php)
  • Re: How to open and read "feed:" in PHP?
    ... Question: Is a URL that starts with feed: output XML? ... Question: How do I open a feed: URL in PHP and parse it? ... Now you have a SimpleXML object named $rss which you can use to iterate. ... SimpleXML alows you to navigate the xml tree as you wish, ...
    (comp.lang.php)