Ich habe folgende *.xml Datei:
Code:
<?xml version="1.0" encoding="utf-8"?>
<Items>
<!-- possible types -->
<Item id="0" name="Laser1" type="weapon" requeiredItemID="-1">
<!--
id : id des Gegenstandes
name : Name des Gegenstandes
type : Typ (weapon, weaponaddon, shield, shieldaddon, armor, armoraddon, cargoaddon)
required : ID eines Gegenstandes der für diesen benötigt wird
-->
<Description>Laser 1 descriptions goes here</Description>
<Price>10000</Price>
<Weight>2000</Weight>
<CargoSize>2</CargoSize>
<IsIllegal>False</IsIllegal>
<map name="affects">
<affects type="shield" value="-100">
<affects type="armor" value="-50">
</map>
</Item>
<Item id="1" name="Laser2" type="cargo" requiredItemID="-1">
<Description>Laser II description goes here</Description>
<Price>20000</Price>
<Weight>4000</Weight>
<CargoSize>3</CargoSize>
<IsIllegal>False</IsIllegal>
<map name="affects">
<affects type="shield" value="-200"/>
<affects type="armor" value="-100"/>
</map>
</Item>
<Item id="2" name="Laser3" type="shield" requeiredItemID="-1">
<Description>Laser III description goes here</Description>
<Price>40000</Price>
<Weight>8000</Weight>
<CargoSize>4</CargoSize>
<IsIllegal>False</IsIllegal>
<map name="affects">
<affects type="shield" value="-400"/>
<affects type="armor" value="-200"/>
</map>
</Item>
</Items>
Ich bekomme die Elemente Items ums verrecken nicht eingelesen, bzw. nur das erste..
Hier der Code, hat jemand einen Tipp für mich?
Code:
TiXmlDocument doc(StringConversions::ToString(fileName).c_str());
doc.LoadFile();
TiXmlElement *root = doc.FirstChildElement("Items");
if (root) {
Item *gameItem = NULL;
TiXmlHandle handleDoc(&doc);
TiXmlElement *root = handleDoc.FirstChildElement().ToElement();
TiXmlHandle rootHandle = TiXmlHandle(root);
for(TiXmlElement *item = rootHandle.FirstChild("Item").ToElement(); item; item = item->NextSiblingElement()) {
gameItem = new Item();
irr::s32 id = atoi(item->Attribute("id"));
String name = item->Attribute("name");
String type = item->Attribute("type");
irr::s32 requiredID = atoi(item->Attribute("requeiredItemID"));
String description = item->FirstChildElement("Description")->GetText();
irr::f64 price = atof(item->FirstChildElement("Price")->GetText());
irr::s32 weight = atoi(item->FirstChildElement("Weight")->GetText());
irr::s32 cargoSize = atoi(item->FirstChildElement("CargoSize")->GetText());
String illegal = item->FirstChildElement("IsIllegal")->GetText();
bool isIllegal = false;
if (illegal == "TRUE" || illegal == "true" || illegal == "True") {
isIllegal = true;
}
gameItem->SetID(id);
gameItem->SetName(name);
gameItem->SetItemType(this->getItemType(type));
gameItem->SetRequiredID(requiredID);
gameItem->SetDescription(description);
gameItem->SetPrice(price);
gameItem->SetWeight(weight);
gameItem->SetCargoSize(cargoSize);
gameItem->SetIsIllegal(isIllegal);
_itemList.push_back(gameItem);
}
}