19 #define LIBSMBIOS_SOURCE
24 #if defined(DEBUG_XMLUTILS)
26 # define DCOUT(line) do { cout << line; } while(0)
27 # define DCERR(line) do { cerr << line; } while(0)
29 # define DCOUT(line) do {} while(0)
30 # define DCERR(line) do {} while(0)
51 xmlChar *text = xmlGetProp(const_cast<xmlNode *>(node), reinterpret_cast<const xmlChar *>(attr.c_str()));
53 retval =
reinterpret_cast<const char *
>(text);
62 xmlNodePtr
findElement( xmlNodePtr root,
const string elementName,
const string &attribute,
const string &value )
65 DCERR(
"findElement( root, " <<
"\"" << elementName <<
"\", \"" << attribute <<
"\", \"" << value <<
"\");" << endl);
69 throw NotFoundImpl(
"no root element ref to xml file, cannot findElement");
71 xmlNodePtr cur_node = NULL;
72 for (cur_node = root; cur_node; cur_node = cur_node->next) {
73 DCERR(
"\tnode type: Element, name: " << cur_node->name << endl);
74 if (cur_node->type == XML_ELEMENT_NODE) {
75 if (!xmlStrcmp(cur_node->name, reinterpret_cast<const xmlChar *>(elementName.c_str())))
78 DCERR(
"\tELEMENT attribute ("<< attribute <<
") value: " <<
"\"" << strAttrValue <<
"\"" << endl);
79 if( (strAttrValue == value) || (attribute ==
"") )
81 DCERR(
"MATCH!" << endl);
89 DCERR(
"\tsearching child: " << cur_node->name << endl);
90 elem =
findElement(cur_node->children, elementName, attribute, value);
96 DCERR(
"\tDid not find match in child: " << cur_node->name << endl);
103 DCERR(
"Throwing not found error!"<< endl);
104 throw NotFoundImpl(
"could not find element.");
115 xmlNodePtr
findElement( xmlNodePtr root,
const string elementName,
const string &attribute,
long value)
119 DCERR(
"findElement( root, " <<
"\"" << elementName <<
"\", \"" << attribute <<
"\", \"" << value <<
"\");" << endl);
123 throw NotFoundImpl(
"no root element ref to xml file, cannot findElement");
125 xmlNodePtr cur_node = NULL;
126 for (cur_node = root; cur_node; cur_node = cur_node->next) {
127 DCERR(
"\tnode type: Element, name: " << cur_node->name << endl);
128 if (cur_node->type == XML_ELEMENT_NODE) {
129 if (!xmlStrcmp(cur_node->name, reinterpret_cast<const xmlChar *>(elementName.c_str())))
134 long attrValue = strtol(strAttrValue.c_str(), &endptr, 0);
135 DCERR(
"\tELEMENT attribute ("<< attribute <<
") value: " <<
"\"" << strAttrValue <<
"\"" << endl);
136 if(endptr != strAttrValue.c_str())
137 if( (attrValue == value) || (attribute ==
"") )
139 DCERR(
"MATCH!" << endl);
147 DCERR(
"\tsearching child: " << cur_node->name << endl);
148 elem =
findElement(cur_node->children, elementName, attribute, value);
157 DCERR(
"Throwing not found error!"<< endl);
158 throw NotFoundImpl(
"could not find element.");
166 return findElement(root, elementName, attribute, value);
173 text = xmlNodeGetContent(elem);
174 retval =
reinterpret_cast<const char *
>(text);
184 if(tempStr.length() != 0)
185 tempNum = strtol( tempStr.c_str(), 0, base);