本文整理汇总了C++中xml::Element::getChildren方法的典型用法代码示例。如果您正苦于以下问题:C++ Element::getChildren方法的具体用法?C++ Element::getChildren怎么用?C++ Element::getChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml::Element
的用法示例。
在下文中一共展示了Element::getChildren方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseXMLRoot
/***************************************************************
* Function: CodeParser::parseScript()
* Purpose : Parse the XML root element
* Initial : Maxime Chevalier-Boisvert on November 18, 2008
****************************************************************
Revisions and bug fixes:
*/
CompUnits CodeParser::parseXMLRoot(const XML::Element* pTreeRoot)
{
// Create a list to store parsed functions
CompUnits functionList;
// If the root tag is not the compilation units, throw an exception
if (pTreeRoot->getName() != "CompilationUnits")
{
// TODO: implement error list parsing
std::cout << "XML tree: " << pTreeRoot->toString(true, 0) << std::endl;
throw XML::ParseError("Expected compilation units: \"" + pTreeRoot->getName() + "\"", pTreeRoot->getTextPos());
}
// If the verbose output flag is set
if (ConfigManager::s_verboseVar.getBoolValue() == true)
{
// Log the number of compilation units
std::cout << "Number of compilation units: " << pTreeRoot->getNumChildren() << std::endl;
}
// For each compilation unit
for (size_t i = 0; i < pTreeRoot->getNumChildren(); ++i)
{
// Get a pointer to this element
XML::Element* pUnitElement = pTreeRoot->getChildElement(i);
// If this is a function list
if (pUnitElement->getName() == "FunctionList")
{
// Get the list of functions
const std::vector<XML::Node*>& functions = pUnitElement->getChildren();
// For each function
for (std::vector<XML::Node*>::const_iterator itr = functions.begin(); itr != functions.end(); ++itr)
{
// If this is not an XML element, throw an exception
if ((*itr)->getType() != XML::Node::ELEMENT)
throw XML::ParseError("Unexpected XML node type in function list");
// Get a pointer to this element
XML::Element* pFuncElement = (XML::Element*)*itr;
// If this ia a function declaration
if (pFuncElement->getName() == "Function")
{
// Parse the function
IIRNode* pNewNode = parseFunction(pFuncElement);
// Add the function to the list
functionList.push_back(pNewNode);
}
// If this is a symbol table
else if (pFuncElement->getName() == "Symboltable")
{
// Ignore for now
}
// Otherwise
else
{
// This is an invalid element, throw an exception
throw XML::ParseError("Invalid element in function list: \"" + pFuncElement->getName() + "\"", pFuncElement->getTextPos());
}
}
}
// If this is a script
else if (pUnitElement->getName() == "Script")
{
// Parse the script
IIRNode* pNewNode = parseScript(pUnitElement);
// Add the function to the list
functionList.push_back(pNewNode);
}
// Otherwise
else
{
// This is an invalid element, throw an exception
throw XML::ParseError("Invalid element in compilation unit list: \"" + pUnitElement->getName() + "\"", pUnitElement->getTextPos());
}
}
// If the verbose output flag is set
if (ConfigManager::s_verboseVar.getBoolValue() == true)
{
// Output parsed IIR
std::cout << std::endl;
std::cout << "Constructed IIR:" << std::endl;
for (CompUnits::iterator itr = functionList.begin(); itr != functionList.end(); ++itr)
//.........这里部分代码省略.........