XMLElement XMLTree::getRootElement() const { #ifdef PUGIXML return XMLElement(docPtr.first_child()); #else return XMLElement(xmlDocGetRootElement(docPtr)); #endif }
void XMLNodeList::setElementAtPosition(double index, const XMLNodeList & list) { if (list.getSize() && list.getRealNode() != parent) { int pos = (int)index; if (index < 1) { pos = 1; } else if (index > size) { pos = size++; } else if ((int)index != index) { pos++; } setElementAtPosition(index, XMLElement(doc, list.getRealNode())); for (xmlNode * cur = list.getRealNode()->next; cur; cur = cur->next) { setElementAtPosition((double)(pos++) + 0.5, XMLElement(doc, cur)); } } }
XMLElement XMLElement::GetParent() const { if (!file_ || (!node_ && !xpathNode_)) return XMLElement(); const pugi::xml_node& node = xpathNode_ ? xpathNode_->node() : pugi::xml_node(node_); return XMLElement(file_, node.parent().internal_object()); }
XMLElement XMLElement::SelectSingle(const ea::string& query, pugi::xpath_variable_set* variables) const { if (!file_ || (!node_ && !xpathNode_)) return XMLElement(); const pugi::xml_node& node = xpathNode_ ? xpathNode_->node() : pugi::xml_node(node_); pugi::xpath_node result = node.select_single_node(query.c_str(), variables); return XMLElement(file_, nullptr, &result, 0); }
XMLElement XMLElement::SelectSinglePrepared(const XPathQuery& query) const { if (!file_ || (!node_ && !xpathNode_ && !query.GetXPathQuery())) return XMLElement(); const pugi::xml_node& node = xpathNode_ ? xpathNode_->node() : pugi::xml_node(node_); pugi::xpath_node result = node.select_single_node(*query.GetXPathQuery()); return XMLElement(file_, nullptr, &result, 0); }
XMLElement XMLElement::CreateChild(const char* name) { if (!file_ || (!node_ && !xpathNode_)) return XMLElement(); const pugi::xml_node& node = xpathNode_ ? xpathNode_->node() : pugi::xml_node(node_); pugi::xml_node child = const_cast<pugi::xml_node&>(node).append_child(name); return XMLElement(file_, child.internal_object()); }
XMLElement XMLElement::GetChild(const char* name) const { if (!file_ || (!node_ && !xpathNode_)) return XMLElement(); const pugi::xml_node& node = xpathNode_ ? xpathNode_->node() : pugi::xml_node(node_); if (!String::CStringLength(name)) return XMLElement(file_, node.first_child().internal_object()); else return XMLElement(file_, node.child(name).internal_object()); }
XMLElement XMLElement::GetNext(const char* name) const { if (!file_ || (!node_ && !xpathNode_)) return XMLElement(); const pugi::xml_node& node = xpathNode_ ? xpathNode_->node() : pugi::xml_node(node_); if (!CStringLength(name)) return XMLElement(file_, node.next_sibling().internal_object()); else return XMLElement(file_, node.next_sibling(name).internal_object()); }
XMLElement XMLFile::GetRoot(const String& name) { pugi::xml_node root = document_->first_child(); if (root.empty()) return XMLElement(); if (!name.Empty() && name != root.name()) return XMLElement(); else return XMLElement(this, root.internal_object()); }
XMLElement XMLElement::NextResult() const { if (!xpathResultSet_ || !xpathNode_) return XMLElement(); return xpathResultSet_->operator [](++xpathResultIndex_); }
XMLElement XPathResultSet::operator[](unsigned index) const { if (!resultSet_) LOGERRORF("Could not return result at index: %u. Most probably this is caused by the XPathResultSet not being stored in a lhs variable.", index); return resultSet_ && index < Size() ? XMLElement(file_, this, &resultSet_->operator [](index), index) : XMLElement(); }
std::istream& XMLDoc::ReadDoc(std::istream& is) { root_node = XMLElement(); // clear doc contents s_element_stack.clear(); // clear this to start a fresh read s_curr_parsing_doc = this; // indicate where to add elements std::string parse_str; std::string temp_str; while (is) { getline(is, temp_str); parse_str += temp_str + '\n'; } parse(parse_str.c_str(), document); s_curr_parsing_doc = 0; return is; }
void XMLNodeList::setElementAtPosition(double index, const std::string & xmlCode) { std::string error; XMLDocument document = XMLDocument(xmlCode, false, &error); if (error.empty()) { setElementAtPosition(index, document); } else { xmlNode *n = xmlNewText((xmlChar *) xmlCode.c_str()); setElementAtPosition(index, XMLElement(doc, n)); } }
void XMLElement::setChildren(const std::string & xmlCode) const { std::string error; XMLDocument document = XMLDocument(xmlCode, false, &error); if (error.empty()) { setChildren(*document.getRoot()); } else { xmlNode *n = xmlNewText((xmlChar *) xmlCode.c_str()); setChildren(XMLElement(doc, n)); } }
XMLElement XMLElement::fromQString(const QString &str) { QStringList sections = str.split( ' '); QString tagname = sections[0]; XMLElement e(tagname.latin1()); sections.pop_front(); // Loop over the remaining strings which are attributes="values" if(sections.count()) { const int sectionsCount = sections.count(); for(int i = 0; i < sectionsCount; ++i) { QStringList list = sections[i].split( '='); if(list.count() != 2) { std::cerr << "XMLElement::fromQString: Cannot convert list: " << list.join("|") << ". `" << str << "' is not in valid format.\n"; return XMLElement(" "); } e.setAttribute(list[0], list[1].left(list[1].length() - 1).right(list[1].length() -2)); } } return e; }
XMLElement XMLNode::toElement() const { return XMLElement(*this); }
XMLElement XMLFile::CreateRoot(const String& name) { document_->reset(); pugi::xml_node root = document_->append_child(name.CString()); return XMLElement(this, root.internal_object()); }
XMLDoc::XMLDoc(const std::string& root_tag/*= "XMLDoc"*/) : root_node(XMLElement(root_tag, true)) {}
XMLDoc::XMLDoc(const std::istream& is) : root_node(XMLElement()) {}
void XMLDoc::SetElemName(const char* first, const char* last) { s_temp_elem = XMLElement(std::string(first, last)); }
XMLElement findElementById(svg_string_t const & id) { std::pair<element_by_id_t::iterator, bool> ins = element_by_id_.insert(element_by_id_t::value_type(id, XMLElement())); if (ins.second) ins.first->second = FindChildElementById(getRoot(), id); return ins.first->second; }
void XMLElement::AppendChild(const std::string& tag) { m_children.push_back(XMLElement(tag)); }