Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8164165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:15:21+00:00 2026-06-06T19:15:21+00:00

Right, so this is my first day using XML. I’m not creating the XML,

  • 0

Right, so this is my first day using XML. I’m not creating the XML, someone is sending me a URL and I need to do something with it using PHP. This is what the XML structure looks like:

<response>
<query id="1">
<results>
    <item>
        <id>GZ7w39jpqwo</id>
        <rank>1</rank>
        <explanation>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla a massa lectus, sed convallis sapien. Curabitur sem mauris, ullamcorper ut. </explanation>
    </item>
    <item>
        <id>hfMNRUAwLVM</id>
        <rank>2</rank>
        <explanation>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla a massa lectus, sed convallis sapien. Curabitur sem mauris, ullamcorper ut. </explanation>
    </item>
    <item>
        <id>I_cxElavpS8</id>
        <rank>3</rank>
        <explanation>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla a massa lectus, sed convallis sapien. Curabitur sem mauris, ullamcorper ut. </explanation>
    </item>
</results>
</query>
</response>

So, yeah, this is what I’ve figured out so far…

$url = "http://www.MyURL.blah";

$string = file_get_contents($url);

$xml = simplexml_load_string($string);

echo $xml->getName();

This echoes the word ‘response’. Yay, go me! So now how the hell do you get the id, rank, and explanation of each item? I only posted 3 items above. There’ll actually be about 50.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:15:23+00:00Added an answer on June 6, 2026 at 7:15 pm

    This example may help you, it used using DOMDocument.

    $document = new DOMDocument(); //Creates a new DOM Document (used to process XML)
    $document->loadXML($fileContents); //Load the XML file from an string
    $resultsNode = $document->getElementsByTagName("results")->item(0); //Get the node with the results tag
    foreach($resultsNode->childNodes as $itemNode) //Get each child node (item) and process it
    {
        foreach($itemNode->childNodes as $unknownNode) //Get each child node of item and process it
        {
            if($unknownNode->nodeName == "id") //Check if it's the dessired node
            {
                $this->id = $unknownNode->value; //Assign the value of the node to a variable
            }
            if($unknownNode->nodeName == "rank")
            {
                $this->rank = $unknownNode->value;
            }
            if($unknownNode->nodeName == "explanation")
            {
                $this->explanation = $unknownNode->value;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first app and i need to be using dates i want
This is my first day coding and using jquery, I figured the best way
Right so some really noob(this is my first deployment of a bundle to Karaf)
First of all I don't know if this is the right approach. I want
My first post here, so i hope this is the right area. I am
Right this is confusing me quite a bit, i'm not sure if any of
Not sure I heard this right, but VS2010 no longer has support for Wix?
I must confess that today is my first day using either Sweave or LaTeX.
So right now I'm using this query: select * from items where mydate =
This is my first day of jQuery, so bear with me. Currently, I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.