本文整理汇总了C++中node::NodeList::size方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeList::size方法的具体用法?C++ NodeList::size怎么用?C++ NodeList::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类node::NodeList
的用法示例。
在下文中一共展示了NodeList::size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: getNodeContent
static ustring getNodeContent(const Node *pNode)
{
if (pNode == NULL)
{
return "";
}
// Is it an element ?
const Element *pElem = dynamic_cast<const Element*>(pNode);
if (pElem != NULL)
{
#ifdef HAS_LIBXMLPP026
const TextNode *pText = pElem->get_child_content();
#else
const TextNode *pText = pElem->get_child_text();
#endif
if (pText == NULL)
{
// Maybe the text is given as CDATA
const Node::NodeList childNodes = pNode->get_children();
if (childNodes.size() == 1)
{
// Is it CDATA ?
const CdataNode *pContent = dynamic_cast<const CdataNode*>(*childNodes.begin());
if (pContent != NULL)
{
return pContent->get_content();
}
}
return "";
}
return pText->get_content();
}
return "";
}
示例4: iss
/** Process received string. */
void
Msl2010RefBoxProcessor::process_string(char *buf, size_t len)
{
__logger->log_info(__name, "Received\n *****\n %s \n *****", buf);
std::istringstream iss( std::string(buf), std::istringstream::in);
dom = new DomParser();
//dom->set_validate();
dom->set_substitute_entities();
dom->parse_stream(iss);
root = dom->get_document()->get_root_node();
//printf( " root node:\n%s\n", root->get_name().data() );
const Element * el = dynamic_cast<const Element *>(root);
if ( el ) {
/// valid element
//printf("Is valid Element\n");
__logger->log_info(__name, "root-element name is '%s'", el->get_name().data() );
const Node::NodeList nl = el->get_children();
if( nl.size() == 0 ) {
__logger->log_info(__name, "root has NO children!");
}
else {
//printf("root has %u children!\n", nl.size());
for (Node::NodeList::const_iterator it = nl.begin(); it != nl.end(); ++it) {
const Node* node = *it;
__logger->log_info(__name, "1st level child name is '%s'", node->get_name().data() );
//if( node->get_name().data() == REFBOX_GAMEINFO ) {
//
//}
//else if( node->get_name().data() == REFBOX_EVENT ) {
//
//}
//else {
// printf(" unhandled RefboxMessage-type '%s'!\n", node->get_name().data() );
//}
const Node::NodeList cnl = node->get_children();
if( cnl.size() == 0 ) {
__logger->log_info(__name, "child has NO children!");
}
else {
//printf("child has %u children!\n", nl.size());
for (Node::NodeList::const_iterator cit = cnl.begin(); cit != cnl.end(); ++cit) {
const Node* cnode = *cit;
const Element* cel = dynamic_cast<const Element *>(cnode);
std::string cnodename(cnode->get_name().data());
__logger->log_info(__name, "2nd level child name is '%s'", cnode->get_name().data() );
const Attribute* cattr;
std::string cteamcolor;
//std::string cgoalcolor;
//std::string ccardcolor;
std::string cstagetype;
if( cnodename == REFBOX_KICKOFF || cnodename == REFBOX_FREEKICK ||
cnodename == REFBOX_GOALKICK || cnodename == REFBOX_THROWIN ||
cnodename == REFBOX_CORNER || cnodename == REFBOX_PENALTY ||
cnodename == REFBOX_GOAL_AWARDED || cnodename == REFBOX_GOAL_REMOVED ||
cnodename == REFBOX_CARD_AWARDED || cnodename == REFBOX_CARD_REMOVED ||
cnodename == REFBOX_PLAYER_OUT || cnodename == REFBOX_PLAYER_IN ||
cnodename == REFBOX_SUBSTITUTION )
{
cattr = cel->get_attribute("team");
cteamcolor = std::string( cattr->get_value().data() );
}
if( cnodename == REFBOX_CANCEL ) {
// refbox canceled last command
__logger->log_info(__name, "RefBox cancelled last command");
}
else if( cnodename == REFBOX_GAMESTOP ) {
_rsh->set_gamestate(GS_FROZEN, TEAM_BOTH);
}
else if( cnodename == REFBOX_GAMESTART ) {
_rsh->set_gamestate(GS_PLAY, TEAM_BOTH);
}
else if( cnodename == REFBOX_DROPPEDBALL ) {
_rsh->set_gamestate(GS_DROP_BALL, TEAM_BOTH);
}
else if( cnodename == REFBOX_GOAL_AWARDED ) {
// increment according to color
if( cteamcolor == REFBOX_TEAMCOLOR_CYAN ) {
_rsh->set_score(++__score_cyan, __score_magenta);
}
else if ( cteamcolor == REFBOX_TEAMCOLOR_MAGENTA ) {
_rsh->set_score(__score_cyan, ++__score_magenta);
}
_rsh->set_gamestate(GS_FROZEN, TEAM_BOTH);
//.........这里部分代码省略.........
示例5: parse
iPackage* JispParser::parse(const FindFile::Found& defFile) {
using namespace xmlpp;
// parsujemy xmla z definicjami
DomParser parser;
parser.set_substitute_entities();
Node* rootNode;
Node* metaNode;
Node::NodeList icons;
Node::NodeList nodes;
Attribute* attrib;
eMSet result;
ifstream file(defFile.getFilePath().c_str());
try {
parser.parse_stream(file);
} catch (const xmlpp::exception& e) {
throw XMLParserException(e.what());
}
file.close();
rootNode = parser.get_document()->get_root_node();
if (rootNode->get_name() != "icondef") throw WrongFormat("Z³a nazwa korzenia dokumentu (z³y format ?)");
nodes = rootNode->get_children("meta");
if (nodes.size() != 1) throw WrongFormat("Nie ma dok³adnie jednego elementu 'meta'");
metaNode = *nodes.begin();
if (!metaNode) throw WrongFormat("Element 'meta' nie zawiera dzieci");
nodes = metaNode->get_children("name");
if (nodes.size() == 1 && dynamic_cast<Element*>(*nodes.begin())) {
result.setName(dynamic_cast<Element*>(*nodes.begin())->get_child_text()->get_content().c_str());
}
nodes = metaNode->get_children("version");
if (nodes.size() == 1 && dynamic_cast<Element*>(*nodes.begin())) {
result.setVersion(dynamic_cast<Element*>(*nodes.begin())->get_child_text()->get_content().c_str());
}
nodes = metaNode->get_children("description");
if (nodes.size() == 1 && dynamic_cast<Element*>(*nodes.begin())) {
result.setDescription(dynamic_cast<Element*>(*nodes.begin())->get_child_text()->get_content().c_str());
}
nodes = metaNode->get_children("author");
for (Node::NodeList::iterator it = nodes.begin(); it != nodes.end(); it++) {
if (dynamic_cast<Element*>(*it)) {
attrib = dynamic_cast<Element*>(*it)->get_attribute("jid");
result.addAuthor(eMAuthor(dynamic_cast<Element*>(*it)->get_child_text()->get_content().c_str(),
attrib ? attrib->get_value().c_str() : ""));
}
}
nodes = metaNode->get_children("creation");
if (nodes.size() == 1 && dynamic_cast<Element*>(*nodes.begin())) {
// result.setCTime(dynamic_cast<Element*>(*nodes.begin())->get_child_text()->get_content().c_str());
}
nodes = metaNode->get_children("home");
if (nodes.size() == 1 && dynamic_cast<Element*>(*nodes.begin())) {
result.setUrl(dynamic_cast<Element*>(*nodes.begin())->get_child_text()->get_content().c_str());
}
icons = rootNode->get_children("icon");
for (Node::NodeList::iterator it = icons.begin(); it != icons.end(); it++) {
eM emot(true, false);
string mime;
nodes = (*it)->get_children("object");
for (Node::NodeList::iterator it = nodes.begin(); it != nodes.end(); it++) {
if (dynamic_cast<Element*>(*it) && dynamic_cast<Element*>(*it)->get_attribute("mime")) {
mime = dynamic_cast<Element*>(*it)->get_attribute("mime")->get_value();
if (mime == "image/png" || mime == "image/gif" || mime == "image/jpeg") {
emot.setImgPath(defFile.getDirectory() + (string) dynamic_cast<Element*>(*it)->get_child_text()->get_content());
break;
}
mime.clear();
}
}
if (mime.empty()) continue;
nodes = (*it)->get_children("text");
if (nodes.empty()) throw WrongFormat("Brak tekstu do zamiany");
for (Node::NodeList::iterator it = nodes.begin(); it != nodes.end(); it++) {
if (dynamic_cast<Element*>(*it)) {
emot.setText(dynamic_cast<Element*>(*it)->get_child_text()->get_content().c_str());
attrib = dynamic_cast<Element*>(*it)->get_attribute("regexp");
if (attrib) {
emot.setPreg((bool) atoi(attrib->get_value().c_str()));
}
result.addEmot(emot);
}
}
}
return new eMSet(result);
}