00001
00024 #include "xmlutils.h"
00025 #include <cassert>
00026
00027 using namespace std;
00028 using namespace xmlpp;
00029
00034 string getChildContent(xmlpp::Node* node)
00035 {
00036
00037 Element* enode = dynamic_cast<Element*>(node);
00038 TextNode* tnode = enode ? enode->get_child_content() : dynamic_cast<TextNode*>(node);
00039
00040 return tnode ? tnode->get_content() : "";
00041 }
00042
00049 xmlpp::Node* getFirstChild(xmlpp::Node* node, const std::string& name)
00050 {
00051 Node::NodeList children = node->get_children(name);
00052 if (children.empty()) {
00053 return NULL;
00054 } else {
00055 return *children.begin();
00056 }
00057 }
00058
00060
00067 bool getChildContent(xmlpp::Node* node, const std::string& name, std::string& val)
00068 {
00069 bool success;
00070
00071 xmlpp::Node* child = getFirstChild(node, name);
00072
00073 if (child != NULL) {
00074 val = getChildContent(child);
00075 success = true;
00076 } else {
00077 success = false;
00078 }
00079
00080 return success;
00081 }
00082
00088 std::string getPropValue(xmlpp::Node* node, const std::string& name)
00089 {
00090 string prop_value;
00091
00092 Element* elem = dynamic_cast<Element*>(node);
00093
00094 if (elem) {
00095 Attribute *dirprop = elem->get_attribute(name.c_str());
00096 if (dirprop != NULL) {
00097 prop_value = dirprop->get_value();
00098 }
00099 }
00100
00101 return prop_value;
00102
00103 }
00104
00105
00112 xmlpp::Node* addChild(xmlpp::Node* parent, xmlpp::Node* child)
00113 {
00114 assert(parent && child);
00115
00116
00117 xmlNode* c_parent = parent->cobj();
00118 xmlNode* c_child = child->cobj();
00119
00120 return xmlAddChild(c_parent, c_child) ? child : NULL;
00121
00122 }
00123
00124