Issues with simplexml_load_string()

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

 



It seems like when dealing with nodes which have CDATA, I cannot get
access to both the attributes of that node and the CDATA of that node
with the same simplexml_load_string() call.  Consider the following:

$previewString =
'<root><message><![CDATA[lkjlkjklj]]></message><buttons><button
name="Add Me"><![CDATA[This is my free form
text]]></button></buttons></root>';

When passing LIBXML_NOCDATA:

echo '<pre>' . print_r( json_decode( json_encode(
(array)simplexml_load_string( $previewString, 'SimpleXMLElement',
LIBXML_NOCDATA | LIBXML_NOBLANKS )), 1 ), TRUE ) . '</pre>';

yields the following output :

Array
(
   [message] => lkjlkjklj
   [buttons] => Array
       (
           [button] => This is my free form text
       )
)

So I get the CDATA but I don't get the "name" attribute for the button.

When not using LIBXML_NOCDATA:

echo '<pre>' . print_r( json_decode(
json_encode((array)simplexml_load_string( $previewString,
'SimpleXMLElement', LIBXML_NOBLANKS )), 1 ), TRUE ) . '</pre>';

yields the following output :

Array
(
   [message] => Array
       (
       )
   [buttons] => Array
       (
           [button] => Array
               (
                   [@attributes] => Array
                       (
                           [name] => Add Me
                       )
               )
       )
)

I get the attributes but not the CDATA.  Looking at the doc page for
simplexml_load_string()
(http://us.php.net/manual/en/function.simplexml-load-string.php and
http://us.php.net/manual/en/libxml.constants.php), I don't see a way
to get access to both.  Am I missing something?  Or is this really not
possible?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[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