?
Solved

PHP Read XML Items

Posted on 2012-04-04
2
Medium Priority
?
277 Views
Last Modified: 2012-04-04
Hi all,

I'm loading a XML this way... using PHP

$xml = simplexml_load_file(PATH);

I can get any member by calling

$param = (string)$xml->Node->Child1;

No problem... i can read Child1, Child2, etc...

But, when i have multiple nodes with the same name...

Example

<det nItem="1">
<prod>
  <child1>HELLO</child1>
  <child2>WORLD</child2>
</prod>
</det>
<det nItem="2">
<prod>
  <child1>ITS ME</child1>
  <child2>DET AGAIN!</child2>
</prod>
</det>
<det nItem="3">
<prod>
  <child1>ITS ME</child1>
  <child2>AGAIN AGAIN!</child2>
</prod>
</det>

Ok, we have multiple "det" nodes... differentiated by "nItem" property

How to walk for every "det" nodes getting its content?

$param = (string)$xml->det?!->Child1;

Forget about "node" and "child"... my english is poor sorry...

regards,
0
Comment
Question by:cebasso
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 2000 total points
ID: 37808211
$xml = simplexml_load_file(...);

foreach ($xml->det as $value)
{ 
  echo $value->prod->child1.'<br \>';
  echo $value->prod->child2.'<br \><br \>';
}

Open in new window


Bye, Olaf.
0
 
LVL 4

Author Closing Comment

by:cebasso
ID: 37808277
Perfect!
Thank you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question