I was working on a project for XML Parsing.
I came across instances where my elements were completely missing.
After further Digging into the issue, I found out, that when placing tags inside of an element with text, SimpleXML (and dom Document) ignore the added tags, and the text within.
Heres an example.
-----------ok.xml-----------------
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Document>
<Article>
<Title pagenum="84" docname="Career Path mar 08">Is Your Face on Facebook? </Title>
<Subtitle>Employ simple strategies to market your ?profile? using online social networking.</Subtitle>
<Body>Temp Testing Example of SimpleXML Bug.<b>Is it a bug though?</b></Body>
<Folio>Trying to just show Examples</Folio>
</Article>
</Document>
-----------ok.xml-----------------
-----------ok.php-----------------
<?php
$file = file_get_contents('ok.xml');
$xml = new SimpleXMLElement($file);
print_r($xml);
print $xml->Article->Body->b . "\n";
-----------ok.php-----------------
-----------output-----------------
SimpleXMLElement Object
(
[Article] => SimpleXMLElement Object
(
[Title] => Is Your Face on Facebook?
[Subtitle] => Employ simple strategies to market your ?profile? using online social networking.
[Body] => Temp Testing Example of SimpleXML Bug.
[Folio] => Trying to just show Examples
)
)
Is it a bug though?
-----------output-----------------
Furthermore if I place <b> tags at the beginning of of the <Body> tags
ie.
<Body><b>Testing</b>Temp Testing Example of SimpleXML Bug.<b>Is it a bug though?</b></Body>
The text between the </b> and <b> is ignored and is output as follows..
-----------output---------------
SimpleXMLElement Object
(
[Article] => SimpleXMLElement Object
(
[Title] => Is Your Face on Facebook?
[Subtitle] => Employ simple strategies to market your ?profile? using online social networking.
[Body] => SimpleXMLElement Object
(
[b] => Array
(
[0] => Testing
[1] => Is it a bug though?
)
)
[Folio] => Trying to just show Examples
)
)
Testing
-----------output---------------
The above output is using ok.php.
Is this working as intended?
SimpleXML has some serious
SimpleXML has some serious quirks in it. Here is another one I stumbled on today. They marked it as "Wont fix".
http://bugs.php.net/bug.php?id=29500
I think it'd be better if you
I think it'd be better if you put the content of Body in CDATA especially if it contains HTML.
Of course, and that
Of course, and that definitely works. However, even if the element isn't HTML, it still doesn't work.
And to clarify, this was XML that Quark was generating so I cant entirely change that unless I submit a bug to the Quark team and/or Preprocess the xml files and add the CDATA tags.