Solved

PHP Read XML Items

Posted on 2012-04-04
2
272 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 500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

749 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