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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:57:54+00:00 2026-06-09T16:57:54+00:00

How my XML node structure works, is I have multiple children elements of parents

  • 0

How my XML node structure works, is I have multiple children elements of parents that also occur multiple times. I am able to get to the children elements, but only the first one of each parent. I am also trying to insert the data in the children elements into MySQL. I just can’t seem to access any child element after the first one. When I echo count(), I’m able to get a total count of the children elements for each reoccurring parent, but I can’t seem to work with that data. Parsing XML is fairly new to me, and my PHP is a bit rusty, so please forgive me. What am I not getting?

Note: The data I’m concerned with is in the mt nodes. The immediate parent of the mt nodes is the mi node.

$string = file_get_contents('file1.xml');
$xml = new SimpleXMLElement($string);

foreach ($xml->md as $mt_tag) {
    if (isset($mt_tag->mi->mt)) {
        $query = "INSERT INTO xmlData(
                xml_data
                ) VALUES (
                '{$mt_tag->mi->mt}'
                )";
        mysql_query($query, $connection);
        echo count($mt_tag->mi->mt);
        echo "<br />";
    } else {
        echo "<p>Creation Failed.<p>";
        echo "<p>" . mysql_error() . "</p>";
    }
}
  • 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-06-09T16:57:56+00:00Added an answer on June 9, 2026 at 4:57 pm

    Youre missing a for loop on the mt nodes:

    foreach ($xml->md as $md_tag) {
           if (isset($md_tag->mi->mt)) {
    
                  foreach ($md_tag->mi->mt as $mt) {
                        //do something
                  }
           }
    }
    

    Please make sure to change this which is inconsistent

    foreach ($xml->md as $mt_tag) {
    

    to

    foreach ($xml->md as $md_tag) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simple XML structure that has to be parsed: <Nodes> <Node
I have several xml files with different node structure. I want to extract xml
I have a XML structure like the following: <Root> <Node Name=File System> <Node Name=C:\Windows\System32\drivers\etc\hosts>
I have an XML that does not have a consistent structure. I need to
how to copy attribute XML node to specified structure or array with one command
Which XML structure allows me faster adding,deleting,updating of a node? My assumption is the
I am having xml with following structure <ruleDefinition appId=3 customerId = acf> <node alias=element1
So I currently have a XML Node at the Item level: <Item> <Item_Number>0000000063089</Item_Number> <English_Description>MOUNTAIN
I have to read the xml node name from the following XML, but I
I have a xml structure similar to below one: <test> <test1>test1 value</test1> </test> Now

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.