本文整理汇总了C++中node::NodeList::front方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeList::front方法的具体用法?C++ NodeList::front怎么用?C++ NodeList::front使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类node::NodeList
的用法示例。
在下文中一共展示了NodeList::front方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fromXML
void FileItem::fromXML(const xmlpp::Element &root) throw(xmlpp::exception, invalid_argument, overflow_error)
{
using namespace xmlpp;
Node::NodeList list = root.get_children("file");
string name = "";
if (list.size()==0)
{
throw xmlpp::exception("Missing file name");
}
else
{
Element *tmp = dynamic_cast<Element*>(list.front());
Attribute *attr = tmp->get_attribute("name");
if (attr!=NULL)
{
name = attr->get_value();
}
}
setFileName(name);
}
示例2: getTextFromElement
string XmlReader::getTextFromElement(const Element* elementNode, const string& childName, bool required) const {
string text;
const Node::NodeList children = elementNode->get_children(childName);
if (children.size() == 1) {
const Element *elementChild = castToElement(children.front());
for (const Node *child : elementChild->get_children()) {
const TextNode* textNode = dynamic_cast<const TextNode*>(child);
if (textNode != nullptr) {
if (!textNode->is_white_space())
text += textNode->get_content();
} else {
throw InvalidDatasetFile(caller(), "Invalid cast to 'TextNode*' type!", (child != nullptr ? child->get_line() : -1));
}
}
} else if (children.size() > 1) {
throw InvalidDatasetFile(caller(), "Only from one child the text can be retrieved!", elementNode->get_line());
} else if (children.empty() && required) {
string msg = "Cannot find the '"+string(childName)+"' element!\n";
throw InvalidDatasetFile(caller(), msg+"Invalid input xml file!", elementNode->get_line());
}
return text;
}
示例3: fromFile
void Scenario::fromFile(const std::string &fileName, bool checkFiles) throw(xmlpp::exception, invalid_argument)
{
using namespace xmlpp;
using namespace Poco;
string xmlFile, fileType;
bool isArchive = false;
clear();
if (pDetector)
{
fileType = pDetector->typeOfFile(fileName);
}
if (fileType == "text/xml" || fileType == "application/xml")
{
xmlFile = fileName;
}
else if (!pDetector || fileType == "application/zip")
{
// attempt to unzip
FileInputStream input(fileName.c_str());
if (input.good())
{
// creating new temporary directory and extracting into it
sTempDir = TemporaryFile::tempName();
Zip::Decompress dec(input, sTempDir);
TemporaryFile::registerForDeletion(sTempDir);
// valid extraction
isArchive = false;
try
{
dec.decompressAllFiles();
isArchive = true;
}
catch (Poco::Exception)
{
if (!pDetector)
{
xmlFile = fileName;
}
else
{
throw xmlpp::exception("Bad file format");
}
}
if (isArchive)
{
Zip::Decompress::ZipMapping mapping = dec.mapping();
try
{
xmlFile = mapping.at("scenario.xml").makeAbsolute(sTempDir).toString();
}
catch(out_of_range &e)
{
throw xmlpp::exception("No scenario in file " + fileName);
}
}
}
else
{
throw xmlpp::exception("Unable to open the file " + fileName);
}
}
else
{
throw xmlpp::exception("Unrecognized file format");
}
ioConfig = IOConfig::detect(xmlFile, isArchive);
DomParser parser(xmlFile);
Document *document = parser.get_document();
Element *root = document->get_root_node();
if (root->get_name() != ioConfig.rootName())
{
throw xmlpp::exception("Bad document content type: " + ioConfig.rootName() + " expected");
}
// getting the user interface
try
{
Attribute *attr = root->get_attribute("interface");
if (attr)
{
uiInterface = stringToInterface(attr->get_value());
}
else
{
uiInterface = uiFull;
}
}
catch (invalid_argument)
{
throw xmlpp::exception("Bad user interface");
}
// now loading the different parts of the game
Node::NodeList node;
if (ioConfig.hasMetadata())
{
node = root->get_children("metadata");
if (!node.empty())
{
mMetadata.fromXML(*dynamic_cast<Element*>(node.front()));
}
//.........这里部分代码省略.........
示例4: fromFile
void Scenario::fromFile(const std::string &fileName) throw(xmlpp::exception, invalid_argument, overflow_error)
{
using namespace xmlpp;
clear();
DomParser parser(fileName);
Document *document = parser.get_document();
Element *root = document->get_root_node();
if (root->get_name()!="game")
{
throw xmlpp::exception("Bad document content type: game expected");
}
// getting the user interface
try
{
Attribute *attr = root->get_attribute("interface");
if (attr != NULL)
{
uiInterface = stringToInterface(attr->get_value());
}
else
{
uiInterface = uiFull;
}
}
catch (invalid_argument)
{
throw xmlpp::exception("Bad user interface");
}
// now loading the different parts of the game
Node::NodeList node = root->get_children("scenario");
if (!node.empty())
{
tScenario.fromXML(*dynamic_cast<Element*>(node.front()));
}
node = root->get_children("notes");
if (!node.empty())
{
Element *elem = dynamic_cast<Element*>(node.front());
if (elem->has_child_text())
{
sNotes = elem->get_child_text()->get_content();
}
else
{
sNotes = "";
}
}
node = root->get_children("skills");
if (!node.empty())
{
lSkills.fromXML(*dynamic_cast<Element*>(node.front()));
}
node = root->get_children("characters");
if (!node.empty())
{
lCharacters.fromXML(*dynamic_cast<Element*>(node.front()));
}
node = root->get_children("history");
if (!node.empty())
{
tHistory.fromXML(*dynamic_cast<Element*>(node.front()));
}
node = root->get_children("music");
if (!node.empty())
{
tMusic.fromXML(*dynamic_cast<Element*>(node.front()));
}
node = root->get_children("effects");
if (!node.empty())
{
tEffects.fromXML(*dynamic_cast<Element*>(node.front()),true);
}
}