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

  • Home
  • SEARCH
  • 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 6079955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:00:24+00:00 2026-05-23T11:00:24+00:00

I am parsing xml using simplexml_load_string like this : $xml = simplexml_load_string($response); echo ‘{‘.

  • 0

I am parsing xml using simplexml_load_string like this :

 $xml = simplexml_load_string($response);

        echo '{'.
            '"Date":"'.$xml->Date[0].'",'.
            '"Description":"'.$xml->ShipTos->ShipTo->ShippingGroups->ShippingGroup->OrderItems->OrderItem->Description[0].'",'. 
            '"Track":"'.$xml->Shipments->Shipment->Track[0].'"'.
            '}'; 

This works ok but if a node appears in the xml multiple times it only grabs it once. Can someone please help me understand how I would write a foreach loop specifically for the Description node?

  • 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-23T11:00:24+00:00Added an answer on May 23, 2026 at 11:00 am

    You are only referring to one instance of each SimpleXMLObject.
    For example $xml->Date[0] refers to the first occurence of a Date object only. To print all Date objects you need to
    loop through them

    foreach( $xml->Date as $date ){
       print (string)$date;
    }
    

    Alternatively, you could use the children function:

    foreach( $xml->children('Date') as $date ){
       print (string)$date;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some problems parsing this piece of XML using SimpleXML. There is
this is my first time using StAX for parsing XML documents (still in the
I am Parsing XML currently using: $data = simplexml_load_string($xmlFile); foreach($data->item as $key => $current){
I'm parsing an xml file using Python's ElementTree, like that: et = ElementTree(file=file(test.xml)) test.xml
I'm having trouble parsing this xml file using jquery: <?xml version=1.0 encoding=utf-8?> <?mso-infoPathSolution name=urn:schemas-microsoft-com:office:infopath:BOT-Memos:-myXSD-2011-07-13T14-29-57
I am doing this tutorial but with a diferent xml http://blog.insicdesigns.com/2009/03/parsing-xml-file-using-codeigniters-simplexml-library/ , but I
I tried parsing this huge XML document using XML minidom . While it worked
I'm currently using JDOM for doing some simple XML parsing, and it seems like
I am looking to create an expression tree by parsing xml using C#. The
I have an expression tree I have created by parsing an Xml using 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.