Hey guys, I have the following xml:
[code]
1
Infantry
basicinfantry.jpg
1
2
0
1
1
1000
2
<card_id>2</card_id>
3
3
basicinfantry_lv3.jpg
<card_id>3</card_id>
5
<unit>
<id>4</id>
<name>Bazooka Marine</name>
<picture>bazookamarine.jpg</picture>
<attack>2</attack>
<health>4</health>
<cost>1</cost>
<rarity>1</rarity>
<skill id='pierce' x='1' />
<type>1</type>
<set>1000</set>
<upgrade>
<level>2</level>
<card_id>350</card_id>
<health>5</health>
</upgrade>
<upgrade>
<level>3</level>
<card_id>351</card_id>
<health>6</health>
<skill id='pierce' x='2' />
</upgrade>
</unit>[/code]
I’d like to extract the followed by the and <card_id> values from the last element within each .
E.g. name = Bazooka Marine, level = 3, card id = 351
I made this code to extract all the data i wanted but I dont know to to restrict the results… can anyone help?
[php]$xmlSource = simplexml_load_file(“cards_section_1.xml”);
//print("<pre>".print_r($xmlSource,true)."</pre>");
foreach ($xmlSource->unit as $units) {
printf(
"<p>the card ID for %s at level one is %d.</p>",
$units->name,
$units->id
);
if (isset($units->upgrade)) {
foreach ($units->upgrade as $unitsUpgrade) {
printf(
"<p>the card ID for %s at level %d is %s.</p>",
$units->name,
$unitsUpgrade->level,
$unitsUpgrade->card_id
);
}}}[/php]