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 3789810
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:12:59+00:00 2026-05-19T12:12:59+00:00

I am receiving an XML response based on a request I place to a

  • 0

I am receiving an XML response based on a request I place to a server and it does in fact return a valid set of results that I can dump on the screen using print_r()
Result set looks like this(edit: this is the exact structure of the file):

<root>  
     <main_node1>  
         <value1>one</value1>  
         <value2>two</value2>  
     </main_node1>  
     <main_node2>  
         <anothervalue>whatever</anothervalue>  
     </main_node2>  
     <recordset>  
        <record>  
            <value1>one</value1>  
            <value2>two</value2>  
        </reocrd>  
        <record>  
            <value1>one</value1>  
            <value2>two</value2>  
        </reocrd>  
        <record>  
            <value1>one</value1>  
            <value2>two</value2>  
        </reocrd>  
     </recordset>  
</root>

when I use the line:

$xml = simplexml_load_string($xmlRequest);
$records = $xml->recordset->record;  

I can walk through the $records array with a foreach loop without any problems however, when I try to access a specific record within the recordset using an index such as

$record = $xml->recordset->record[$index];  

I am getting a NULL valeu back. I also tried to cast the result into an (array) with no success so far.

Every document I looked at regarding simpleXML says that it is possible to access the XML node by index, can someone please tell me what I might be doing wrong here?

Edit: so recordset is not the root of the document yet I am able to use the $xml->recordset->record notation to load a list of records in to my $records variable and print it out using the foreach loop.

  • 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-05-19T12:13:00+00:00Added an answer on May 19, 2026 at 12:13 pm

    I resolved my issue by using

    $records = $xml->xpath('//record'); 
    

    notation and I am now able to access any record by their index.

    Thank you for trying, I appreciate your efforts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I need to build an application that will receive xml request and based
I am receiving a response from a XML request and I need to deal
I'm receiving the below xml response and I need to parse so that all
I am working on a small project that is receiving XML data in string
I'm receiving feedback from a developer that The only way visual basic (6) can
I am receiving an XML response which comes through perfectly. Words such as português
I am sending a request to webservice and am receiving correct response from web
I am receiving an XML response from an API in a variable r so
I am receiving dynamic xml where I won't know the attribute names, if you'll
We are receiving an XML file from our client. I want to load the

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.