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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:05:40+00:00 2026-05-22T02:05:40+00:00

I’m trying to parse an xml file that has the contents of a simple

  • 0

I’m trying to parse an xml file that has the contents of a simple order form. I’m comfortable with parsing an XML file which would have the contents of such:

<list>
    <item>
    <id>1</id>
    <quantity>14</quantity>
    </item>

    <item>
    <id>2</id>
    <quantity>3</quantity>
    </item>
</list>

Now I would like to be able to parse an xml file that is structured like so. This file is named “order.xml” for future reference.

<main>
<user>
    <address>123 Fake Street, City, STATE, ZIP</address>
    <list>
        <item>
            <id>1</id>
            <quantity>3</quantity>
        </item>
        <item>
            <id>3</id>
            <quantity>4</quantity>
        </item>
    </list>
</user>

<user>
    <address>246 Fake Street, City, STATE, ZIP</address>
    <list>
        <item>
            <id>2</id>
            <quantity>4</quantity>
        </item>
        <item>
            <id>3</id>
            <quantity>4</quantity>
        </item>
    </list>
</user>

</main>

The PHP code for which I’m using to parse the file is as so:

<?php
    // load SimpleXML
    $main = new SimpleXMLElement('order.xml', null, true);
    $list = $main;
    print("<table border = '1'>
    <tr>
        <th>Address</th>
        <th>Item_id</th>
        <th>Quantity</th>
    </tr> ");
    foreach($main as $user) // Loops through the users
    {
        print ("<tr>
            <td>{$user->address}</td>");
        foreach($list as $item)
        {
            print ("<td>{$item->id}</td>
        <td>{$item->quantity}</td></tr>");
        }
    }
    echo '</table>';
?>

so for an output I would like the PHP script to create a table something like the following, but properly formatted in an HTML table for easy viewing.:

       Address   Item_id    Quantity
      Address 1    2          3
      Address 1    3          4
      Address 2    1          1

Thank you very much in advance!

  • 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-22T02:05:41+00:00Added an answer on May 22, 2026 at 2:05 am
    <?php
        // load SimpleXML
        $main = new SimpleXMLElement('order.xml', null, true);
        print("<table border = '1'>
        <tr>
            <th>Address</th>
            <th>Item_id</th>
            <th>Quantity</th>
        </tr> ");
        foreach($main->user as $user) // Loops through the users
        {
            print ("<tr>
                <td>{$user->address}</td>");
            foreach($user->item as $item)
            {
                print ("<td>{$item->id}</td>
            <td>{$item->quantity}</td></tr>");
            }
        }
        echo '</table>';
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an XML file, the creators of it stuck in a bunch social
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

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.