PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
tsalmeida
Forum Commoner
Posts: 38 Joined: Sat Jul 06, 2013 2:23 pm
Post
by tsalmeida » Fri Jul 19, 2013 12:17 am
Hi,
Im trying to parse a xml with php simplexml load file.
My xml.
Code: Select all
<specification>
<item label="aaa">
<value>1</value>
<value>2</value>
<value>3</value>
<value>4</value>
</item>
<item label="bbb">
<value>5</value>
</item>
<item label="ccc">
<value>6</value>
</item>
</specification>
My php
Code: Select all
foreach ($xml->specification-> children() as $item =>$atr){
echo $atr['label']. '</br>';
}
im just receiving the results for label like:
aaa
bbb
ccc
and i want to show
aaa: 1
2
3
4
bbb: 5
ccc: 6
how can I do this?
Thank you.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Fri Jul 19, 2013 2:32 am
With a second loop.
Code: Select all
foreach ($xml->specification->item as $item) {
echo (string)$item["label"], ": ";
foreach ($item->value as $value) {
echo (string)$value, "<br/>";
}
}
tsalmeida
Forum Commoner
Posts: 38 Joined: Sat Jul 06, 2013 2:23 pm
Post
by tsalmeida » Fri Jul 19, 2013 5:50 pm
Thank You,
Work correctly.