27 #ifndef _RL_XML_NODE_H_
28 #define _RL_XML_NODE_H_
32 #include <boost/shared_array.hpp>
33 #include <libxml/parser.h>
34 #include <libxml/uri.h>
35 #include <libxml/xinclude.h>
52 Node(const ::std::string& name) :
56 reinterpret_cast< const xmlChar* >(name.c_str())
64 if (NULL == this->
node->doc)
73 reinterpret_cast< const xmlChar*
>(content.c_str())
79 return xmlAddChild(this->node,
node());
84 return xmlAddNextSibling(this->node,
node());
89 return xmlAddPrevSibling(this->node,
node());
94 return xmlAddSibling(this->node,
node());
102 reinterpret_cast< const xmlChar*
>(name.c_str())
109 return xmlChildElementCount(this->
node);
114 ::boost::shared_array< xmlChar > content(
115 xmlNodeGetContent(this->
node),
119 return reinterpret_cast< char*
>(content.get());
124 ::boost::shared_array< xmlChar > absolute(
126 reinterpret_cast< const xmlChar*
>(uri.c_str()),
127 xmlNodeGetBase(this->
node->doc, this->node)
132 ::boost::shared_array< char > unescaped(
133 xmlURIUnescapeString(
134 reinterpret_cast< char*
>(absolute.get()),
143 if (0 == strncmp(unescaped.get(),
"file://localhost/", 17))
146 path = &unescaped.get()[17];
148 path = &unescaped.get()[16];
151 else if (0 == strncmp(unescaped.get(),
"file:///", 8))
154 path = &unescaped.get()[8];
156 path = &unescaped.get()[7];
161 path = unescaped.get();
169 return reinterpret_cast< const char*
>(this->
node->name);
174 ::boost::shared_array<xmlChar> relative(
176 reinterpret_cast< const xmlChar*
>(uri.c_str()),
177 xmlNodeGetBase(this->
node->doc, this->node)
182 return reinterpret_cast< char*
>(relative.get());
185 ::std::string
getUri(const ::std::string& uri)
const
187 ::boost::shared_array< xmlChar > absolute(
189 reinterpret_cast< const xmlChar*
>(uri.c_str()),
190 xmlNodeGetBase(this->
node->doc, this->node)
195 return reinterpret_cast< char*
>(absolute.get());
200 return NULL != xmlHasProp(
202 reinterpret_cast< const xmlChar*
>(name.c_str())
208 return 1 == xmlNodeIsText(this->
node) ? true :
false;
218 return xmlReplaceNode(this->node,
node());
225 reinterpret_cast< const xmlChar*
>(content.c_str())
231 xmlNodeSetName(this->
node,
reinterpret_cast< const xmlChar*
>(name.c_str()));
236 int substitutions = xmlXIncludeProcessTreeFlags(this->
node, flags);
238 if (-1 == substitutions)
240 throw Exception(xmlGetLastError()->message);
243 return substitutions;
248 xmlUnlinkNode(this->
node);
259 #endif // _RL_XML_NODE_H_