diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-05-26 16:39:42 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-05-26 16:39:42 +0300 |
commit | b56bb904dc1c9b6911ae9d589e18ed348bc06510 (patch) | |
tree | 4ee1c952e6f67e45c218000ad9364fb4dccaa6ed /library/cpp/xml/document/README.md | |
parent | 79dae787b59bbf5e3c408af595165012389ffba9 (diff) | |
download | ydb-b56bb904dc1c9b6911ae9d589e18ed348bc06510.tar.gz |
intermediate changes
ref:053341dde4c25aa65918f21eb765fc97232e55cb
Diffstat (limited to 'library/cpp/xml/document/README.md')
-rw-r--r-- | library/cpp/xml/document/README.md | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/library/cpp/xml/document/README.md b/library/cpp/xml/document/README.md new file mode 100644 index 0000000000..b2649523d8 --- /dev/null +++ b/library/cpp/xml/document/README.md @@ -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. |