本文整理汇总了C++中xml::Document::rootNode方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::rootNode方法的具体用法?C++ Document::rootNode怎么用?C++ Document::rootNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml::Document
的用法示例。
在下文中一共展示了Document::rootNode方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
void ColorDB::load()
{
if (mLoaded)
return;
XML::Document *doc = new XML::Document(HAIR_COLOR_FILE);
xmlNodePtr root = doc->rootNode();
bool TMWHair = false;
if (!root || !xmlStrEqual(root->name, BAD_CAST "colors"))
{
logger->log("Trying TMW's color file, %s.", TMW_COLOR_FILE);
TMWHair = true;
delete doc;
doc = new XML::Document(TMW_COLOR_FILE);
root = doc->rootNode();
if (!root || !xmlStrEqual(root->name, BAD_CAST "colors"))
{
logger->log("ColorDB: Failed");
mColors[0] = mFail;
mLoaded = true;
delete doc;
return;
}
}
for_each_xml_child_node(node, root)
{
if (xmlStrEqual(node->name, BAD_CAST "color"))
{
int id = XML::getProperty(node, "id", 0);
if (mColors.find(id) != mColors.end())
logger->log("ColorDB: Redefinition of dye ID %d", id);
mColors[id] = TMWHair ? XML::getProperty(node, "value", mFail) :
XML::getProperty(node, "dye", mFail);
}
}
delete doc;
mLoaded = true;
}
示例2: loadXmlFile
void SoundDB::loadXmlFile(const std::string &fileName)
{
XML::Document *doc = new XML::Document(fileName);
const XmlNodePtrConst root = doc->rootNode();
if (!root || !xmlNameEqual(root, "sounds"))
{
delete doc;
return;
}
for_each_xml_child_node(node, root)
{
if (xmlNameEqual(node, "include"))
{
const std::string name = XML::getProperty(node, "name", "");
if (!name.empty())
loadXmlFile(name);
continue;
}
else if (xmlNameEqual(node, "sound"))
{
const std::string name = XML::getProperty(node, "name", "");
const int id = NotifyManager::getIndexBySound(name);
if (id)
{
const std::string value = XML::getProperty(node, "value", "");
mSounds[id] = value;
}
}
}
delete doc;
}
示例3: load
void EffectDB::load()
{
if (!mLoaded)
return;
const XML::Document doc("effects.xml");
const xmlNodePtr root = doc.rootNode();
if (!root || !xmlStrEqual(root->name, BAD_CAST "being-effects"))
{
logger->log("Error loading being effects file: effects.xml");
return;
}
else
logger->log("Effects are now loading");
for_each_xml_child_node(node, root)
{
if (xmlStrEqual(node->name, BAD_CAST "effect"))
{
EffectDescription ed;
ed.id = XML::getProperty(node, "id", -1);
ed.GFX = XML::getProperty(node, "particle", "");
ed.SFX = XML::getProperty(node, "audio", "");
mEffects.push_back(ed);
}
}
mLoaded = true;
}
示例4: loadInfo
void MapDB::loadInfo(const std::string &fileName,
const SkipError skipError)
{
XML::Document *doc = new XML::Document(fileName,
UseResman_true,
skipError);
const XmlNodePtrConst root = doc->rootNode();
if (!root)
{
delete doc;
return;
}
for_each_xml_child_node(node, root)
{
if (xmlNameEqual(node, "map"))
{
readMap(node);
}
else if (xmlNameEqual(node, "atlas"))
{
readAtlas(node);
}
else if (xmlNameEqual(node, "include"))
{
const std::string name = XML::getProperty(node, "name", "");
if (!name.empty())
loadInfo(name, skipError);
continue;
}
}
delete doc;
}
示例5: load
void EmoteDB::load()
{
if (mLoaded)
return;
mLastEmote = 0;
logger->log("Initializing emote database...");
const XML::Document doc("emotes.xml");
const xmlNodePtr rootNode = doc.rootNode();
if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "emotes"))
{
logger->log("Emote Database: Error while loading emotes.xml!");
return;
}
//iterate <emote>s
for_each_xml_child_node(emoteNode, rootNode)
{
if (!xmlStrEqual(emoteNode->name, BAD_CAST "emote"))
continue;
const int id = XML::getProperty(emoteNode, "id", -1);
if (id == -1)
{
logger->log("Emote Database: Emote with missing ID in emotes.xml!");
continue;
}
EmoteInfo *currentInfo = new EmoteInfo();
for_each_xml_child_node(spriteNode, emoteNode)
{
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
EmoteSprite *currentSprite = new EmoteSprite();
std::string file = "graphics/sprites/" + (std::string)
(const char*) spriteNode->xmlChildrenNode->content;
currentSprite->sprite = AnimatedSprite::load(file,
XML::getProperty(spriteNode, "variant", 0));
currentInfo->sprites.push_back(currentSprite);
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
{
std::string particlefx = (const char*) spriteNode->xmlChildrenNode->content;
currentInfo->particles.push_back(particlefx);
}
}
mEmoteInfos[id] = currentInfo;
if (id > mLastEmote)
mLastEmote = id;
}
mLoaded = true;
}
示例6: load
void CharDB::load()
{
if (mLoaded)
unload();
XML::Document *doc = new XML::Document(
paths.getStringValue("charCreationFile"),
true,
false);
const XmlNodePtrConst root = doc->rootNode();
if (!root || !xmlNameEqual(root, "chars"))
{
logger->log("CharDB: Failed to parse %s.",
paths.getStringValue("charCreationFile").c_str());
delete doc;
return;
}
for_each_xml_child_node(node, root)
{
if (xmlNameEqual(node, "haircolor"))
{
loadMinMax(node, &mMinHairColor, &mMaxHairColor);
}
else if (xmlNameEqual(node, "hairstyle"))
{
loadMinMax(node, &mMinHairStyle, &mMaxHairStyle);
}
else if (xmlNameEqual(node, "look"))
{
loadMinMax(node, &mMinLook, &mMaxLook);
}
else if (xmlNameEqual(node, "stat"))
{
loadMinMax(node, &mMinStat, &mMaxStat);
mSumStat = XML::getProperty(node, "sum", 0);
}
else if (xmlNameEqual(node, "item"))
{
const int id = XML::getProperty(node, "id", 0);
if (id > 0)
mDefaultItems.push_back(id);
}
else if (xmlNameEqual(node, "race"))
{
loadMinMax(node, &mMinRace, &mMaxRace);
}
}
delete doc;
mLoaded = true;
}
示例7: loadHair
void ColorDB::loadHair(const std::string &fileName,
std::map<ItemColor, ItemColorData> &colors)
{
XML::Document *doc = new XML::Document(fileName,
UseResman_true,
SkipError_false);
const XmlNodePtrConst root = doc->rootNode();
if (!root || !xmlNameEqual(root, "colors"))
{
logger->log("ColorDB: Failed to find hair colors file.");
if (colors.find(ItemColor_zero) == colors.end())
colors[ItemColor_zero] = ItemColorData(ItemColor_zero, "", "");
delete doc;
return;
}
for_each_xml_child_node(node, root)
{
if (xmlNameEqual(node, "include"))
{
const std::string name = XML::getProperty(node, "name", "");
if (!name.empty())
loadHair(name, colors);
continue;
}
else if (xmlNameEqual(node, "color"))
{
const ItemColor id = fromInt(XML::getProperty(
node, "id", 0), ItemColor);
if (colors.find(id) != colors.end())
{
logger->log("ColorDB: Redefinition of dye ID %d",
toInt(id, int));
}
colors[id] = ItemColorData(id, XML::langProperty(node, "name", ""),
XML::getProperty(node, "value", "#FFFFFF"));
}
}
示例8: load
void EffectDB::load()
{
if (!mLoaded)
return;
const XML::Document doc("effects.xml");
const xmlNodePtr root = doc.rootNode();
if (!root || !xmlStrEqual(root->name, BAD_CAST "being-effects"))
{
logger->log("Error loading being effects file: effects.xml");
return;
}
else
logger->log("Effects are now loading");
for_each_xml_child_node(node, root)
{
if (xmlStrEqual(node->name, BAD_CAST "effect"))
{
EffectDescription ed;
ed.id = XML::getProperty(node, "id", -1);
ed.GFX = XML::getProperty(node, "particle", "");
ed.SFX = XML::getProperty(node, "audio", "");
ed.ambient.type = ""; // since we test this, ensure it's initialized
// with something
if (xmlStrEqual(node->name, BAD_CAST "ambient"))
{
ed.ambient.type = XML::getProperty(node, "type", "");
ed.ambient.x = XML::getProperty(node, "x", 0.0f);
ed.ambient.y = XML::getProperty(node, "y", 0.0f);
ed.ambient.speedX = XML::getProperty(node, "speedx", 0.95f);
ed.ambient.speedY = XML::getProperty(node, "speedy", 0.95f);
ed.ambient.duration = XML::getProperty(node, "duration", 100);
}
mEffects.push_back(ed);
}
}
mLoaded = true;
}
示例9: loadXmlFile
void TextDb::loadXmlFile(const std::string &fileName,
const SkipError skipError)
{
XML::Document *doc = new XML::Document(fileName,
UseVirtFs_true,
skipError);
XmlNodeConstPtrConst root = doc->rootNode();
if ((root == nullptr) || !xmlNameEqual(root, "texts"))
{
delete doc;
return;
}
for_each_xml_child_node(node, root)
{
if (xmlNameEqual(node, "include"))
{
const std::string name = XML::getProperty(node, "name", "");
if (!name.empty())
loadXmlFile(name, skipError);
continue;
}
else if (xmlNameEqual(node, "text"))
{
const bool show = XML::getBoolProperty(node, "show", false);
if (show == true)
{
if (!XmlHaveChildContent(node))
continue;
std::string text = XmlChildContent(node);
mTexts.push_back(text);
}
}
}
delete doc;
}
示例10: load
void MonsterDB::load()
{
if (mLoaded)
return;
mUnknown.addSprite("error.xml");
mUnknown.setName(_("unnamed"));
logger->log("Initializing monster database...");
const XML::Document doc("monsters.xml");
const xmlNodePtr rootNode = doc.rootNode();
if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "monsters"))
logger->error("Monster Database: Error while loading monster.xml!");
//iterate <monster>s
for_each_xml_child_node(monsterNode, rootNode)
{
if (!xmlStrEqual(monsterNode->name, BAD_CAST "monster"))
continue;
MonsterInfo *currentInfo = new MonsterInfo();
currentInfo->setName(XML::getProperty(monsterNode, "name", _("unnamed")));
std::string targetCursor;
targetCursor = XML::getProperty(monsterNode, "targetCursor", "medium");
if (targetCursor == "small")
currentInfo->setTargetCursorSize(Being::TC_SMALL);
else if (targetCursor == "medium")
currentInfo->setTargetCursorSize(Being::TC_MEDIUM);
else if (targetCursor == "large")
currentInfo->setTargetCursorSize(Being::TC_LARGE);
else
{
logger->log("MonsterDB: Unknown target cursor type \"%s\" for %s -"
"using medium sized one",
targetCursor.c_str(), currentInfo->getName().c_str());
currentInfo->setTargetCursorSize(Being::TC_MEDIUM);
}
//iterate <sprite>s and <sound>s
for_each_xml_child_node(spriteNode, monsterNode)
{
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
currentInfo->addSprite(
(const char*) spriteNode->xmlChildrenNode->content);
if (xmlStrEqual(spriteNode->name, BAD_CAST "sound"))
{
std::string event = XML::getProperty(spriteNode, "event", "");
const char *filename;
filename = (const char*) spriteNode->xmlChildrenNode->content;
if (event == "hit")
currentInfo->addSound(MONSTER_EVENT_HIT, filename);
else if (event == "miss")
currentInfo->addSound(MONSTER_EVENT_MISS, filename);
else if (event == "hurt")
currentInfo->addSound(MONSTER_EVENT_HURT, filename);
else if (event == "die")
currentInfo->addSound(MONSTER_EVENT_DIE, filename);
else
{
logger->log("MonsterDB: Warning, sound effect %s for "
"unknown event %s of monster %s",
filename, event.c_str(),
currentInfo->getName().c_str());
}
}
if (xmlStrEqual(spriteNode->name, BAD_CAST "attack"))
{
std::string event = XML::getProperty(
spriteNode, "particle-effect", "");
currentInfo->addAttackParticleEffect(event);
}
if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
currentInfo->addParticleEffect(
(const char*) spriteNode->xmlChildrenNode->content);
}
mMonsterInfos[XML::getProperty(monsterNode, "id", 0)] = currentInfo;
}
mLoaded = true;
}
示例11: load
void CharDB::load()
{
if (mLoaded)
unload();
XML::Document *doc = new XML::Document(
paths.getStringValue("charCreationFile"),
UseResman_true,
SkipError_false);
const XmlNodePtrConst root = doc->rootNode();
if (!root || !xmlNameEqual(root, "chars"))
{
logger->log("CharDB: Failed to parse %s.",
paths.getStringValue("charCreationFile").c_str());
delete doc;
return;
}
for_each_xml_child_node(node, root)
{
if (xmlNameEqual(node, "haircolor"))
{
loadMinMax(node, &mMinHairColor, &mMaxHairColor);
}
else if (xmlNameEqual(node, "hairstyle"))
{
loadMinMax(node, &mMinHairStyle, &mMaxHairStyle);
}
else if (xmlNameEqual(node, "look"))
{
loadMinMax(node, &mMinLook, &mMaxLook);
}
else if (xmlNameEqual(node, "stat"))
{
loadMinMax(node, &mMinStat, &mMaxStat);
mSumStat = XML::getProperty(node, "sum", 0);
}
else if (xmlNameEqual(node, "item"))
{
const int id = XML::getProperty(node, "id", 0);
if (id > 0)
{
BeingSlot slot;
slot.spriteId = id;
for (int f = 0; f < maxCards; f ++)
{
const std::string cardName = strprintf("card%d", f + 1);
slot.cardsId.cards[f] = XML::getProperty(node,
cardName.c_str(),
0);
}
mDefaultItems.push_back(slot);
}
}
else if (xmlNameEqual(node, "race"))
{
loadMinMax(node, &mMinRace, &mMaxRace);
}
}
delete doc;
mLoaded = true;
}