views:

2534

answers:

2

Is there a way to read off from an [external] xml (an xml file from a different website) using PHP? I know there's a way to read XML using JavaScript, but only if they are both in the same root.

Could you provide an example on how to source the xml file, then read the following:

<parent>
    <child>
        <grandchild>Example Text 1</grandchild>
    </child>

    <child>
        <grandchild>Example Text 2</grandchild>
    </child>
</parent>

Thanks!

+1  A: 

Use fopen to read files over http and take your pick of the approaches to read XML.

David Dorward
+6  A: 

The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators.

http://us2.php.net/manual/en/simplexml.examples-basic.php

gahooa
+1 extension: see the load function. I personally use this approach to pull from my twitter account.
geowa4
I recommend SimpleXML extension, too. I'm also using it for some twitter stuff.
DASKAjA
This is really good, but what's the code to read it off of a foreign XML file? What I need to do is display results from an XML file that's on a different page (kinda like loading data from twitter).Thanks a lot guys.
Michal Kopanski