Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SimpleXML and ADO XML

0 views
Skip to first unread message

Álvaro G. Vicario

unread,
Sep 29, 2008, 2:21:59 PM9/29/08
to
I've spent an hour trying to make SimpleXML work until I realized the
problem seems to be namespaces. This code:

<?php
$xml = simplexml_load_file('foo.xml');
print_r($xml);
?>

works fine, unless the XML file contains tags with colons, e.g.:

<rs:data>

In this case, I get an empty object. What am I missing?


I need to parse third-party XML files. I believe it's ADO XML:

http://www.devarticles.com/c/a/XML/Displaying-ADO-Retrieved-Data-with-XML-Islands/2/

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
--

Álvaro G. Vicario

unread,
Oct 10, 2008, 10:20:27 AM10/10/08
to
*** Álvaro G. Vicario escribió/wrote (Mon, 29 Sep 2008 20:21:59 +0200):
> I've spent an hour trying to make SimpleXML work until I realized the
> problem seems to be namespaces. This code:
>
> <?php
> $xml = simplexml_load_file('foo.xml');
> print_r($xml);
> ?>
>
> works fine, unless the XML file contains tags with colons, e.g.:
>
> <rs:data>
>
> In this case, I get an empty object. What am I missing?

For the records: I finally discarded SimpleXML. It's only simple when
you don't have namespaces.

I tried the XMLReader extension with sample code taken from a user
note in the PHP manual and I got it working in a few minutes, although
the code is not intuitive at all. I also tried the DOM extension and
the results were similar, but the code was slightly more intuitive.

Finally, I found a PHP port of JavaScript's jQuery library: phpQuery
[1]. I parsed my XML with a few lines of code and I can even
understand them :) Using such library is probably an overkill but it
was quick and easy.


[1] http://code.google.com/p/phpquery/

0 new messages