5#include <libxml++/libxml++.h>
6#include <boost/lexical_cast.hpp>
13#if LIBXMLXX_MAJOR_VERSION == 2
23 current_node_ = parser.
Document()->get_root_node();
32 while (!spawned_children_.empty()) {
33 InfileTree* qe_child = *spawned_children_.begin();
34 spawned_children_.erase(spawned_children_.begin());
45 const xmlpp::Node::NodeList nodelist = current_node_->get_children();
46 xmlpp::Node::NodeList::const_iterator it;
47 for (it = nodelist.begin(); it != nodelist.end(); it++) {
48 const Element* element =
dynamic_cast<const Element*
>(*it);
58 return current_node_->find(query).size();
64 using xmlpp::TextNode;
66 const NodeSet nodeset = current_node_->find(query);
67 if (nodeset.empty()) {
68 throw KeyError(
"Could not find a node by the name: " + query);
71 if (nodeset.size() < index + 1) {
72 throw ValueError(
"Index exceeds number of nodes in query: " + query);
75 const Element* element =
76 dynamic_cast<const Element*
>(nodeset.at(index));
79 throw CastError(
"Node: " + nodeset.at(index)->get_name() +
80 " is not an Element node.");
84 if (nodelist.size() != 1) {
85 throw ValueError(
"Element node " + element->get_name() +
86 " has more content than expected.");
89 const TextNode* text =
90 dynamic_cast<const xmlpp::TextNode*
>(element->get_children().front());
93 throw CastError(
"Node: " + element->get_name() +
" is not a Text node.");
96 return text->get_content();
103 std::vector<xmlpp::Element*> elements;
104 const Node::NodeList nodelist = current_node_->get_children();
105 Node::NodeList::const_iterator it;
106 for (it = nodelist.begin(); it != nodelist.end(); it++) {
107 xmlpp::Element* element =
dynamic_cast<xmlpp::Element*
>(*it);
109 elements.push_back(element);
112 if (elements.size() < index + 1) {
113 throw ValueError(
"Index exceeds number of elements in node: "
114 + current_node_->get_name());
116 return elements.at(index)->get_name();
123 const NodeSet nodeset = current_node_->find(query);
125 if (nodeset.size() < index + 1) {
126 throw ValueError(
"Index exceeds number of nodes in query: " + query);
129 xmlpp::Element* element =
dynamic_cast<xmlpp::Element*
>(nodeset.at(index));
132 throw CastError(
"Node: " + nodeset.at(index)->get_name() +
133 " is not an Element node.");
142 spawned_children_.insert(qe_child);
For failed casts that shouldn't.
A class for extracting information from a given XML parser.
virtual InfileTree * GetEngineFromQuery(std::string query, int index)
every derived infile must return a new instance initialized by a query.
InfileTree(XMLParser &parser)
constructor given a parser
virtual int NMatches(std::string query)
investigates the current status and returns the number of elements matching a query
virtual std::string GetElementName(int index=0)
investigates the current status and returns a string representing the name of a given index
InfileTree * SubTree(std::string query, int index=0)
populates a child infile based on a query and index
virtual std::string GetString(std::string query, int index=0)
investigates the current status and returns a string representing the content of a query at a given i...
For failed retrieval/insertion of key-based data into/from data structures.
For values that are too big, too small, etc.
A helper class to hold xml file data and provide automatic validation.
xmlpp::Document * Document()
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
xmlpp::Node::NodeSet NodeSet
xmlpp::Node::const_NodeList const_NodeList