0

I want to parse a xml document which is located on another domain. I want to do this with PHP. Is it possible?

I've already try simpleXML but it doesn't seems to work.

3
  • 5
    Yes, it's possible. What exactly isn't working? What errors are you getting? Can you show some code? Commented Feb 20, 2012 at 20:17
  • 1
    The answer to your question is "yes", however I get the impression that that's not what you're looking for. What have you tried? Commented Feb 20, 2012 at 20:18
  • oops sorry <?php if (file_exists('stevymahy.com/xml/test.xml')) { $xml = simplexml_load_file('stevymahy.com/xml/test.xml'); print_r($xml); } else { exit('Cannot open the xml file.'); } ?> Commented Feb 20, 2012 at 20:32

1 Answer 1

3

WEll first of all: http://www.stevymahy.com/xml/test.xml has malformed XML. You will not be able to parse this document until its fixed.

Whats up there now

    <?xml version="1.0" encoding="utf-8"?>
    <mahy>
    <!-- Diaporama -->
        <diaporama duree="4">
        <photo fichier="/admin/uploads/stevy01_001.jpg"></photo>
        <photo fichier="/admin/uploads/stevy05_001.jpg"></photo>
        <photo fichier="/admin/uploads/stevy06_001.jpg"></photo>
        <photo fichier="/admin/uploads/DSC_8133-Modifier.jpg"></photo>
        <photo fichier="/admin/uploads/appuyevelo.jpg"></photo>
        <photo fichier="/admin/uploads/atriumplus.jpg"></photo>
        <photo fichier="/admin/uploads/balancoirine.jpg"></photo>
    </diaporama>

    <!-- Biographie -->
    <bio textetaille="16" ><![CDATA[jhkjdhgkjdhgjksdghkjshgjkshdgjkhsdgjksdhgjksdhgkj]]></bio>

It just trails off... EDIT: I've posted the full XML. It doesn't trail off (anymore?). However the diaporama and bio elements must be contained in a common root node. so maybe wrap everything in <root>

After you get that fixed

http://www.php.net/manual/en/function.file-get-contents.php http://www.php.net/manual/en/simplexml.examples-basic.php

    // Get the contents of the XML
    $str_xml = file_get_contents('http://www.stevymahy.com/xml/test.xml');

    // Parse the XML
    $obj_xml = new SimpleXMLElement($str_xml);

    // ...do something with the parsed XML object
Sign up to request clarification or add additional context in comments.

1 Comment

Check to see if your XML is valid: validator.w3.org/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.