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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:43:05+00:00 2026-05-22T20:43:05+00:00

I am new to PHP and XML. Can somebody tell me how can I

  • 0

I am new to PHP and XML.

Can somebody tell me how can I get the values of a sub element or child node of a an xml element?

index.php

$domdoc = new DOMDocument(); 
$domdoc->load('actionstars.xml'); 

foreach ($domdoc->getElementsByTagName("actionstar") as $star) {
 echo $star->item(0)->nodeValue; // displays the <id> element
 echo $star->item(1)->nodeValue; // displays the <name> element
 echo "<br />";
} 

actionstars.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<actionstars>
 <actionstar>
  <id>1</id>
  <name>Jean Claude Van Damme</name>
 </actionstar>
 <actionstar>
  <id>2</id>
  <name>Scott Adkins</name>
 </actionstar>
 <actionstar>
  <id>3</id>
  <name>Dolph Ludgren</name>
 </actionstar>
 <actionstar>
  <id>4</id>
  <name>Michael Jai White</name>
 </actionstar>
 <actionstar>
  <id>5</id>
  <name>Michael Worth</name>
 </actionstar>
</actionstars>

Pls help…

  • 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-22T20:43:06+00:00Added an answer on May 22, 2026 at 8:43 pm

    If you can guarantee their order, you can use childNodes and the offset, otherwise…

    $domdoc = new DOMDocument(); 
    $domdoc->load('actionstars.xml'); 
    
    foreach ($domdoc->getElementsByTagName("actionstar") as $star) {
     echo $shit->getElementsByTagName('id')->item(0)->nodeValue; // displays the <id> element
     echo $shit->getElementsByTagName('name')->item(0)->nodeValue; // displays the <name> element
     echo "<br />";
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a beginner in PHP and XML. Can somebody tell me how to
I am new to PHP. I need to GET a xml stored locally using
A little new to PHP parsing here, but I can't seem to get PHP's
page.xml.php will not show any output, in firebug I can see the get response
Im new to this.I have a cron file called xml.php and i want to
I am trying to setup a wordpress xml-rpc with rails: blog = XMLRPC::Client.new(localhost/blog, /xmlrpc.php,
Im new to PHP and I can't figure out what the rules are for
Using PHP, how do I get an entire subset of nodes from an XML
I have find out how to replace specific node values with PHP string using
I'm relatively new to PHP and I hope you can help me solve my

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.