namespace xml {
-Document::Document(const std::string& version) :
- rootNode(nullptr),
+Document::Document(const std::string& root, const std::string& version) :
implementation(xmlNewDoc((const xmlChar*)version.c_str()))
{
if (implementation == nullptr) {
}
implementation->_private = this;
+
+ xmlNode* rootPtr = xmlNewNode(NULL, xmlStrdup((const xmlChar*)root.c_str()));
+ xmlDocSetRootElement(implementation, rootPtr);
+
+ rootNode = new Node(rootPtr);
}
Document::Document(xmlDoc* doc)
return nodeList;
}
+Node Node::addNewChild(const std::string& name)
+{
+ xmlNode* nodePtr = xmlNewNode(NULL, xmlStrdup((const xmlChar*)name.c_str()));
+ xmlAddChild(implementation, nodePtr);
+
+ return Node(nodePtr);
+}
+
std::string Node::getName() const
{
return implementation->name ? (const char*)implementation->name : "";
xmlNodeSetName(implementation, (const xmlChar*)name.c_str());
}
-void Node::setContent(const std::string& content)
-{
- if (implementation->type != XML_ELEMENT_NODE) {
- throw runtime::Exception("Can not set content for this node type");
- }
-
- auto child = implementation->xmlChildrenNode;
- xmlNodeSetContent(child, (xmlChar*)content.c_str());
-}
-
std::string Node::getContent() const
{
if (implementation->type != XML_ELEMENT_NODE) {
return child->content ? (char*)child->content : "";
}
-void Node::setProp(const std::string& name, const std::string& val)
+void Node::setContent(const std::string& content)
{
if (implementation->type != XML_ELEMENT_NODE) {
- throw runtime::Exception("Can not set properties for this node type");
+ throw runtime::Exception("Can not set content for this node type");
}
- xmlSetProp(implementation, (xmlChar*)name.c_str(), (xmlChar*)val.c_str());
+ auto child = implementation->xmlChildrenNode;
+ xmlNodeSetContent(child, (xmlChar*)content.c_str());
}
std::string Node::getProp(const std::string& name) const
return result ? (char*)result : "";
}
+void Node::setProp(const std::string& name, const std::string& val)
+{
+ if (implementation->type != XML_ELEMENT_NODE) {
+ throw runtime::Exception("Can not set properties for this node type");
+ }
+
+ xmlSetProp(implementation, (xmlChar*)name.c_str(), (xmlChar*)val.c_str());
+}
+
bool Node::isBlank() const
{
return xmlIsBlankNode(const_cast<xmlNode*>(implementation));