AlexSm 6d3e410c45 Remove CMakeLists from main (#2032) 7 months ago
..
ut bf0f13dd39 add ymake export to ydb 1 year ago
README.md b56bb904dc intermediate changes 2 years ago
libxml-guards.h 47a7e7b296 Restoring authorship annotation for <kerzum@yandex-team.ru>. Commit 2 of 2. 2 years ago
node-attr.h 7bf72dabd2 Restoring authorship annotation for <fippo@yandex-team.ru>. Commit 2 of 2. 2 years ago
xml-document-decl.h 096edeeaa3 Restoring authorship annotation for <rufrozen@yandex-team.ru>. Commit 2 of 2. 2 years ago
xml-document.cpp 9f9f5936c5 Restoring authorship annotation for <vegayours@yandex-team.ru>. Commit 2 of 2. 2 years ago
xml-document.h 2ab6bab688 Restoring authorship annotation for <finder@yandex-team.ru>. Commit 2 of 2. 2 years ago
xml-document_ut.cpp 7bf72dabd2 Restoring authorship annotation for <fippo@yandex-team.ru>. Commit 2 of 2. 2 years ago
xml-options.cpp 1136f2ce7c Restoring authorship annotation for Arslan Urtashev <urtashev@gmail.com>. Commit 2 of 2. 2 years ago
xml-options.h 1136f2ce7c Restoring authorship annotation for Arslan Urtashev <urtashev@gmail.com>. Commit 2 of 2. 2 years ago
xml-options_ut.cpp 1136f2ce7c Restoring authorship annotation for Arslan Urtashev <urtashev@gmail.com>. Commit 2 of 2. 2 years ago
xml-textreader.cpp 1136f2ce7c Restoring authorship annotation for Arslan Urtashev <urtashev@gmail.com>. Commit 2 of 2. 2 years ago
xml-textreader.h 1136f2ce7c Restoring authorship annotation for Arslan Urtashev <urtashev@gmail.com>. Commit 2 of 2. 2 years ago
xml-textreader_ut.cpp 0f4c5d1e8c Restoring authorship annotation for <a-romanov@yandex-team.ru>. Commit 2 of 2. 2 years ago
ya.make bf0f13dd39 add ymake export to ydb 1 year ago

README.md

A wrapper around the DOM interface of libxml2.

The standard way to use it is as follows:

#include <library/cpp/xml/document/xml-document.h>
...

// open a document
NXml::TDocument xml("filename.xml");

// get a nodeset from an XPath query
NXml::TConstNodes nodes = xml.Root().Nodes("xpath/expression/here");

// iterate over the nodeset
for (size_t i = 0; i < nodes.size(); ++i) {
    using namespace NXml;
    TConstNode& node = nodes[i];
    // query node
    TString name = node.Name();
    TString lang = node.Attr<TString>("lang");
    TString text = node.Value<TString>();
    TConstNode child = node.GetFirstChild("");
    // edit node
    TNode node = child.ConstCast();
    node.DelAttr("id");
    node.SetAttr("x", 2);
    node.SetValue(5);
    node.AddText(" apples");
}

// edit documents with copy-paste
NXml::TDocument xml2("<xpath><node/></xpath>", NXml::TDocument::String);
NXml::TNode place = xml2.Root().Node("xpath/node");
// copy node's subtree from one document to another
place.AddChild(xml.Root());
// save (render) single element
TString modifiedNode = place.ToString();
// save whole document with optional encoding
TString modifiedDoc  = xml2.ToString("ISO-8559-1");

See xml-document_ut.cpp for more examples.