PHP - Parse XML subitems using foreach()
Posted
by Nate Shoffner
on Stack Overflow
See other posts from Stack Overflow
or by Nate Shoffner
Published on 2010-04-25T02:25:58Z
Indexed on
2010/04/25
2:33 UTC
Read the original article
Hit count: 224
I have an XML file that needs parsing in PHP. I am currenlty using simplexml_load_file to load the file like so:
$xml = simplexml_load_file('Project.xml');
Inside that XML file lies a structure like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<project>
<name>Project 1</name>
<features>
<feature>Feature 1</feature>
<feature>Feature 2</feature>
<feature>Feature 3</feature>
<feature>Feature 4</feature>
</features>
</project>
What I am trying to do is print the <name>
contents along with EACH <feature>
element within <features>
. I'm not sure how to do this because there is more than 1 element called <feature>
. Any help is greatly appreciated.
© Stack Overflow or respective owner