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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:54:46+00:00 2026-05-29T20:54:46+00:00

I have an XML stream parsed to a SimpleXMLElement Object and I am trying

  • 0

I have an XML stream parsed to a SimpleXMLElement Object and I am trying to iterate though the available records to use as values in a PHP page.

The parent node of [listing] currently exists twice as there are two records in the test XML (listing[0] and listing[1])
But I can not get this to work like shown on the “Basic SimpleXML usage” from the PHP Manual

    <?php
    $xml = simplexml_load_file('http://feed.postlets.com/Burndog/6458ec1af54f632');

This works to provide the first listing title element value:

    $value1 = $xml->listing[0]->title;
    echo ' here:' . $value1;

This fails to iterate through the available values:

    foreach ($xml->listing->title as $title) {
    echo $title;
    }
    ?>

values from a print_r:

SimpleXMLElement Object
(
[listing] => Array
    (
        [0] => SimpleXMLElement Object
            (
                [url] => http://www.postlets.com/repb/6509636
                [title] => 3BR/2BA Manufactured - Beaumont
                [subtitle] => SimpleXMLElement Object
                    (
                    )

                [description] => SimpleXMLElement Object
                    (
                    )

                [location] => SimpleXMLElement Object
                    (
                        [street] => 1415 E 6th St
                        [city] => Beaumont
                        [zipcode] => 92223
                        [state] => CA
                        [latitude] => 33.928326
                        [longitude] => -116.959923
                        [walkscore] => 46
                    )

                [details] => SimpleXMLElement Object
                    (
                        [money] => SimpleXMLElement Object
                            (
                                [price] => 44900
                            )

                        [property_for] => Sale
                        [property_use] => Residential
                        [property_type] => Manufactured
                        [year_built] => 2011
                        [bedrooms] => 3
                        [full_bathrooms] => 2
                        [partial_bathrooms] => 0
                        [sqft] => 1041
                        [lot_size] => 1045 sqft
                        [parking] => SimpleXMLElement Object
                            (
                            )

                    )

                [photos] => SimpleXMLElement Object
                    (
                        [photo_1] => http://www.postlets.com/create/photos/20111101/082821_6509636_158803034.jpg
                        [photo_caption_1] => Photo 1
                        [photo_2] => http://www.postlets.com/create/photos/20111101/082822_6509636_3416721218.jpg
                        [photo_caption_2] => Photo 2
                        [photo_3] => http://www.postlets.com/create/photos/20111101/082822_6509636_1298858591.jpg
                        [photo_caption_3] => Photo 3
                    )

                [contact] => SimpleXMLElement Object
                    (

                    )

            )

        [1] => SimpleXMLElement Object
            (
                [url] => http://www.postlets.com/repb/7066849
                [title] => 2BR/1+1BA Manufactured - Beaumont
                [subtitle] => SimpleXMLElement Object
                    (
                    )

                [description] => SimpleXMLElement Object
                    (
                    )

                [location] => SimpleXMLElement Object
                    (
                        [street] => 1415 E 6th St # 12
                        [city] => Beaumont
                        [zipcode] => 92223
                        [state] => CA
                        [latitude] => 33.929199
                        [longitude] => -116.959831
                        [walkscore] => 46
                    )

                [details] => SimpleXMLElement Object
                    (
                        [money] => SimpleXMLElement Object
                            (
                                [price] => 56000
                                [hoa] => 400
                            )

                        [property_for] => Sale
                        [property_use] => Residential
                        [property_type] => Manufactured
                        [year_built] => 1997
                        [bedrooms] => 2
                        [full_bathrooms] => 1
                        [partial_bathrooms] => 1
                        [sqft] => 1250
                        [lot_size] => 3000 sqft
                        [property_features] => Central A/C, Dining room, Breakfast nook, Dryer
                        [community_features] => Covered parking
                        [parking] => SimpleXMLElement Object
                            (
                            )

                    ) etc etc

Then what will it take to loop through the elements for pictures as there is more than one?
Thanks!

  • 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-29T20:54:48+00:00Added an answer on May 29, 2026 at 8:54 pm

    As you can see in your print_r output, the ‘listing’ field of the XML-Object is the array, not the title. So what you have to do is iterate through the listings and print out each listings title:

    foreach ($xml->listing as $listing)
    {
        echo $listing->title;
    }
    

    To print out the pictures you’d do something like this:

    foreach ($xml->listing as $listing)
    {
        echo "Title: " . $listing->title . "<br>";
    
        foreach ($listing->photos->children() as $child)
        {
            echo $child . "<br>";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stream object, and I want to create and output xml using
I have a method which returns some xml in a memory stream private MemoryStream
I have xml where some of the element values are unicode characters. Is it
I have a jqgrid with data loading from an xml stream (handled by django
I have a simple object I'm trying to serialize using DataContractSerializer. In my unit
I have some classes that already use DOM4J to read XML files and provide
I have XML data as a string which has to parsed, I am converting
I'm having an issue with trying to use VB.NET and the WebRequest object to
I have a stream of xml being returned from a webservice which is coming
I have an XML stream I want to parse using SAX. What I actually

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.