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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:32:51+00:00 2026-05-22T11:32:51+00:00

So what I am trying to do is load data from an XML file

  • 0

So what I am trying to do is load data from an XML file into php and use those variables to generate content. For each item i want to get a new set of variable values and print them out onto the page. If there are 4 interfaceItems then it should print 4 displayWrappers with 4 unique titles. This isn’t working for me. Is there a better or more efficient way of doing this? The errors I am getting right now are:

Notice: Trying to get property of non-object

Warning: Invalid argument supplied for foreach()

<?php

$xmldata = simplexml_load_file('elements.xml');
foreach($xmldata->portfolio->interface->interfaceItem as $item) :?>
<?php
$title = ($item->title);
$desc = ($item->description);
$whatOne = ($item->whatOne);    
$whatTwo = ($item->whatTwo);
$location = ($item->location);      

?>
<div class="displayWrapper">
    <div class="display">
        <p> <?=$title ?> </p>
    </div>
</div>



<?php endforeach;?>




<portfolio>
<interface>
    <interfaceItem>
        <title>modi tempora</title>
        <decription>lorum ipsum</decription>
        <whatOne> dolor sit amet</whatOne>
        <whatTwo>sed quia non</whatTwo>         
        <location>i/blah.jpg</location>
    </interfaceItem>
    <interfaceItem>
        <title>magnam aliquam</title>
        <decription>omnis voluptas assumenda est, omnis dolor repellendus.</decription>
        <whatOne>expedita distinctio</whatOne>
        <whatTwo>possimus, omnis voluptas</whatTwo>         
        <location>i/blah2.jpg</location>
    </interfaceItem>
</interface>
</portfolio>
  • 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-22T11:32:51+00:00Added an answer on May 22, 2026 at 11:32 am

    I’m going to take a wild stab in the dark here and reduce it down to one or both of two possible problems.

    Scenario 1

    Your XML file looks like this

    <portfolio>
        <interface>
            <interfaceItem>
    

    With SimleXML, the first element is the root node. You would need to change your code to use

    foreach ($xmldata->interface->interfaceItem as $item)
    

    Scenario 2

    SimpleXML element iteration is case sensitive. If your XML looks like this

    <root>
        <Portfolio>
            <Interface>
                <InterfaceItem>
    

    You would need to change your code to

    foreach ($xmldata->Portfolio->Interface->InterfaceItem as $item)
    

    Update

    Given the XML sample in your question, if that is the contents of elements.xml, it would simply be

    foreach ($xmldata->interfaceItem as $item)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file containing seed data that I'm trying to load into
I am trying to use URLLoader to load an XML file from server (same
I'm facing a rather strange Issue when trying to load data from an XML-Webservice.
I was trying to load a data file into mysql table using LOAD DATA
I am currently trying to load a slightly large xml file into a dataset.
Need to load data from a single file with a 100,000+ records into multiple
I'm needing to load an XML document into PHP that comes from an external
I am trying to output a XML file by fetching data from a dataset.
I am trying to load an XML file from res/raw folder in my Android
I am am trying to load a SQL table from a flat file. 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.