diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/xml/document/README | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/xml/document/README')
-rw-r--r-- | library/cpp/xml/document/README | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/library/cpp/xml/document/README b/library/cpp/xml/document/README new file mode 100644 index 00000000000..b2649523d8f --- /dev/null +++ b/library/cpp/xml/document/README @@ -0,0 +1,42 @@ +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. |