By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

SimpleXML and ADO XML

P: n/a
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/D...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
--
Sep 29 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
*** Á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/
--
-- 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
--
Oct 10 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.