SimpleXML and ADO XML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?iso-8859-1?Q?=C1lvaro?= G. Vicario

    SimpleXML and ADO XML

    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://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
    --
  • =?iso-8859-1?Q?=C1lvaro?= G. Vicario

    #2
    Re: SimpleXML and ADO XML

    *** Á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
    --

    Comment

    Working...