25 NodeParser::NodeParser(
const xmlpp::Node::NodeList& list): xmlpp::Node::NodeList(list)
29 NodeParser::NodeParser(
const xmlpp::Node* node)
31 push_back(const_cast<xmlpp::Node*>(node));
34 NodeParser::NodeParser(
const xmlpp::DomParser& parser)
36 xmlpp::Node* node = parser.get_document()->get_root_node();
37 push_back(const_cast<xmlpp::Node*>(node));
40 NodeParser NodeParser::Path(
const xmlpp::Node* node,
const std::string& path)
47 std::string key = path;
48 std::string remainder;
49 std::string::size_type token_pos = path.find(
'/');
50 if ( token_pos != std::string::npos )
52 key = path.substr(0, token_pos );
53 remainder = path.substr( token_pos + 1 );
57 xmlpp::Node::NodeList list = node->get_children();
58 for (xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
60 if ( (*iter)->get_name() == key )
63 if ( remainder.length() )
66 result.splice(result.end(), remain_list);
71 result.push_back(*iter);
78 NodeParser NodeParser::Path(
const std::string& path)
const 83 for (const_iterator iter = begin(); iter != end(); ++iter)
86 result.splice(result.end(), iter_list);
92 NodeParser NodeParser::Select(
const std::string& key,
const std::string& value)
const 96 for (const_iterator iter = begin(); iter != end(); ++iter)
98 xmlpp::Node::NodeList list = (*iter)->get_children();
99 for (xmlpp::Node::NodeList::const_iterator iter3 = list.begin(); iter3 != list.end(); ++iter3)
101 if ( (*iter3)->get_name() == key )
103 xmlpp::Node::NodeList list = (*iter3)->get_children();
104 for (xmlpp::Node::NodeList::const_iterator iter4 = list.begin(); iter4 != list.end(); ++iter4)
106 const xmlpp::TextNode* nodeText =
dynamic_cast<const xmlpp::TextNode*
>(*iter4);
107 if ( nodeText && nodeText->get_content() == value )
108 result.push_back(*iter);
117 vector<string> NodeParser::Text(
void)
const 119 vector<string> result;
122 for (xmlpp::Node::NodeList::const_iterator iter = begin(); iter != end(); ++iter)
125 xmlpp::Node::NodeList list = (*iter)->get_children();
126 for (xmlpp::Node::NodeList::const_iterator iter2 = list.begin(); iter2 != list.end(); ++iter2)
128 const xmlpp::TextNode* nodeText =
dynamic_cast<const xmlpp::TextNode*
>(*iter2);
131 result.push_back(nodeText->get_content());
135 if ( result.empty() )
136 result.push_back(
string());
Declaration of nodeparser object, which facilitiates searching for nodes in an XML file using a notat...