32 #include <boost/shared_array.hpp>
33 #include <libxml/parser.h>
34 #include <libxml/uri.h>
35 #include <libxml/xinclude.h>
53 explicit Node(const ::std::string& name) :
57 reinterpret_cast<const ::xmlChar*>(name.c_str())
65 if (
nullptr != this->
node &&
nullptr == this->
node->doc)
67 ::xmlFree(this->
node);
73 return Node(::xmlNewText(
reinterpret_cast<const ::xmlChar*
>(content.c_str())));
78 return Node(::xmlAddChild(this->node,
node.get()));
83 return Node(::xmlAddNextSibling(this->node,
node.get()));
88 return Node(::xmlAddPrevSibling(this->node,
node.get()));
93 return Node(::xmlAddSibling(this->node,
node.get()));
96 ::xmlNodePtr
get()
const
103 return ::xmlChildElementCount(this->
node);
108 ::boost::shared_array< ::xmlChar> content(
109 ::xmlNodeGetContent(this->
node),
113 return nullptr != content.get() ?
reinterpret_cast<char*
>(content.get()) : ::std::string();
128 return this->
node->line;
133 ::boost::shared_array< ::xmlChar> absolute(
135 reinterpret_cast<const ::xmlChar*
>(uri.c_str()),
136 ::xmlNodeGetBase(this->
node->doc, this->node)
141 ::boost::shared_array<char> unescaped(
142 ::xmlURIUnescapeString(
143 reinterpret_cast<char*
>(absolute.get()),
152 if (0 == ::strncmp(unescaped.get(),
"file://localhost/", 17))
155 path = &unescaped.get()[17];
157 path = &unescaped.get()[16];
160 else if (0 == ::strncmp(unescaped.get(),
"file:///", 8))
163 path = &unescaped.get()[8];
165 path = &unescaped.get()[7];
168 else if (0 == ::strncmp(unescaped.get(),
"file:/", 6))
171 path = &unescaped.get()[6];
173 path = &unescaped.get()[5];
178 path = unescaped.get();
181 return nullptr != path ? path : ::std::string();
186 return nullptr != this->
node->name ?
reinterpret_cast<const char*
>(this->
node->name) : ::std::string();
211 ::boost::shared_array< ::xmlChar> prop(
214 reinterpret_cast<const ::xmlChar*
>(name.c_str())
219 return nullptr != prop.get() ?
reinterpret_cast<char*
>(prop.get()) : ::std::string();
222 ::std::string
getProperty(const ::std::string& name, const ::std::string& nameSpace)
const
224 ::boost::shared_array< ::xmlChar> prop(
227 reinterpret_cast<const ::xmlChar*
>(name.c_str()),
228 reinterpret_cast<const ::xmlChar*
>(nameSpace.c_str())
233 return nullptr != prop.get() ?
reinterpret_cast<char*
>(prop.get()) : ::std::string();
238 ::boost::shared_array< ::xmlChar> relative(
239 ::xmlBuildRelativeURI(
240 reinterpret_cast<const ::xmlChar*
>(uri.c_str()),
241 ::xmlNodeGetBase(this->
node->doc, this->node)
246 return nullptr != relative.get() ?
reinterpret_cast<char*
>(relative.get()) : ::std::string();
249 ::std::string
getUri(const ::std::string& uri)
const
251 ::boost::shared_array< ::xmlChar> absolute(
253 reinterpret_cast<const ::xmlChar*
>(uri.c_str()),
254 ::xmlNodeGetBase(this->
node->doc, this->node)
259 return nullptr != absolute.get() ?
reinterpret_cast<char*
>(absolute.get()) : ::std::string();
264 return nullptr != this->
node->children;
269 return nullptr != this->
node->ns;
274 return nullptr != this->
node->parent;
279 return nullptr != this->
node->properties;
287 reinterpret_cast<const ::xmlChar*
>(name.c_str())
297 reinterpret_cast<const ::xmlChar*
>(name.c_str()),
298 reinterpret_cast<const ::xmlChar*
>(nameSpace.c_str())
305 return 1 == ::xmlIsBlankNode(this->
node) ? true :
false;
310 return 1 == ::xmlNodeIsText(this->
node) ? true :
false;
320 return 0 == ::xmlRemoveProp(attribute.
get()) ? true :
false;
325 return Node(::xmlReplaceNode(this->node,
node.get()));
332 reinterpret_cast<const ::xmlChar*
>(content.c_str())
338 ::xmlNodeSetName(this->
node,
reinterpret_cast<const ::xmlChar*
>(name.c_str()));
346 reinterpret_cast<const ::xmlChar*
>(name.c_str()),
347 reinterpret_cast<const ::xmlChar*
>(value.c_str())
358 reinterpret_cast<const ::xmlChar*
>(name.c_str()),
359 reinterpret_cast<const ::xmlChar*
>(value.c_str())
366 int substitutions = ::xmlXIncludeProcessTreeFlags(this->
node, flags);
368 if (-1 == substitutions)
370 throw Exception(::xmlGetLastError()->message);
373 return substitutions;
378 ::xmlUnlinkNode(this->
node);
389 #endif // RL_XML_NODE_H