Note: I've made some minor adjustments to your XML so it would be well-formed:
- Added a top level
<areas>
node;
- Added the corresponding close tag for each
<area>
node.
From your question tag I assume you're trying to use SimpleXML, so here's a code snippet that can help you retrieve the data you want.
<?php
$xml = <<<XML
<areas>
<area name="Abjurer Grove">
<monster short="Nikwasli the Catfolk Apprentice" exp="319112" info="acid arrow" race="Catfolk" align="good" god="none" />
<monster short="An extra fluffy sheep" exp="49271" race="Sheep" align="good" god="none" />
<monster short="Slireistar the Treant Master Abjurer" race="Treant" align="good" god="Silvain" />
<monster short="Alkinoyine the Djinni Master Abjurer" race="Djinni" align="good" god="Aquaris" />
<monster short="Arthorian the Guildmaster of the Abjurers" align="good" god="none" race="Human" />
<monster short="Katalare the Ent Master Abjurer" race="Ent" align="good" god="Silvain" />
<monster short="An older dwarf with a long beard and a sharp pick" race="Dwarf" eq="A well used iron pick (2h), A pair of brown leggings" info="kick, brawl?" exp="271681" />
<monster short="A older dwarf named Hargris Doc, leaning on his pick" race="Dwarf" eq="A light blue working-class shirt, A well used iron pick (2h), A simple cloth belt, A warm pair of woolen pants, An expertly made pair of high quality boots" align="sli good" god="none" />
<monster short="A grumpy young dwarf is mining here" race="Dwarf" eq="A well used iron pick (2h), An olive coloured pair of pants / A pair of shiney black leather pants with silver studs" exp="256087" />
<monster short="Fredzin the crazed Dwarf" info="aggr, kungfu, cancellation" race="Dwarf" eq="A cheaply made grey shirt, A pressed pair of black trousers" exp="120280" palpoints="93" align="evil" god="Teros" />
<monster short="Zoreil the Mind flayer Adept Apprentice" race="Mind flayer" exp="1151225" align="evil" god="Kirvana" info="tentacle drain (drains sps), acid arrow" />
<monster short="Anthiala, a beautiful elven scholar working in the tower" race="Elf" />
<monster short="A hard working grumpy dwarf swinging a pick" exp="245112" info="kick" race="Dwarf" eq="A well used iron pick (2h), A pair of brown leggings" align="evil" palpoints="126" god="Teros" />
<monster short="A dwarf, covered in grime from a day in the mines" exp="228719" align="evil" palpoints="111" eq="A well used iron pick (2h), A plain white pair of pants" />
</area>
<area name="Agnarock">
<monster short="The Icedragon 'Kel'ba'rash'" exp="5755726" race="Dragon" palpoints="3000" align="extr evil" god="none" />
<monster short="Muscular Giant Recruit." exp="138754" eq="Giants breastplate" race="Giant" align="good" god="Silvain" />
<monster short="Strong looking outer valley Giant" exp="141396" eq="Giants breastplate" race="Giant" align="good" god="Silvain" />
<monster short="A strong looking giant recruit" exp="67153" race="Giant" eq="Thick wooden shield, Ugly Giant boots (smelling)" align="good" god="Silvain" />
<monster short="A hairy, strong looking elite Giant warrior" exp="294573" race="Giant" info="bladed fury" eq="A Lochaber (2h), A huge giant sword (2h), Giant leather pants" align="good" god="Silvain" />
<monster short="Blue wearing Giant warrior" exp="463955" eq="Battlemail of the Giant Army, A shimmering Halberd (2h), Giant leather pants" race="Giant" align="sli good" god="Silvain" />
<monster short="All black Giant Fighter" exp="1271226" race="Giant" align="sli good" god="Silvain" eq="A multicolored cloak, Elite Platemail of Angarock, A shimmering Halberd (2h) x 2, Giant leather pants" />
<monster short="A female giant warrior of Angarock" exp="3135812" race="Giant" />
<monster short="Karbitsch the Hobbit, Herald of Shakadoom." exp="6559714" race="Hobbit" eq="Karbitsch's pants of Quickness, Speed shoes of Karbitsch" />
<monster short="Shaikuub, Grandwarriorlord of Angarock" exp="5100480" race="Giant" eq="Black axe named 'Deathstorm' (2h), The Executioner (2h)" />
<monster short="Deschoga the Djinni, Unholy Master of the Assassins." exp="10759793" race="Djinni" eq="The Bonemask of Disappearence, Gaseous Gloves, Claws of Assassination (2h)" />
</area>
</areas>
XML;
// Retrieve each monster node's short attribute using XPath
$sxe = new SimpleXMLElement($xml);
$monsters = $sxe->xpath('//monster');
// Iterate all monster nodes
foreach ($monsters as $monster) {
// Retrieve each monster node attributes
$monsterAttributes = $monster->attributes();
print_r($monsterAttributes);
// Database insert operation
}
Output:
I didn't include the whole output, you can check that in this codepad live example. Notice how each of these objects reflect the different attributes from each node. All you have to do is process them as store them at your will in your DB.
SimpleXMLElement Object
(
[@attributes] => Array
(
[short] => Nikwasli the Catfolk Apprentice
[exp] => 319112
[info] => acid arrow
[race] => Catfolk
[align] => good
[god] => none
)
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[short] => An extra fluffy sheep
[exp] => 49271
[race] => Sheep
[align] => good
[god] => none
)
)
SimpleXMLElement Object
(
[@attributes] => Array
(
[short] => Slireistar the Treant Master Abjurer
[race] => Treant
[align] => good
[god] => Silvain
)
)