Bug in SimpleXML?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux