source: icGREP/icgrep-devel/icgrep/combine/pugixml/docs/quickstart.html @ 5516

Last change on this file since 5516 was 5516, checked in by faldebey, 2 years ago

added combinatorial testing tool

File size: 105.0 KB
Line 
1<!DOCTYPE html>
2<html lang="en">
3<head>
4<meta charset="UTF-8">
5<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
6<meta name="viewport" content="width=device-width, initial-scale=1.0">
7<meta name="generator" content="Asciidoctor 1.5.5">
8<meta name="author" content="website, repository">
9<title>pugixml 1.8 quick start guide</title>
10<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
11<style>
12/* Asciidoctor default stylesheet | MIT License | http://asciidoctor.org */
13/* Remove comment around @import statement below when using as a custom stylesheet */
14/*@import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700";*/
15article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}
16audio,canvas,video{display:inline-block}
17audio:not([controls]){display:none;height:0}
18[hidden],template{display:none}
19script{display:none!important}
20html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}
21a{background:transparent}
22a:focus{outline:thin dotted}
23a:active,a:hover{outline:0}
24h1{font-size:2em;margin:.67em 0}
25abbr[title]{border-bottom:1px dotted}
26b,strong{font-weight:bold}
27dfn{font-style:italic}
28hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}
29mark{background:#ff0;color:#000}
30code,kbd,pre,samp{font-family:monospace;font-size:1em}
31pre{white-space:pre-wrap}
32q{quotes:"\201C" "\201D" "\2018" "\2019"}
33small{font-size:80%}
34sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}
35sup{top:-.5em}
36sub{bottom:-.25em}
37img{border:0}
38svg:not(:root){overflow:hidden}
39figure{margin:0}
40fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}
41legend{border:0;padding:0}
42button,input,select,textarea{font-family:inherit;font-size:100%;margin:0}
43button,input{line-height:normal}
44button,select{text-transform:none}
45button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}
46button[disabled],html input[disabled]{cursor:default}
47input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}
48input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}
49input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}
50button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}
51textarea{overflow:auto;vertical-align:top}
52table{border-collapse:collapse;border-spacing:0}
53*,*:before,*:after{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}
54html,body{font-size:100%}
55body{background:#fff;color:rgba(0,0,0,.8);padding:0;margin:0;font-family:"Noto Serif","DejaVu Serif",serif;font-weight:400;font-style:normal;line-height:1;position:relative;cursor:auto;tab-size:4;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}
56a:hover{cursor:pointer}
57img,object,embed{max-width:100%;height:auto}
58object,embed{height:100%}
59img{-ms-interpolation-mode:bicubic}
60.left{float:left!important}
61.right{float:right!important}
62.text-left{text-align:left!important}
63.text-right{text-align:right!important}
64.text-center{text-align:center!important}
65.text-justify{text-align:justify!important}
66.hide{display:none}
67img,object,svg{display:inline-block;vertical-align:middle}
68textarea{height:auto;min-height:50px}
69select{width:100%}
70.center{margin-left:auto;margin-right:auto}
71.spread{width:100%}
72p.lead,.paragraph.lead>p,#preamble>.sectionbody>.paragraph:first-of-type p{font-size:1.21875em;line-height:1.6}
73.subheader,.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{line-height:1.45;color:#7a2518;font-weight:400;margin-top:0;margin-bottom:.25em}
74div,dl,dt,dd,ul,ol,li,h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6,pre,form,p,blockquote,th,td{margin:0;padding:0;direction:ltr}
75a{color:#2156a5;text-decoration:underline;line-height:inherit}
76a:hover,a:focus{color:#1d4b8f}
77a img{border:none}
78p{font-family:inherit;font-weight:400;font-size:1em;line-height:1.6;margin-bottom:1.25em;text-rendering:optimizeLegibility}
79p aside{font-size:.875em;line-height:1.35;font-style:italic}
80h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{font-family:"Open Sans","DejaVu Sans",sans-serif;font-weight:300;font-style:normal;color:#ba3925;text-rendering:optimizeLegibility;margin-top:1em;margin-bottom:.5em;line-height:1.0125em}
81h1 small,h2 small,h3 small,#toctitle small,.sidebarblock>.content>.title small,h4 small,h5 small,h6 small{font-size:60%;color:#e99b8f;line-height:0}
82h1{font-size:2.125em}
83h2{font-size:1.6875em}
84h3,#toctitle,.sidebarblock>.content>.title{font-size:1.375em}
85h4,h5{font-size:1.125em}
86h6{font-size:1em}
87hr{border:solid #ddddd8;border-width:1px 0 0;clear:both;margin:1.25em 0 1.1875em;height:0}
88em,i{font-style:italic;line-height:inherit}
89strong,b{font-weight:bold;line-height:inherit}
90small{font-size:60%;line-height:inherit}
91code{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;color:rgba(0,0,0,.9)}
92ul,ol,dl{font-size:1em;line-height:1.6;margin-bottom:1.25em;list-style-position:outside;font-family:inherit}
93ul,ol,ul.no-bullet,ol.no-bullet{margin-left:1.5em}
94ul li ul,ul li ol{margin-left:1.25em;margin-bottom:0;font-size:1em}
95ul.square li ul,ul.circle li ul,ul.disc li ul{list-style:inherit}
96ul.square{list-style-type:square}
97ul.circle{list-style-type:circle}
98ul.disc{list-style-type:disc}
99ul.no-bullet{list-style:none}
100ol li ul,ol li ol{margin-left:1.25em;margin-bottom:0}
101dl dt{margin-bottom:.3125em;font-weight:bold}
102dl dd{margin-bottom:1.25em}
103abbr,acronym{text-transform:uppercase;font-size:90%;color:rgba(0,0,0,.8);border-bottom:1px dotted #ddd;cursor:help}
104abbr{text-transform:none}
105blockquote{margin:0 0 1.25em;padding:.5625em 1.25em 0 1.1875em;border-left:1px solid #ddd}
106blockquote cite{display:block;font-size:.9375em;color:rgba(0,0,0,.6)}
107blockquote cite:before{content:"\2014 \0020"}
108blockquote cite a,blockquote cite a:visited{color:rgba(0,0,0,.6)}
109blockquote,blockquote p{line-height:1.6;color:rgba(0,0,0,.85)}
110@media only screen and (min-width:768px){h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2}
111h1{font-size:2.75em}
112h2{font-size:2.3125em}
113h3,#toctitle,.sidebarblock>.content>.title{font-size:1.6875em}
114h4{font-size:1.4375em}}
115table{background:#fff;margin-bottom:1.25em;border:solid 1px #dedede}
116table thead,table tfoot{background:#f7f8f7;font-weight:bold}
117table thead tr th,table thead tr td,table tfoot tr th,table tfoot tr td{padding:.5em .625em .625em;font-size:inherit;color:rgba(0,0,0,.8);text-align:left}
118table tr th,table tr td{padding:.5625em .625em;font-size:inherit;color:rgba(0,0,0,.8)}
119table tr.even,table tr.alt,table tr:nth-of-type(even){background:#f8f8f7}
120table thead tr th,table tfoot tr th,table tbody tr td,table tr td,table tfoot tr td{display:table-cell;line-height:1.6}
121h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2;word-spacing:-.05em}
122h1 strong,h2 strong,h3 strong,#toctitle strong,.sidebarblock>.content>.title strong,h4 strong,h5 strong,h6 strong{font-weight:400}
123.clearfix:before,.clearfix:after,.float-group:before,.float-group:after{content:" ";display:table}
124.clearfix:after,.float-group:after{clear:both}
125*:not(pre)>code{font-size:.9375em;font-style:normal!important;letter-spacing:0;padding:.1em .5ex;word-spacing:-.15em;background-color:#f7f7f8;-webkit-border-radius:4px;border-radius:4px;line-height:1.45;text-rendering:optimizeSpeed;word-wrap:break-word}
126*:not(pre)>code.nobreak{word-wrap:normal}
127*:not(pre)>code.nowrap{white-space:nowrap}
128pre,pre>code{line-height:1.45;color:rgba(0,0,0,.9);font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;text-rendering:optimizeSpeed}
129em em{font-style:normal}
130strong strong{font-weight:400}
131.keyseq{color:rgba(51,51,51,.8)}
132kbd{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;display:inline-block;color:rgba(0,0,0,.8);font-size:.65em;line-height:1.45;background-color:#f7f7f7;border:1px solid #ccc;-webkit-border-radius:3px;border-radius:3px;-webkit-box-shadow:0 1px 0 rgba(0,0,0,.2),0 0 0 .1em white inset;box-shadow:0 1px 0 rgba(0,0,0,.2),0 0 0 .1em #fff inset;margin:0 .15em;padding:.2em .5em;vertical-align:middle;position:relative;top:-.1em;white-space:nowrap}
133.keyseq kbd:first-child{margin-left:0}
134.keyseq kbd:last-child{margin-right:0}
135.menuseq,.menu{color:rgba(0,0,0,.8)}
136b.button:before,b.button:after{position:relative;top:-1px;font-weight:400}
137b.button:before{content:"[";padding:0 3px 0 2px}
138b.button:after{content:"]";padding:0 2px 0 3px}
139p a>code:hover{color:rgba(0,0,0,.9)}
140#header,#content,#footnotes,#footer{width:100%;margin-left:auto;margin-right:auto;margin-top:0;margin-bottom:0;max-width:62.5em;*zoom:1;position:relative;padding-left:.9375em;padding-right:.9375em}
141#header:before,#header:after,#content:before,#content:after,#footnotes:before,#footnotes:after,#footer:before,#footer:after{content:" ";display:table}
142#header:after,#content:after,#footnotes:after,#footer:after{clear:both}
143#content{margin-top:1.25em}
144#content:before{content:none}
145#header>h1:first-child{color:rgba(0,0,0,.85);margin-top:2.25rem;margin-bottom:0}
146#header>h1:first-child+#toc{margin-top:8px;border-top:1px solid #ddddd8}
147#header>h1:only-child,body.toc2 #header>h1:nth-last-child(2){border-bottom:1px solid #ddddd8;padding-bottom:8px}
148#header .details{border-bottom:1px solid #ddddd8;line-height:1.45;padding-top:.25em;padding-bottom:.25em;padding-left:.25em;color:rgba(0,0,0,.6);display:-ms-flexbox;display:-webkit-flex;display:flex;-ms-flex-flow:row wrap;-webkit-flex-flow:row wrap;flex-flow:row wrap}
149#header .details span:first-child{margin-left:-.125em}
150#header .details span.email a{color:rgba(0,0,0,.85)}
151#header .details br{display:none}
152#header .details br+span:before{content:"\00a0\2013\00a0"}
153#header .details br+span.author:before{content:"\00a0\22c5\00a0";color:rgba(0,0,0,.85)}
154#header .details br+span#revremark:before{content:"\00a0|\00a0"}
155#header #revnumber{text-transform:capitalize}
156#header #revnumber:after{content:"\00a0"}
157#content>h1:first-child:not([class]){color:rgba(0,0,0,.85);border-bottom:1px solid #ddddd8;padding-bottom:8px;margin-top:0;padding-top:1rem;margin-bottom:1.25rem}
158#toc{border-bottom:1px solid #efefed;padding-bottom:.5em}
159#toc>ul{margin-left:.125em}
160#toc ul.sectlevel0>li>a{font-style:italic}
161#toc ul.sectlevel0 ul.sectlevel1{margin:.5em 0}
162#toc ul{font-family:"Open Sans","DejaVu Sans",sans-serif;list-style-type:none}
163#toc li{line-height:1.3334;margin-top:.3334em}
164#toc a{text-decoration:none}
165#toc a:active{text-decoration:underline}
166#toctitle{color:#7a2518;font-size:1.2em}
167@media only screen and (min-width:768px){#toctitle{font-size:1.375em}
168body.toc2{padding-left:15em;padding-right:0}
169#toc.toc2{margin-top:0!important;background-color:#f8f8f7;position:fixed;width:15em;left:0;top:0;border-right:1px solid #efefed;border-top-width:0!important;border-bottom-width:0!important;z-index:1000;padding:1.25em 1em;height:100%;overflow:auto}
170#toc.toc2 #toctitle{margin-top:0;margin-bottom:.8rem;font-size:1.2em}
171#toc.toc2>ul{font-size:.9em;margin-bottom:0}
172#toc.toc2 ul ul{margin-left:0;padding-left:1em}
173#toc.toc2 ul.sectlevel0 ul.sectlevel1{padding-left:0;margin-top:.5em;margin-bottom:.5em}
174body.toc2.toc-right{padding-left:0;padding-right:15em}
175body.toc2.toc-right #toc.toc2{border-right-width:0;border-left:1px solid #efefed;left:auto;right:0}}
176@media only screen and (min-width:1280px){body.toc2{padding-left:20em;padding-right:0}
177#toc.toc2{width:20em}
178#toc.toc2 #toctitle{font-size:1.375em}
179#toc.toc2>ul{font-size:.95em}
180#toc.toc2 ul ul{padding-left:1.25em}
181body.toc2.toc-right{padding-left:0;padding-right:20em}}
182#content #toc{border-style:solid;border-width:1px;border-color:#e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;-webkit-border-radius:4px;border-radius:4px}
183#content #toc>:first-child{margin-top:0}
184#content #toc>:last-child{margin-bottom:0}
185#footer{max-width:100%;background-color:rgba(0,0,0,.8);padding:1.25em}
186#footer-text{color:rgba(255,255,255,.8);line-height:1.44}
187.sect1{padding-bottom:.625em}
188@media only screen and (min-width:768px){.sect1{padding-bottom:1.25em}}
189.sect1+.sect1{border-top:1px solid #efefed}
190#content h1>a.anchor,h2>a.anchor,h3>a.anchor,#toctitle>a.anchor,.sidebarblock>.content>.title>a.anchor,h4>a.anchor,h5>a.anchor,h6>a.anchor{position:absolute;z-index:1001;width:1.5ex;margin-left:-1.5ex;display:block;text-decoration:none!important;visibility:hidden;text-align:center;font-weight:400}
191#content h1>a.anchor:before,h2>a.anchor:before,h3>a.anchor:before,#toctitle>a.anchor:before,.sidebarblock>.content>.title>a.anchor:before,h4>a.anchor:before,h5>a.anchor:before,h6>a.anchor:before{content:"\00A7";font-size:.85em;display:block;padding-top:.1em}
192#content h1:hover>a.anchor,#content h1>a.anchor:hover,h2:hover>a.anchor,h2>a.anchor:hover,h3:hover>a.anchor,#toctitle:hover>a.anchor,.sidebarblock>.content>.title:hover>a.anchor,h3>a.anchor:hover,#toctitle>a.anchor:hover,.sidebarblock>.content>.title>a.anchor:hover,h4:hover>a.anchor,h4>a.anchor:hover,h5:hover>a.anchor,h5>a.anchor:hover,h6:hover>a.anchor,h6>a.anchor:hover{visibility:visible}
193#content h1>a.link,h2>a.link,h3>a.link,#toctitle>a.link,.sidebarblock>.content>.title>a.link,h4>a.link,h5>a.link,h6>a.link{color:#ba3925;text-decoration:none}
194#content h1>a.link:hover,h2>a.link:hover,h3>a.link:hover,#toctitle>a.link:hover,.sidebarblock>.content>.title>a.link:hover,h4>a.link:hover,h5>a.link:hover,h6>a.link:hover{color:#a53221}
195.audioblock,.imageblock,.literalblock,.listingblock,.stemblock,.videoblock{margin-bottom:1.25em}
196.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{text-rendering:optimizeLegibility;text-align:left;font-family:"Noto Serif","DejaVu Serif",serif;font-size:1rem;font-style:italic}
197table.tableblock>caption.title{white-space:nowrap;overflow:visible;max-width:0}
198.paragraph.lead>p,#preamble>.sectionbody>.paragraph:first-of-type p{color:rgba(0,0,0,.85)}
199table.tableblock #preamble>.sectionbody>.paragraph:first-of-type p{font-size:inherit}
200.admonitionblock>table{border-collapse:separate;border:0;background:none;width:100%}
201.admonitionblock>table td.icon{text-align:center;width:80px}
202.admonitionblock>table td.icon img{max-width:none}
203.admonitionblock>table td.icon .title{font-weight:bold;font-family:"Open Sans","DejaVu Sans",sans-serif;text-transform:uppercase}
204.admonitionblock>table td.content{padding-left:1.125em;padding-right:1.25em;border-left:1px solid #ddddd8;color:rgba(0,0,0,.6)}
205.admonitionblock>table td.content>:last-child>:last-child{margin-bottom:0}
206.exampleblock>.content{border-style:solid;border-width:1px;border-color:#e6e6e6;margin-bottom:1.25em;padding:1.25em;background:#fff;-webkit-border-radius:4px;border-radius:4px}
207.exampleblock>.content>:first-child{margin-top:0}
208.exampleblock>.content>:last-child{margin-bottom:0}
209.sidebarblock{border-style:solid;border-width:1px;border-color:#e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;-webkit-border-radius:4px;border-radius:4px}
210.sidebarblock>:first-child{margin-top:0}
211.sidebarblock>:last-child{margin-bottom:0}
212.sidebarblock>.content>.title{color:#7a2518;margin-top:0;text-align:center}
213.exampleblock>.content>:last-child>:last-child,.exampleblock>.content .olist>ol>li:last-child>:last-child,.exampleblock>.content .ulist>ul>li:last-child>:last-child,.exampleblock>.content .qlist>ol>li:last-child>:last-child,.sidebarblock>.content>:last-child>:last-child,.sidebarblock>.content .olist>ol>li:last-child>:last-child,.sidebarblock>.content .ulist>ul>li:last-child>:last-child,.sidebarblock>.content .qlist>ol>li:last-child>:last-child{margin-bottom:0}
214.literalblock pre,.listingblock pre:not(.highlight),.listingblock pre[class="highlight"],.listingblock pre[class^="highlight "],.listingblock pre.CodeRay,.listingblock pre.prettyprint{background:#f7f7f8}
215.sidebarblock .literalblock pre,.sidebarblock .listingblock pre:not(.highlight),.sidebarblock .listingblock pre[class="highlight"],.sidebarblock .listingblock pre[class^="highlight "],.sidebarblock .listingblock pre.CodeRay,.sidebarblock .listingblock pre.prettyprint{background:#f2f1f1}
216.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{-webkit-border-radius:4px;border-radius:4px;word-wrap:break-word;padding:1em;font-size:.8125em}
217.literalblock pre.nowrap,.literalblock pre[class].nowrap,.listingblock pre.nowrap,.listingblock pre[class].nowrap{overflow-x:auto;white-space:pre;word-wrap:normal}
218@media only screen and (min-width:768px){.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{font-size:.90625em}}
219@media only screen and (min-width:1280px){.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{font-size:1em}}
220.literalblock.output pre{color:#f7f7f8;background-color:rgba(0,0,0,.9)}
221.listingblock pre.highlightjs{padding:0}
222.listingblock pre.highlightjs>code{padding:1em;-webkit-border-radius:4px;border-radius:4px}
223.listingblock pre.prettyprint{border-width:0}
224.listingblock>.content{position:relative}
225.listingblock code[data-lang]:before{display:none;content:attr(data-lang);position:absolute;font-size:.75em;top:.425rem;right:.5rem;line-height:1;text-transform:uppercase;color:#999}
226.listingblock:hover code[data-lang]:before{display:block}
227.listingblock.terminal pre .command:before{content:attr(data-prompt);padding-right:.5em;color:#999}
228.listingblock.terminal pre .command:not([data-prompt]):before{content:"$"}
229table.pyhltable{border-collapse:separate;border:0;margin-bottom:0;background:none}
230table.pyhltable td{vertical-align:top;padding-top:0;padding-bottom:0;line-height:1.45}
231table.pyhltable td.code{padding-left:.75em;padding-right:0}
232pre.pygments .lineno,table.pyhltable td:not(.code){color:#999;padding-left:0;padding-right:.5em;border-right:1px solid #ddddd8}
233pre.pygments .lineno{display:inline-block;margin-right:.25em}
234table.pyhltable .linenodiv{background:none!important;padding-right:0!important}
235.quoteblock{margin:0 1em 1.25em 1.5em;display:table}
236.quoteblock>.title{margin-left:-1.5em;margin-bottom:.75em}
237.quoteblock blockquote,.quoteblock blockquote p{color:rgba(0,0,0,.85);font-size:1.15rem;line-height:1.75;word-spacing:.1em;letter-spacing:0;font-style:italic;text-align:justify}
238.quoteblock blockquote{margin:0;padding:0;border:0}
239.quoteblock blockquote:before{content:"\201c";float:left;font-size:2.75em;font-weight:bold;line-height:.6em;margin-left:-.6em;color:#7a2518;text-shadow:0 1px 2px rgba(0,0,0,.1)}
240.quoteblock blockquote>.paragraph:last-child p{margin-bottom:0}
241.quoteblock .attribution{margin-top:.5em;margin-right:.5ex;text-align:right}
242.quoteblock .quoteblock{margin-left:0;margin-right:0;padding:.5em 0;border-left:3px solid rgba(0,0,0,.6)}
243.quoteblock .quoteblock blockquote{padding:0 0 0 .75em}
244.quoteblock .quoteblock blockquote:before{display:none}
245.verseblock{margin:0 1em 1.25em 1em}
246.verseblock pre{font-family:"Open Sans","DejaVu Sans",sans;font-size:1.15rem;color:rgba(0,0,0,.85);font-weight:300;text-rendering:optimizeLegibility}
247.verseblock pre strong{font-weight:400}
248.verseblock .attribution{margin-top:1.25rem;margin-left:.5ex}
249.quoteblock .attribution,.verseblock .attribution{font-size:.9375em;line-height:1.45;font-style:italic}
250.quoteblock .attribution br,.verseblock .attribution br{display:none}
251.quoteblock .attribution cite,.verseblock .attribution cite{display:block;letter-spacing:-.025em;color:rgba(0,0,0,.6)}
252.quoteblock.abstract{margin:0 0 1.25em 0;display:block}
253.quoteblock.abstract blockquote,.quoteblock.abstract blockquote p{text-align:left;word-spacing:0}
254.quoteblock.abstract blockquote:before,.quoteblock.abstract blockquote p:first-of-type:before{display:none}
255table.tableblock{max-width:100%;border-collapse:separate}
256table.tableblock td>.paragraph:last-child p>p:last-child,table.tableblock th>p:last-child,table.tableblock td>p:last-child{margin-bottom:0}
257table.tableblock,th.tableblock,td.tableblock{border:0 solid #dedede}
258table.grid-all th.tableblock,table.grid-all td.tableblock{border-width:0 1px 1px 0}
259table.grid-all tfoot>tr>th.tableblock,table.grid-all tfoot>tr>td.tableblock{border-width:1px 1px 0 0}
260table.grid-cols th.tableblock,table.grid-cols td.tableblock{border-width:0 1px 0 0}
261table.grid-all *>tr>.tableblock:last-child,table.grid-cols *>tr>.tableblock:last-child{border-right-width:0}
262table.grid-rows th.tableblock,table.grid-rows td.tableblock{border-width:0 0 1px 0}
263table.grid-all tbody>tr:last-child>th.tableblock,table.grid-all tbody>tr:last-child>td.tableblock,table.grid-all thead:last-child>tr>th.tableblock,table.grid-rows tbody>tr:last-child>th.tableblock,table.grid-rows tbody>tr:last-child>td.tableblock,table.grid-rows thead:last-child>tr>th.tableblock{border-bottom-width:0}
264table.grid-rows tfoot>tr>th.tableblock,table.grid-rows tfoot>tr>td.tableblock{border-width:1px 0 0 0}
265table.frame-all{border-width:1px}
266table.frame-sides{border-width:0 1px}
267table.frame-topbot{border-width:1px 0}
268th.halign-left,td.halign-left{text-align:left}
269th.halign-right,td.halign-right{text-align:right}
270th.halign-center,td.halign-center{text-align:center}
271th.valign-top,td.valign-top{vertical-align:top}
272th.valign-bottom,td.valign-bottom{vertical-align:bottom}
273th.valign-middle,td.valign-middle{vertical-align:middle}
274table thead th,table tfoot th{font-weight:bold}
275tbody tr th{display:table-cell;line-height:1.6;background:#f7f8f7}
276tbody tr th,tbody tr th p,tfoot tr th,tfoot tr th p{color:rgba(0,0,0,.8);font-weight:bold}
277p.tableblock>code:only-child{background:none;padding:0}
278p.tableblock{font-size:1em}
279td>div.verse{white-space:pre}
280ol{margin-left:1.75em}
281ul li ol{margin-left:1.5em}
282dl dd{margin-left:1.125em}
283dl dd:last-child,dl dd:last-child>:last-child{margin-bottom:0}
284ol>li p,ul>li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em}
285ul.unstyled,ol.unnumbered,ul.checklist,ul.none{list-style-type:none}
286ul.unstyled,ol.unnumbered,ul.checklist{margin-left:.625em}
287ul.checklist li>p:first-child>.fa-square-o:first-child,ul.checklist li>p:first-child>.fa-check-square-o:first-child{width:1em;font-size:.85em}
288ul.checklist li>p:first-child>input[type="checkbox"]:first-child{width:1em;position:relative;top:1px}
289ul.inline{margin:0 auto .625em auto;margin-left:-1.375em;margin-right:0;padding:0;list-style:none;overflow:hidden}
290ul.inline>li{list-style:none;float:left;margin-left:1.375em;display:block}
291ul.inline>li>*{display:block}
292.unstyled dl dt{font-weight:400;font-style:normal}
293ol.arabic{list-style-type:decimal}
294ol.decimal{list-style-type:decimal-leading-zero}
295ol.loweralpha{list-style-type:lower-alpha}
296ol.upperalpha{list-style-type:upper-alpha}
297ol.lowerroman{list-style-type:lower-roman}
298ol.upperroman{list-style-type:upper-roman}
299ol.lowergreek{list-style-type:lower-greek}
300.hdlist>table,.colist>table{border:0;background:none}
301.hdlist>table>tbody>tr,.colist>table>tbody>tr{background:none}
302td.hdlist1,td.hdlist2{vertical-align:top;padding:0 .625em}
303td.hdlist1{font-weight:bold;padding-bottom:1.25em}
304.literalblock+.colist,.listingblock+.colist{margin-top:-.5em}
305.colist>table tr>td:first-of-type{padding:0 .75em;line-height:1}
306.colist>table tr>td:last-of-type{padding:.25em 0}
307.thumb,.th{line-height:0;display:inline-block;border:solid 4px #fff;-webkit-box-shadow:0 0 0 1px #ddd;box-shadow:0 0 0 1px #ddd}
308.imageblock.left,.imageblock[style*="float: left"]{margin:.25em .625em 1.25em 0}
309.imageblock.right,.imageblock[style*="float: right"]{margin:.25em 0 1.25em .625em}
310.imageblock>.title{margin-bottom:0}
311.imageblock.thumb,.imageblock.th{border-width:6px}
312.imageblock.thumb>.title,.imageblock.th>.title{padding:0 .125em}
313.image.left,.image.right{margin-top:.25em;margin-bottom:.25em;display:inline-block;line-height:0}
314.image.left{margin-right:.625em}
315.image.right{margin-left:.625em}
316a.image{text-decoration:none;display:inline-block}
317a.image object{pointer-events:none}
318sup.footnote,sup.footnoteref{font-size:.875em;position:static;vertical-align:super}
319sup.footnote a,sup.footnoteref a{text-decoration:none}
320sup.footnote a:active,sup.footnoteref a:active{text-decoration:underline}
321#footnotes{padding-top:.75em;padding-bottom:.75em;margin-bottom:.625em}
322#footnotes hr{width:20%;min-width:6.25em;margin:-.25em 0 .75em 0;border-width:1px 0 0 0}
323#footnotes .footnote{padding:0 .375em 0 .225em;line-height:1.3334;font-size:.875em;margin-left:1.2em;text-indent:-1.05em;margin-bottom:.2em}
324#footnotes .footnote a:first-of-type{font-weight:bold;text-decoration:none}
325#footnotes .footnote:last-of-type{margin-bottom:0}
326#content #footnotes{margin-top:-.625em;margin-bottom:0;padding:.75em 0}
327.gist .file-data>table{border:0;background:#fff;width:100%;margin-bottom:0}
328.gist .file-data>table td.line-data{width:99%}
329div.unbreakable{page-break-inside:avoid}
330.big{font-size:larger}
331.small{font-size:smaller}
332.underline{text-decoration:underline}
333.overline{text-decoration:overline}
334.line-through{text-decoration:line-through}
335.aqua{color:#00bfbf}
336.aqua-background{background-color:#00fafa}
337.black{color:#000}
338.black-background{background-color:#000}
339.blue{color:#0000bf}
340.blue-background{background-color:#0000fa}
341.fuchsia{color:#bf00bf}
342.fuchsia-background{background-color:#fa00fa}
343.gray{color:#606060}
344.gray-background{background-color:#7d7d7d}
345.green{color:#006000}
346.green-background{background-color:#007d00}
347.lime{color:#00bf00}
348.lime-background{background-color:#00fa00}
349.maroon{color:#600000}
350.maroon-background{background-color:#7d0000}
351.navy{color:#000060}
352.navy-background{background-color:#00007d}
353.olive{color:#606000}
354.olive-background{background-color:#7d7d00}
355.purple{color:#600060}
356.purple-background{background-color:#7d007d}
357.red{color:#bf0000}
358.red-background{background-color:#fa0000}
359.silver{color:#909090}
360.silver-background{background-color:#bcbcbc}
361.teal{color:#006060}
362.teal-background{background-color:#007d7d}
363.white{color:#bfbfbf}
364.white-background{background-color:#fafafa}
365.yellow{color:#bfbf00}
366.yellow-background{background-color:#fafa00}
367span.icon>.fa{cursor:default}
368.admonitionblock td.icon [class^="fa icon-"]{font-size:2.5em;text-shadow:1px 1px 2px rgba(0,0,0,.5);cursor:default}
369.admonitionblock td.icon .icon-note:before{content:"\f05a";color:#19407c}
370.admonitionblock td.icon .icon-tip:before{content:"\f0eb";text-shadow:1px 1px 2px rgba(155,155,0,.8);color:#111}
371.admonitionblock td.icon .icon-warning:before{content:"\f071";color:#bf6900}
372.admonitionblock td.icon .icon-caution:before{content:"\f06d";color:#bf3400}
373.admonitionblock td.icon .icon-important:before{content:"\f06a";color:#bf0000}
374.conum[data-value]{display:inline-block;color:#fff!important;background-color:rgba(0,0,0,.8);-webkit-border-radius:100px;border-radius:100px;text-align:center;font-size:.75em;width:1.67em;height:1.67em;line-height:1.67em;font-family:"Open Sans","DejaVu Sans",sans-serif;font-style:normal;font-weight:bold}
375.conum[data-value] *{color:#fff!important}
376.conum[data-value]+b{display:none}
377.conum[data-value]:after{content:attr(data-value)}
378pre .conum[data-value]{position:relative;top:-.125em}
379b.conum *{color:inherit!important}
380.conum:not([data-value]):empty{display:none}
381dt,th.tableblock,td.content,div.footnote{text-rendering:optimizeLegibility}
382h1,h2,p,td.content,span.alt{letter-spacing:-.01em}
383p strong,td.content strong,div.footnote strong{letter-spacing:-.005em}
384p,blockquote,dt,td.content,span.alt{font-size:1.0625rem}
385p{margin-bottom:1.25rem}
386.sidebarblock p,.sidebarblock dt,.sidebarblock td.content,p.tableblock{font-size:1em}
387.exampleblock>.content{background-color:#fffef7;border-color:#e0e0dc;-webkit-box-shadow:0 1px 4px #e0e0dc;box-shadow:0 1px 4px #e0e0dc}
388.print-only{display:none!important}
389@media print{@page{margin:1.25cm .75cm}
390*{-webkit-box-shadow:none!important;box-shadow:none!important;text-shadow:none!important}
391a{color:inherit!important;text-decoration:underline!important}
392a.bare,a[href^="#"],a[href^="mailto:"]{text-decoration:none!important}
393a[href^="http:"]:not(.bare):after,a[href^="https:"]:not(.bare):after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em}
394abbr[title]:after{content:" (" attr(title) ")"}
395pre,blockquote,tr,img,object,svg{page-break-inside:avoid}
396thead{display:table-header-group}
397svg{max-width:100%}
398p,blockquote,dt,td.content{font-size:1em;orphans:3;widows:3}
399h2,h3,#toctitle,.sidebarblock>.content>.title{page-break-after:avoid}
400#toc,.sidebarblock,.exampleblock>.content{background:none!important}
401#toc{border-bottom:1px solid #ddddd8!important;padding-bottom:0!important}
402.sect1{padding-bottom:0!important}
403.sect1+.sect1{border:0!important}
404#header>h1:first-child{margin-top:1.25rem}
405body.book #header{text-align:center}
406body.book #header>h1:first-child{border:0!important;margin:2.5em 0 1em 0}
407body.book #header .details{border:0!important;display:block;padding:0!important}
408body.book #header .details span:first-child{margin-left:0!important}
409body.book #header .details br{display:block}
410body.book #header .details br+span:before{content:none!important}
411body.book #toc{border:0!important;text-align:left!important;padding:0!important;margin:0!important}
412body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-break-before:always}
413.listingblock code[data-lang]:before{display:block}
414#footer{background:none!important;padding:0 .9375em}
415#footer-text{color:rgba(0,0,0,.6)!important;font-size:.9em}
416.hide-on-print{display:none!important}
417.print-only{display:block!important}
418.hide-for-print{display:none!important}
419.show-for-print{display:inherit!important}}
420</style>
421<style>
422.listingblock .pygments .hll { background-color: #ffffcc }
423.listingblock .pygments, .listingblock .pygments code { background: #f8f8f8; }
424.listingblock .pygments .tok-c { color: #408080; font-style: italic } /* Comment */
425.listingblock .pygments .tok-err { border: 1px solid #FF0000 } /* Error */
426.listingblock .pygments .tok-k { color: #008000; font-weight: bold } /* Keyword */
427.listingblock .pygments .tok-o { color: #666666 } /* Operator */
428.listingblock .pygments .tok-cm { color: #408080; font-style: italic } /* Comment.Multiline */
429.listingblock .pygments .tok-cp { color: #BC7A00 } /* Comment.Preproc */
430.listingblock .pygments .tok-c1 { color: #408080; font-style: italic } /* Comment.Single */
431.listingblock .pygments .tok-cs { color: #408080; font-style: italic } /* Comment.Special */
432.listingblock .pygments .tok-gd { color: #A00000 } /* Generic.Deleted */
433.listingblock .pygments .tok-ge { font-style: italic } /* Generic.Emph */
434.listingblock .pygments .tok-gr { color: #FF0000 } /* Generic.Error */
435.listingblock .pygments .tok-gh { color: #000080; font-weight: bold } /* Generic.Heading */
436.listingblock .pygments .tok-gi { color: #00A000 } /* Generic.Inserted */
437.listingblock .pygments .tok-go { color: #888888 } /* Generic.Output */
438.listingblock .pygments .tok-gp { color: #000080; font-weight: bold } /* Generic.Prompt */
439.listingblock .pygments .tok-gs { font-weight: bold } /* Generic.Strong */
440.listingblock .pygments .tok-gu { color: #800080; font-weight: bold } /* Generic.Subheading */
441.listingblock .pygments .tok-gt { color: #0044DD } /* Generic.Traceback */
442.listingblock .pygments .tok-kc { color: #008000; font-weight: bold } /* Keyword.Constant */
443.listingblock .pygments .tok-kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
444.listingblock .pygments .tok-kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
445.listingblock .pygments .tok-kp { color: #008000 } /* Keyword.Pseudo */
446.listingblock .pygments .tok-kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
447.listingblock .pygments .tok-kt { color: #B00040 } /* Keyword.Type */
448.listingblock .pygments .tok-m { color: #666666 } /* Literal.Number */
449.listingblock .pygments .tok-s { color: #BA2121 } /* Literal.String */
450.listingblock .pygments .tok-na { color: #7D9029 } /* Name.Attribute */
451.listingblock .pygments .tok-nb { color: #008000 } /* Name.Builtin */
452.listingblock .pygments .tok-nc { color: #0000FF; font-weight: bold } /* Name.Class */
453.listingblock .pygments .tok-no { color: #880000 } /* Name.Constant */
454.listingblock .pygments .tok-nd { color: #AA22FF } /* Name.Decorator */
455.listingblock .pygments .tok-ni { color: #999999; font-weight: bold } /* Name.Entity */
456.listingblock .pygments .tok-ne { color: #D2413A; font-weight: bold } /* Name.Exception */
457.listingblock .pygments .tok-nf { color: #0000FF } /* Name.Function */
458.listingblock .pygments .tok-nl { color: #A0A000 } /* Name.Label */
459.listingblock .pygments .tok-nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
460.listingblock .pygments .tok-nt { color: #008000; font-weight: bold } /* Name.Tag */
461.listingblock .pygments .tok-nv { color: #19177C } /* Name.Variable */
462.listingblock .pygments .tok-ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
463.listingblock .pygments .tok-w { color: #bbbbbb } /* Text.Whitespace */
464.listingblock .pygments .tok-mb { color: #666666 } /* Literal.Number.Bin */
465.listingblock .pygments .tok-mf { color: #666666 } /* Literal.Number.Float */
466.listingblock .pygments .tok-mh { color: #666666 } /* Literal.Number.Hex */
467.listingblock .pygments .tok-mi { color: #666666 } /* Literal.Number.Integer */
468.listingblock .pygments .tok-mo { color: #666666 } /* Literal.Number.Oct */
469.listingblock .pygments .tok-sb { color: #BA2121 } /* Literal.String.Backtick */
470.listingblock .pygments .tok-sc { color: #BA2121 } /* Literal.String.Char */
471.listingblock .pygments .tok-sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
472.listingblock .pygments .tok-s2 { color: #BA2121 } /* Literal.String.Double */
473.listingblock .pygments .tok-se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
474.listingblock .pygments .tok-sh { color: #BA2121 } /* Literal.String.Heredoc */
475.listingblock .pygments .tok-si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
476.listingblock .pygments .tok-sx { color: #008000 } /* Literal.String.Other */
477.listingblock .pygments .tok-sr { color: #BB6688 } /* Literal.String.Regex */
478.listingblock .pygments .tok-s1 { color: #BA2121 } /* Literal.String.Single */
479.listingblock .pygments .tok-ss { color: #19177C } /* Literal.String.Symbol */
480.listingblock .pygments .tok-bp { color: #008000 } /* Name.Builtin.Pseudo */
481.listingblock .pygments .tok-vc { color: #19177C } /* Name.Variable.Class */
482.listingblock .pygments .tok-vg { color: #19177C } /* Name.Variable.Global */
483.listingblock .pygments .tok-vi { color: #19177C } /* Name.Variable.Instance */
484.listingblock .pygments .tok-il { color: #666666 } /* Literal.Number.Integer.Long */
485</style>
486</head>
487<body class="article toc2 toc-right">
488<div id="header">
489<h1>pugixml 1.8 quick start guide</h1>
490<div class="details">
491<span id="author" class="author">website</span><br>
492<span id="email" class="email"><a href="http://pugixml.org" class="bare">http://pugixml.org</a></span><br>
493<span id="author2" class="author">repository</span><br>
494<span id="email2" class="email"><a href="http://github.com/zeux/pugixml" class="bare">http://github.com/zeux/pugixml</a></span><br>
495</div>
496<div id="toc" class="toc2">
497<div id="toctitle">Table of Contents</div>
498<ul class="sectlevel1">
499<li><a href="#introduction">Introduction</a></li>
500<li><a href="#install">Installation</a></li>
501<li><a href="#dom">Document object model</a></li>
502<li><a href="#loading">Loading document</a></li>
503<li><a href="#access">Accessing document data</a></li>
504<li><a href="#modify">Modifying document data</a></li>
505<li><a href="#saving">Saving document</a></li>
506<li><a href="#feedback">Feedback</a></li>
507<li><a href="#license">License</a></li>
508</ul>
509</div>
510</div>
511<div id="content">
512<div class="sect1">
513<h2 id="introduction"><a class="anchor" href="#introduction"></a><a class="link" href="#introduction">Introduction</a></h2>
514<div class="sectionbody">
515<div class="paragraph">
516<p><a href="http://pugixml.org/">pugixml</a> is a light-weight C&#43;&#43; XML processing library. It consists of a DOM-like interface with rich traversal/modification capabilities, an extremely fast XML parser which constructs the DOM tree from an XML file/buffer, and an XPath 1.0 implementation for complex data-driven tree queries. Full Unicode support is also available, with two Unicode interface variants and conversions between different Unicode encodings (which happen automatically during parsing/saving). The library is extremely portable and easy to integrate and use. pugixml is developed and maintained since 2006 and has many users. All code is distributed under the <a href="#license">MIT license</a>, making it completely free to use in both open-source and proprietary applications.</p>
517</div>
518<div class="paragraph">
519<p>pugixml enables very fast, convenient and memory-efficient XML document processing. However, since pugixml has a DOM parser, it can&#8217;t process XML documents that do not fit in memory; also the parser is a non-validating one, so if you need DTD/Schema validation, the library is not for you.</p>
520</div>
521<div class="paragraph">
522<p>This is the quick start guide for pugixml, which purpose is to enable you to start using the library quickly. Many important library features are either not described at all or only mentioned briefly; for more complete information you <a href="manual.html">should read the complete manual</a>.</p>
523</div>
524<div class="admonitionblock note">
525<table>
526<tr>
527<td class="icon">
528<div class="title">Note</div>
529</td>
530<td class="content">
531No documentation is perfect; neither is this one. If you find errors or omissions, please don’t hesitate to <a href="https://github.com/zeux/pugixml/issues/new">submit an issue or open a pull request</a> with a fix.
532</td>
533</tr>
534</table>
535</div>
536</div>
537</div>
538<div class="sect1">
539<h2 id="install"><a class="anchor" href="#install"></a><a class="link" href="#install">Installation</a></h2>
540<div class="sectionbody">
541<div class="paragraph">
542<p>You can download the latest source distribution as an archive:</p>
543</div>
544<div class="paragraph">
545<p><a href="https://github.com/zeux/pugixml/releases/download/v1.8/pugixml-1.8.zip">pugixml-1.8.zip</a> (Windows line endings)
546/
547<a href="https://github.com/zeux/pugixml/releases/download/v1.8/pugixml-1.8.tar.gz">pugixml-1.8.tar.gz</a> (Unix line endings)</p>
548</div>
549<div class="paragraph">
550<p>The distribution contains library source, documentation (the guide you&#8217;re reading now and the manual) and some code examples. After downloading the distribution, install pugixml by extracting all files from the compressed archive.</p>
551</div>
552<div class="paragraph">
553<p>The complete pugixml source consists of three files - one source file, <code>pugixml.cpp</code>, and two header files, <code>pugixml.hpp</code> and <code>pugiconfig.hpp</code>. <code>pugixml.hpp</code> is the primary header which you need to include in order to use pugixml classes/functions. The rest of this guide assumes that <code>pugixml.hpp</code> is either in the current directory or in one of include directories of your projects, so that <code>#include "pugixml.hpp"</code> can find the header; however you can also use relative path (i.e. <code>#include "../libs/pugixml/src/pugixml.hpp"</code>) or include directory-relative path (i.e. <code>#include &lt;xml/thirdparty/pugixml/src/pugixml.hpp&gt;</code>).</p>
554</div>
555<div class="paragraph">
556<p>The easiest way to build pugixml is to compile the source file, <code>pugixml.cpp</code>, along with the existing library/executable. This process depends on the method of building your application; for example, if you&#8217;re using Microsoft Visual Studio <sup class="footnote">[<a id="_footnoteref_1" class="footnote" href="#_footnote_1" title="View footnote.">1</a>]</sup>, Apple Xcode, Code::Blocks or any other IDE, just add <code>pugixml.cpp</code> to one of your projects. There are other building methods available, including building pugixml as a standalone static/shared library; <a href="manual.html#install.building">read the manual</a> for further information.</p>
557</div>
558</div>
559</div>
560<div class="sect1">
561<h2 id="dom"><a class="anchor" href="#dom"></a><a class="link" href="#dom">Document object model</a></h2>
562<div class="sectionbody">
563<div class="paragraph">
564<p>pugixml stores XML data in DOM-like way: the entire XML document (both document structure and element data) is stored in memory as a tree. The tree can be loaded from character stream (file, string, C&#43;&#43; I/O stream), then traversed via special API or XPath expressions. The whole tree is mutable: both node structure and node/attribute data can be changed at any time. Finally, the result of document transformations can be saved to a character stream (file, C&#43;&#43; I/O stream or custom transport).</p>
565</div>
566<div class="paragraph">
567<p>The root of the tree is the document itself, which corresponds to C&#43;&#43; type <code>xml_document</code>. Document has one or more child nodes, which correspond to C&#43;&#43; type <code>xml_node</code>. Nodes have different types; depending on a type, a node can have a collection of child nodes, a collection of attributes, which correspond to C&#43;&#43; type <code>xml_attribute</code>, and some additional data (i.e. name).</p>
568</div>
569<div class="paragraph">
570<p>The most common node types are:</p>
571</div>
572<div class="ulist">
573<ul>
574<li>
575<p>Document node (<code>node_document</code>) - this is the root of the tree, which consists of several child nodes. This node corresponds to <code>xml_document</code> class; note that <code>xml_document</code> is a sub-class of <code>xml_node</code>, so the entire node interface is also available.</p>
576</li>
577<li>
578<p>Element/tag node (<code>node_element</code>) - this is the most common type of node, which represents XML elements. Element nodes have a name, a collection of attributes and a collection of child nodes (both of which may be empty). The attribute is a simple name/value pair.</p>
579</li>
580<li>
581<p>Plain character data nodes (<code>node_pcdata</code>) represent plain text in XML. PCDATA nodes have a value, but do not have name or children/attributes. Note that <strong>plain character data is not a part of the element node but instead has its own node</strong>; for example, an element node can have several child PCDATA nodes.</p>
582</li>
583</ul>
584</div>
585<div class="paragraph">
586<p>Despite the fact that there are several node types, there are only three C&#43;&#43; types representing the tree (<code>xml_document</code>, <code>xml_node</code>, <code>xml_attribute</code>); some operations on <code>xml_node</code> are only valid for certain node types. They are described below.</p>
587</div>
588<div class="admonitionblock note">
589<table>
590<tr>
591<td class="icon">
592<div class="title">Note</div>
593</td>
594<td class="content">
595All pugixml classes and functions are located in <code>pugi</code> namespace; you have to either use explicit name qualification (i.e. <code>pugi::xml_node</code>), or to gain access to relevant symbols via <code>using</code> directive (i.e. <code>using pugi::xml_node;</code> or <code>using namespace pugi;</code>).
596</td>
597</tr>
598</table>
599</div>
600<div class="paragraph">
601<p><code>xml_document</code> is the owner of the entire document structure; destroying the document destroys the whole tree. The interface of <code>xml_document</code> consists of loading functions, saving functions and the entire interface of <code>xml_node</code>, which allows for document inspection and/or modification. Note that while <code>xml_document</code> is a sub-class of <code>xml_node</code>, <code>xml_node</code> is not a polymorphic type; the inheritance is present only to simplify usage.</p>
602</div>
603<div class="paragraph">
604<p><code>xml_node</code> is the handle to document node; it can point to any node in the document, including document itself. There is a common interface for nodes of all types. Note that <code>xml_node</code> is only a handle to the actual node, not the node itself - you can have several <code>xml_node</code> handles pointing to the same underlying object. Destroying <code>xml_node</code> handle does not destroy the node and does not remove it from the tree.</p>
605</div>
606<div class="paragraph">
607<p>There is a special value of <code>xml_node</code> type, known as null node or empty node. It does not correspond to any node in any document, and thus resembles null pointer. However, all operations are defined on empty nodes; generally the operations don&#8217;t do anything and return empty nodes/attributes or empty strings as their result. This is useful for chaining calls; i.e. you can get the grandparent of a node like so: <code>node.parent().parent()</code>; if a node is a null node or it does not have a parent, the first <code>parent()</code> call returns null node; the second <code>parent()</code> call then also returns null node, so you don&#8217;t have to check for errors twice. You can test if a handle is null via implicit boolean cast: <code>if (node) { &#8230;&#8203; }</code> or <code>if (!node) { &#8230;&#8203; }</code>.</p>
608</div>
609<div class="paragraph">
610<p><code>xml_attribute</code> is the handle to an XML attribute; it has the same semantics as <code>xml_node</code>, i.e. there can be several <code>xml_attribute</code> handles pointing to the same underlying object and there is a special null attribute value, which propagates to function results.</p>
611</div>
612<div class="paragraph">
613<p>There are two choices of interface and internal representation when configuring pugixml: you can either choose the UTF-8 (also called char) interface or UTF-16/32 (also called wchar_t) one. The choice is controlled via <code>PUGIXML_WCHAR_MODE</code> define; you can set it via <code>pugiconfig.hpp</code> or via preprocessor options. All tree functions that work with strings work with either C-style null terminated strings or STL strings of the selected character type. <a href="manual/dom.html#dom.unicode">Read the manual</a> for additional information on Unicode interface.</p>
614</div>
615</div>
616</div>
617<div class="sect1">
618<h2 id="loading"><a class="anchor" href="#loading"></a><a class="link" href="#loading">Loading document</a></h2>
619<div class="sectionbody">
620<div class="paragraph">
621<p>pugixml provides several functions for loading XML data from various places - files, C&#43;&#43; iostreams, memory buffers. All functions use an extremely fast non-validating parser. This parser is not fully W3C conformant - it can load any valid XML document, but does not perform some well-formedness checks. While considerable effort is made to reject invalid XML documents, some validation is not performed because of performance reasons. XML data is always converted to internal character format before parsing. pugixml supports all popular Unicode encodings (UTF-8, UTF-16 (big and little endian), UTF-32 (big and little endian); UCS-2 is naturally supported since it&#8217;s a strict subset of UTF-16) and handles all encoding conversions automatically.</p>
622</div>
623<div class="paragraph">
624<p>The most common source of XML data is files; pugixml provides a separate function for loading XML document from file. This function accepts file path as its first argument, and also two optional arguments, which specify parsing options and input data encoding, which are described in the manual.</p>
625</div>
626<div class="paragraph">
627<p>This is an example of loading XML document from file (<a href="samples/load_file.cpp" class="bare">samples/load_file.cpp</a>):</p>
628</div>
629<div class="listingblock">
630<div class="content">
631<pre class="pygments highlight"><code data-lang="c++"><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_document</span> <span class="tok-n">doc</span><span class="tok-p">;</span>
632
633<span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_parse_result</span> <span class="tok-n">result</span> <span class="tok-o">=</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">load_file</span><span class="tok-p">(</span><span class="tok-s">&quot;tree.xml&quot;</span><span class="tok-p">);</span>
634
635<span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;Load result: &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">result</span><span class="tok-p">.</span><span class="tok-n">description</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;, mesh name: &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">child</span><span class="tok-p">(</span><span class="tok-s">&quot;mesh&quot;</span><span class="tok-p">).</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;name&quot;</span><span class="tok-p">).</span><span class="tok-n">value</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">endl</span><span class="tok-p">;</span></code></pre>
636</div>
637</div>
638<div class="paragraph">
639<p><code>load_file</code>, as well as other loading functions, destroys the existing document tree and then tries to load the new tree from the specified file. The result of the operation is returned in an <code>xml_parse_result</code> object; this object contains the operation status, and the related information (i.e. last successfully parsed position in the input file, if parsing fails).</p>
640</div>
641<div class="paragraph">
642<p>Parsing result object can be implicitly converted to <code>bool</code>; if you do not want to handle parsing errors thoroughly, you can just check the return value of load functions as if it was a <code>bool</code>: <code>if (doc.load_file("file.xml")) { &#8230;&#8203; } else { &#8230;&#8203; }</code>. Otherwise you can use the <code>status</code> member to get parsing status, or the <code>description()</code> member function to get the status in a string form.</p>
643</div>
644<div class="paragraph">
645<p>This is an example of handling loading errors (<a href="samples/load_error_handling.cpp" class="bare">samples/load_error_handling.cpp</a>):</p>
646</div>
647<div class="listingblock">
648<div class="content">
649<pre class="pygments highlight"><code data-lang="c++"><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_document</span> <span class="tok-n">doc</span><span class="tok-p">;</span>
650<span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_parse_result</span> <span class="tok-n">result</span> <span class="tok-o">=</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">load_string</span><span class="tok-p">(</span><span class="tok-n">source</span><span class="tok-p">);</span>
651
652<span class="tok-k">if</span> <span class="tok-p">(</span><span class="tok-n">result</span><span class="tok-p">)</span>
653<span class="tok-p">{</span>
654    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;XML [&quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">source</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;] parsed without errors, attr value: [&quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">child</span><span class="tok-p">(</span><span class="tok-s">&quot;node&quot;</span><span class="tok-p">).</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;attr&quot;</span><span class="tok-p">).</span><span class="tok-n">value</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;]</span><span class="tok-se">\n\n</span><span class="tok-s">&quot;</span><span class="tok-p">;</span>
655<span class="tok-p">}</span>
656<span class="tok-k">else</span>
657<span class="tok-p">{</span>
658    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;XML [&quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">source</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;] parsed with errors, attr value: [&quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">child</span><span class="tok-p">(</span><span class="tok-s">&quot;node&quot;</span><span class="tok-p">).</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;attr&quot;</span><span class="tok-p">).</span><span class="tok-n">value</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;]</span><span class="tok-se">\n</span><span class="tok-s">&quot;</span><span class="tok-p">;</span>
659    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;Error description: &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">result</span><span class="tok-p">.</span><span class="tok-n">description</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;</span><span class="tok-se">\n</span><span class="tok-s">&quot;</span><span class="tok-p">;</span>
660    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;Error offset: &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">result</span><span class="tok-p">.</span><span class="tok-n">offset</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot; (error at [...&quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-p">(</span><span class="tok-n">source</span> <span class="tok-o">+</span> <span class="tok-n">result</span><span class="tok-p">.</span><span class="tok-n">offset</span><span class="tok-p">)</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;]</span><span class="tok-se">\n\n</span><span class="tok-s">&quot;</span><span class="tok-p">;</span>
661<span class="tok-p">}</span></code></pre>
662</div>
663</div>
664<div class="paragraph">
665<p>Sometimes XML data should be loaded from some other source than file, i.e. HTTP URL; also you may want to load XML data from file using non-standard functions, i.e. to use your virtual file system facilities or to load XML from gzip-compressed files. These scenarios either require loading document from memory, in which case you should prepare a contiguous memory block with all XML data and to pass it to one of buffer loading functions, or loading document from C&#43;&#43; IOstream, in which case you should provide an object which implements <code>std::istream</code> or <code>std::wistream</code> interface.</p>
666</div>
667<div class="paragraph">
668<p>There are different functions for loading document from memory; they treat the passed buffer as either an immutable one (<code>load_buffer</code>), a mutable buffer which is owned by the caller (<code>load_buffer_inplace</code>), or a mutable buffer which ownership belongs to pugixml (<code>load_buffer_inplace_own</code>). There is also a simple helper function, <code>xml_document::load</code>, for cases when you want to load the XML document from null-terminated character string.</p>
669</div>
670<div class="paragraph">
671<p>This is an example of loading XML document from memory using one of these functions (<a href="samples/load_memory.cpp" class="bare">samples/load_memory.cpp</a>); read the sample code for more examples:</p>
672</div>
673<div class="listingblock">
674<div class="content">
675<pre class="pygments highlight"><code data-lang="c++"><span class="tok-k">const</span> <span class="tok-kt">char</span> <span class="tok-n">source</span><span class="tok-p">[]</span> <span class="tok-o">=</span> <span class="tok-s">&quot;&lt;mesh name=&#39;sphere&#39;&gt;&lt;bounds&gt;0 0 1 1&lt;/bounds&gt;&lt;/mesh&gt;&quot;</span><span class="tok-p">;</span>
676<span class="tok-kt">size_t</span> <span class="tok-n">size</span> <span class="tok-o">=</span> <span class="tok-k">sizeof</span><span class="tok-p">(</span><span class="tok-n">source</span><span class="tok-p">);</span></code></pre>
677</div>
678</div>
679<div class="listingblock">
680<div class="content">
681<pre class="pygments highlight"><code data-lang="c++"><span class="tok-c1">// You can use load_buffer_inplace to load document from mutable memory block; the block&#39;s lifetime must exceed that of document</span>
682<span class="tok-kt">char</span><span class="tok-o">*</span> <span class="tok-n">buffer</span> <span class="tok-o">=</span> <span class="tok-k">new</span> <span class="tok-kt">char</span><span class="tok-p">[</span><span class="tok-n">size</span><span class="tok-p">];</span>
683<span class="tok-n">memcpy</span><span class="tok-p">(</span><span class="tok-n">buffer</span><span class="tok-p">,</span> <span class="tok-n">source</span><span class="tok-p">,</span> <span class="tok-n">size</span><span class="tok-p">);</span>
684
685<span class="tok-c1">// The block can be allocated by any method; the block is modified during parsing</span>
686<span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_parse_result</span> <span class="tok-n">result</span> <span class="tok-o">=</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">load_buffer_inplace</span><span class="tok-p">(</span><span class="tok-n">buffer</span><span class="tok-p">,</span> <span class="tok-n">size</span><span class="tok-p">);</span>
687
688<span class="tok-c1">// You have to destroy the block yourself after the document is no longer used</span>
689<span class="tok-k">delete</span><span class="tok-p">[]</span> <span class="tok-n">buffer</span><span class="tok-p">;</span></code></pre>
690</div>
691</div>
692<div class="paragraph">
693<p>This is a simple example of loading XML document from file using streams (<a href="samples/load_stream.cpp" class="bare">samples/load_stream.cpp</a>); read the sample code for more complex examples involving wide streams and locales:</p>
694</div>
695<div class="listingblock">
696<div class="content">
697<pre class="pygments highlight"><code data-lang="c++"><span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">ifstream</span> <span class="tok-n">stream</span><span class="tok-p">(</span><span class="tok-s">&quot;weekly-utf-8.xml&quot;</span><span class="tok-p">);</span>
698<span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_parse_result</span> <span class="tok-n">result</span> <span class="tok-o">=</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">load</span><span class="tok-p">(</span><span class="tok-n">stream</span><span class="tok-p">);</span></code></pre>
699</div>
700</div>
701</div>
702</div>
703<div class="sect1">
704<h2 id="access"><a class="anchor" href="#access"></a><a class="link" href="#access">Accessing document data</a></h2>
705<div class="sectionbody">
706<div class="paragraph">
707<p>pugixml features an extensive interface for getting various types of data from the document and for traversing the document. You can use various accessors to get node/attribute data, you can traverse the child node/attribute lists via accessors or iterators, you can do depth-first traversals with <code>xml_tree_walker</code> objects, and you can use XPath for complex data-driven queries.</p>
708</div>
709<div class="paragraph">
710<p>You can get node or attribute name via <code>name()</code> accessor, and value via <code>value()</code> accessor. Note that both functions never return null pointers - they either return a string with the relevant content, or an empty string if name/value is absent or if the handle is null. Also there are two notable things for reading values:</p>
711</div>
712<div class="ulist">
713<ul>
714<li>
715<p>It is common to store data as text contents of some node - i.e. <code>&lt;node&gt;&lt;description&gt;This is a node&lt;/description&gt;&lt;/node&gt;</code>. In this case, <code>&lt;description&gt;</code> node does not have a value, but instead has a child of type <code>node_pcdata</code> with value <code>"This is a node"</code>. pugixml provides <code>child_value()</code> and <code>text()</code> helper functions to parse such data.</p>
716</li>
717<li>
718<p>In many cases attribute values have types that are not strings - i.e. an attribute may always contain values that should be treated as integers, despite the fact that they are represented as strings in XML. pugixml provides several accessors that convert attribute value to some other type.</p>
719</li>
720</ul>
721</div>
722<div class="paragraph">
723<p>This is an example of using these functions (<a href="samples/traverse_base.cpp" class="bare">samples/traverse_base.cpp</a>):</p>
724</div>
725<div class="listingblock">
726<div class="content">
727<pre class="pygments highlight"><code data-lang="c++"><span class="tok-k">for</span> <span class="tok-p">(</span><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span> <span class="tok-n">tool</span> <span class="tok-o">=</span> <span class="tok-n">tools</span><span class="tok-p">.</span><span class="tok-n">child</span><span class="tok-p">(</span><span class="tok-s">&quot;Tool&quot;</span><span class="tok-p">);</span> <span class="tok-n">tool</span><span class="tok-p">;</span> <span class="tok-n">tool</span> <span class="tok-o">=</span> <span class="tok-n">tool</span><span class="tok-p">.</span><span class="tok-n">next_sibling</span><span class="tok-p">(</span><span class="tok-s">&quot;Tool&quot;</span><span class="tok-p">))</span>
728<span class="tok-p">{</span>
729    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;Tool &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">tool</span><span class="tok-p">.</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;Filename&quot;</span><span class="tok-p">).</span><span class="tok-n">value</span><span class="tok-p">();</span>
730    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;: AllowRemote &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">tool</span><span class="tok-p">.</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;AllowRemote&quot;</span><span class="tok-p">).</span><span class="tok-n">as_bool</span><span class="tok-p">();</span>
731    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;, Timeout &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">tool</span><span class="tok-p">.</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;Timeout&quot;</span><span class="tok-p">).</span><span class="tok-n">as_int</span><span class="tok-p">();</span>
732    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;, Description &#39;&quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">tool</span><span class="tok-p">.</span><span class="tok-n">child_value</span><span class="tok-p">(</span><span class="tok-s">&quot;Description&quot;</span><span class="tok-p">)</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;&#39;</span><span class="tok-se">\n</span><span class="tok-s">&quot;</span><span class="tok-p">;</span>
733<span class="tok-p">}</span></code></pre>
734</div>
735</div>
736<div class="paragraph">
737<p>Since a lot of document traversal consists of finding the node/attribute with the correct name, there are special functions for that purpose. For example, <code>child("Tool")</code> returns the first node which has the name <code>"Tool"</code>, or null handle if there is no such node. This is an example of using such functions (<a href="samples/traverse_base.cpp" class="bare">samples/traverse_base.cpp</a>):</p>
738</div>
739<div class="listingblock">
740<div class="content">
741<pre class="pygments highlight"><code data-lang="c++"><span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;Tool for *.dae generation: &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">tools</span><span class="tok-p">.</span><span class="tok-n">find_child_by_attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;Tool&quot;</span><span class="tok-p">,</span> <span class="tok-s">&quot;OutputFileMasks&quot;</span><span class="tok-p">,</span> <span class="tok-s">&quot;*.dae&quot;</span><span class="tok-p">).</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;Filename&quot;</span><span class="tok-p">).</span><span class="tok-n">value</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;</span><span class="tok-se">\n</span><span class="tok-s">&quot;</span><span class="tok-p">;</span>
742
743<span class="tok-k">for</span> <span class="tok-p">(</span><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span> <span class="tok-n">tool</span> <span class="tok-o">=</span> <span class="tok-n">tools</span><span class="tok-p">.</span><span class="tok-n">child</span><span class="tok-p">(</span><span class="tok-s">&quot;Tool&quot;</span><span class="tok-p">);</span> <span class="tok-n">tool</span><span class="tok-p">;</span> <span class="tok-n">tool</span> <span class="tok-o">=</span> <span class="tok-n">tool</span><span class="tok-p">.</span><span class="tok-n">next_sibling</span><span class="tok-p">(</span><span class="tok-s">&quot;Tool&quot;</span><span class="tok-p">))</span>
744<span class="tok-p">{</span>
745    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;Tool &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">tool</span><span class="tok-p">.</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;Filename&quot;</span><span class="tok-p">).</span><span class="tok-n">value</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;</span><span class="tok-se">\n</span><span class="tok-s">&quot;</span><span class="tok-p">;</span>
746<span class="tok-p">}</span></code></pre>
747</div>
748</div>
749<div class="paragraph">
750<p>Child node lists and attribute lists are simply double-linked lists; while you can use <code>previous_sibling</code>/<code>next_sibling</code> and other such functions for iteration, pugixml additionally provides node and attribute iterators, so that you can treat nodes as containers of other nodes or attributes. All iterators are bidirectional and support all usual iterator operations. The iterators are invalidated if the node/attribute objects they&#8217;re pointing to are removed from the tree; adding nodes/attributes does not invalidate any iterators.</p>
751</div>
752<div class="paragraph">
753<p>Here is an example of using iterators for document traversal (<a href="samples/traverse_iter.cpp" class="bare">samples/traverse_iter.cpp</a>):</p>
754</div>
755<div class="listingblock">
756<div class="content">
757<pre class="pygments highlight"><code data-lang="c++"><span class="tok-k">for</span> <span class="tok-p">(</span><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node_iterator</span> <span class="tok-n">it</span> <span class="tok-o">=</span> <span class="tok-n">tools</span><span class="tok-p">.</span><span class="tok-n">begin</span><span class="tok-p">();</span> <span class="tok-n">it</span> <span class="tok-o">!=</span> <span class="tok-n">tools</span><span class="tok-p">.</span><span class="tok-n">end</span><span class="tok-p">();</span> <span class="tok-o">++</span><span class="tok-n">it</span><span class="tok-p">)</span>
758<span class="tok-p">{</span>
759    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;Tool:&quot;</span><span class="tok-p">;</span>
760
761    <span class="tok-k">for</span> <span class="tok-p">(</span><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_attribute_iterator</span> <span class="tok-n">ait</span> <span class="tok-o">=</span> <span class="tok-n">it</span><span class="tok-o">-&gt;</span><span class="tok-n">attributes_begin</span><span class="tok-p">();</span> <span class="tok-n">ait</span> <span class="tok-o">!=</span> <span class="tok-n">it</span><span class="tok-o">-&gt;</span><span class="tok-n">attributes_end</span><span class="tok-p">();</span> <span class="tok-o">++</span><span class="tok-n">ait</span><span class="tok-p">)</span>
762    <span class="tok-p">{</span>
763        <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot; &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">ait</span><span class="tok-o">-&gt;</span><span class="tok-n">name</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;=&quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">ait</span><span class="tok-o">-&gt;</span><span class="tok-n">value</span><span class="tok-p">();</span>
764    <span class="tok-p">}</span>
765
766    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">endl</span><span class="tok-p">;</span>
767<span class="tok-p">}</span></code></pre>
768</div>
769</div>
770<div class="paragraph">
771<p>If your C&#43;&#43; compiler supports range-based for-loop (this is a C&#43;&#43;11 feature, at the time of writing it&#8217;s supported by Microsoft Visual Studio 11 Beta, GCC 4.6 and Clang 3.0), you can use it to enumerate nodes/attributes. Additional helpers are provided to support this; note that they are also compatible with <a href="http://www.boost.org/libs/foreach/">Boost Foreach</a>, and possibly other pre-C&#43;&#43;11 foreach facilities.</p>
772</div>
773<div class="paragraph">
774<p>Here is an example of using C&#43;&#43;11 range-based for loop for document traversal (<a href="samples/traverse_rangefor.cpp" class="bare">samples/traverse_rangefor.cpp</a>):</p>
775</div>
776<div class="listingblock">
777<div class="content">
778<pre class="pygments highlight"><code data-lang="c++"><span class="tok-k">for</span> <span class="tok-p">(</span><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span> <span class="tok-nl">tool</span><span class="tok-p">:</span> <span class="tok-n">tools</span><span class="tok-p">.</span><span class="tok-n">children</span><span class="tok-p">(</span><span class="tok-s">&quot;Tool&quot;</span><span class="tok-p">))</span>
779<span class="tok-p">{</span>
780    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;Tool:&quot;</span><span class="tok-p">;</span>
781
782    <span class="tok-k">for</span> <span class="tok-p">(</span><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_attribute</span> <span class="tok-nl">attr</span><span class="tok-p">:</span> <span class="tok-n">tool</span><span class="tok-p">.</span><span class="tok-n">attributes</span><span class="tok-p">())</span>
783    <span class="tok-p">{</span>
784        <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot; &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">attr</span><span class="tok-p">.</span><span class="tok-n">name</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;=&quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">attr</span><span class="tok-p">.</span><span class="tok-n">value</span><span class="tok-p">();</span>
785    <span class="tok-p">}</span>
786
787    <span class="tok-k">for</span> <span class="tok-p">(</span><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span> <span class="tok-nl">child</span><span class="tok-p">:</span> <span class="tok-n">tool</span><span class="tok-p">.</span><span class="tok-n">children</span><span class="tok-p">())</span>
788    <span class="tok-p">{</span>
789        <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;, child &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">child</span><span class="tok-p">.</span><span class="tok-n">name</span><span class="tok-p">();</span>
790    <span class="tok-p">}</span>
791
792    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">endl</span><span class="tok-p">;</span>
793<span class="tok-p">}</span></code></pre>
794</div>
795</div>
796<div class="paragraph">
797<p>The methods described above allow traversal of immediate children of some node; if you want to do a deep tree traversal, you&#8217;ll have to do it via a recursive function or some equivalent method. However, pugixml provides a helper for depth-first traversal of a subtree. In order to use it, you have to implement <code>xml_tree_walker</code> interface and to call <code>traverse</code> function.</p>
798</div>
799<div class="paragraph">
800<p>This is an example of traversing tree hierarchy with xml_tree_walker (<a href="samples/traverse_walker.cpp" class="bare">samples/traverse_walker.cpp</a>):</p>
801</div>
802<div class="listingblock">
803<div class="content">
804<pre class="pygments highlight"><code data-lang="c++"><span class="tok-k">struct</span> <span class="tok-nl">simple_walker</span><span class="tok-p">:</span> <span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_tree_walker</span>
805<span class="tok-p">{</span>
806    <span class="tok-k">virtual</span> <span class="tok-kt">bool</span> <span class="tok-n">for_each</span><span class="tok-p">(</span><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span><span class="tok-o">&amp;</span> <span class="tok-n">node</span><span class="tok-p">)</span>
807    <span class="tok-p">{</span>
808        <span class="tok-k">for</span> <span class="tok-p">(</span><span class="tok-kt">int</span> <span class="tok-n">i</span> <span class="tok-o">=</span> <span class="tok-mi">0</span><span class="tok-p">;</span> <span class="tok-n">i</span> <span class="tok-o">&lt;</span> <span class="tok-n">depth</span><span class="tok-p">();</span> <span class="tok-o">++</span><span class="tok-n">i</span><span class="tok-p">)</span> <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;  &quot;</span><span class="tok-p">;</span> <span class="tok-c1">// indentation</span>
809
810        <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">node_types</span><span class="tok-p">[</span><span class="tok-n">node</span><span class="tok-p">.</span><span class="tok-n">type</span><span class="tok-p">()]</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;: name=&#39;&quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">node</span><span class="tok-p">.</span><span class="tok-n">name</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;&#39;, value=&#39;&quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">node</span><span class="tok-p">.</span><span class="tok-n">value</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;&#39;</span><span class="tok-se">\n</span><span class="tok-s">&quot;</span><span class="tok-p">;</span>
811
812        <span class="tok-k">return</span> <span class="tok-nb">true</span><span class="tok-p">;</span> <span class="tok-c1">// continue traversal</span>
813    <span class="tok-p">}</span>
814<span class="tok-p">};</span></code></pre>
815</div>
816</div>
817<div class="listingblock">
818<div class="content">
819<pre class="pygments highlight"><code data-lang="c++"><span class="tok-n">simple_walker</span> <span class="tok-n">walker</span><span class="tok-p">;</span>
820<span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">traverse</span><span class="tok-p">(</span><span class="tok-n">walker</span><span class="tok-p">);</span></code></pre>
821</div>
822</div>
823<div class="paragraph">
824<p>Finally, for complex queries often a higher-level DSL is needed. pugixml provides an implementation of XPath 1.0 language for such queries. The complete description of XPath usage can be found in the manual, but here are some examples:</p>
825</div>
826<div class="listingblock">
827<div class="content">
828<pre class="pygments highlight"><code data-lang="c++"><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xpath_node_set</span> <span class="tok-n">tools</span> <span class="tok-o">=</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">select_nodes</span><span class="tok-p">(</span><span class="tok-s">&quot;/Profile/Tools/Tool[@AllowRemote=&#39;true&#39; and @DeriveCaptionFrom=&#39;lastparam&#39;]&quot;</span><span class="tok-p">);</span>
829
830<span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;Tools:</span><span class="tok-se">\n</span><span class="tok-s">&quot;</span><span class="tok-p">;</span>
831
832<span class="tok-k">for</span> <span class="tok-p">(</span><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xpath_node_set</span><span class="tok-o">::</span><span class="tok-n">const_iterator</span> <span class="tok-n">it</span> <span class="tok-o">=</span> <span class="tok-n">tools</span><span class="tok-p">.</span><span class="tok-n">begin</span><span class="tok-p">();</span> <span class="tok-n">it</span> <span class="tok-o">!=</span> <span class="tok-n">tools</span><span class="tok-p">.</span><span class="tok-n">end</span><span class="tok-p">();</span> <span class="tok-o">++</span><span class="tok-n">it</span><span class="tok-p">)</span>
833<span class="tok-p">{</span>
834    <span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xpath_node</span> <span class="tok-n">node</span> <span class="tok-o">=</span> <span class="tok-o">*</span><span class="tok-n">it</span><span class="tok-p">;</span>
835    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">node</span><span class="tok-p">.</span><span class="tok-n">node</span><span class="tok-p">().</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;Filename&quot;</span><span class="tok-p">).</span><span class="tok-n">value</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;</span><span class="tok-se">\n</span><span class="tok-s">&quot;</span><span class="tok-p">;</span>
836<span class="tok-p">}</span>
837
838<span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xpath_node</span> <span class="tok-n">build_tool</span> <span class="tok-o">=</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">select_node</span><span class="tok-p">(</span><span class="tok-s">&quot;//Tool[contains(Description, &#39;build system&#39;)]&quot;</span><span class="tok-p">);</span>
839
840<span class="tok-k">if</span> <span class="tok-p">(</span><span class="tok-n">build_tool</span><span class="tok-p">)</span>
841    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;Build tool: &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">build_tool</span><span class="tok-p">.</span><span class="tok-n">node</span><span class="tok-p">().</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;Filename&quot;</span><span class="tok-p">).</span><span class="tok-n">value</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;</span><span class="tok-se">\n</span><span class="tok-s">&quot;</span><span class="tok-p">;</span></code></pre>
842</div>
843</div>
844<div class="admonitionblock caution">
845<table>
846<tr>
847<td class="icon">
848<div class="title">Caution</div>
849</td>
850<td class="content">
851XPath functions throw <code>xpath_exception</code> objects on error; the sample above does not catch these exceptions.
852</td>
853</tr>
854</table>
855</div>
856</div>
857</div>
858<div class="sect1">
859<h2 id="modify"><a class="anchor" href="#modify"></a><a class="link" href="#modify">Modifying document data</a></h2>
860<div class="sectionbody">
861<div class="paragraph">
862<p>The document in pugixml is fully mutable: you can completely change the document structure and modify the data of nodes/attributes. All functions take care of memory management and structural integrity themselves, so they always result in structurally valid tree - however, it is possible to create an invalid XML tree (for example, by adding two attributes with the same name or by setting attribute/node name to empty/invalid string). Tree modification is optimized for performance and for memory consumption, so if you have enough memory you can create documents from scratch with pugixml and later save them to file/stream instead of relying on error-prone manual text writing and without too much overhead.</p>
863</div>
864<div class="paragraph">
865<p>All member functions that change node/attribute data or structure are non-constant and thus can not be called on constant handles. However, you can easily convert constant handle to non-constant one by simple assignment: <code>void foo(const pugi::xml_node&amp; n) { pugi::xml_node nc = n; }</code>, so const-correctness here mainly provides additional documentation.</p>
866</div>
867<div class="paragraph">
868<p>As discussed before, nodes can have name and value, both of which are strings. Depending on node type, name or value may be absent. You can use <code>set_name</code> and <code>set_value</code> member functions to set them. Similar functions are available for attributes; however, the <code>set_value</code> function is overloaded for some other types except strings, like floating-point numbers. Also, attribute value can be set using an assignment operator. This is an example of setting node/attribute name and value (<a href="samples/modify_base.cpp" class="bare">samples/modify_base.cpp</a>):</p>
869</div>
870<div class="listingblock">
871<div class="content">
872<pre class="pygments highlight"><code data-lang="c++"><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span> <span class="tok-n">node</span> <span class="tok-o">=</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">child</span><span class="tok-p">(</span><span class="tok-s">&quot;node&quot;</span><span class="tok-p">);</span>
873
874<span class="tok-c1">// change node name</span>
875<span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">node</span><span class="tok-p">.</span><span class="tok-n">set_name</span><span class="tok-p">(</span><span class="tok-s">&quot;notnode&quot;</span><span class="tok-p">);</span>
876<span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;, new node name: &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">node</span><span class="tok-p">.</span><span class="tok-n">name</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">endl</span><span class="tok-p">;</span>
877
878<span class="tok-c1">// change comment text</span>
879<span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">last_child</span><span class="tok-p">().</span><span class="tok-n">set_value</span><span class="tok-p">(</span><span class="tok-s">&quot;useless comment&quot;</span><span class="tok-p">);</span>
880<span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;, new comment text: &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">last_child</span><span class="tok-p">().</span><span class="tok-n">value</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">endl</span><span class="tok-p">;</span>
881
882<span class="tok-c1">// we can&#39;t change value of the element or name of the comment</span>
883<span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">node</span><span class="tok-p">.</span><span class="tok-n">set_value</span><span class="tok-p">(</span><span class="tok-s">&quot;1&quot;</span><span class="tok-p">)</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;, &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">last_child</span><span class="tok-p">().</span><span class="tok-n">set_name</span><span class="tok-p">(</span><span class="tok-s">&quot;2&quot;</span><span class="tok-p">)</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">endl</span><span class="tok-p">;</span></code></pre>
884</div>
885</div>
886<div class="listingblock">
887<div class="content">
888<pre class="pygments highlight"><code data-lang="c++"><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_attribute</span> <span class="tok-n">attr</span> <span class="tok-o">=</span> <span class="tok-n">node</span><span class="tok-p">.</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;id&quot;</span><span class="tok-p">);</span>
889
890<span class="tok-c1">// change attribute name/value</span>
891<span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">attr</span><span class="tok-p">.</span><span class="tok-n">set_name</span><span class="tok-p">(</span><span class="tok-s">&quot;key&quot;</span><span class="tok-p">)</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;, &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">attr</span><span class="tok-p">.</span><span class="tok-n">set_value</span><span class="tok-p">(</span><span class="tok-s">&quot;345&quot;</span><span class="tok-p">);</span>
892<span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;, new attribute: &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">attr</span><span class="tok-p">.</span><span class="tok-n">name</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;=&quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">attr</span><span class="tok-p">.</span><span class="tok-n">value</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">endl</span><span class="tok-p">;</span>
893
894<span class="tok-c1">// we can use numbers or booleans</span>
895<span class="tok-n">attr</span><span class="tok-p">.</span><span class="tok-n">set_value</span><span class="tok-p">(</span><span class="tok-mf">1.234</span><span class="tok-p">);</span>
896<span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;new attribute value: &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">attr</span><span class="tok-p">.</span><span class="tok-n">value</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">endl</span><span class="tok-p">;</span>
897
898<span class="tok-c1">// we can also use assignment operators for more concise code</span>
899<span class="tok-n">attr</span> <span class="tok-o">=</span> <span class="tok-nb">true</span><span class="tok-p">;</span>
900<span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;final attribute value: &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">attr</span><span class="tok-p">.</span><span class="tok-n">value</span><span class="tok-p">()</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">endl</span><span class="tok-p">;</span></code></pre>
901</div>
902</div>
903<div class="paragraph">
904<p>Nodes and attributes do not exist without a document tree, so you can&#8217;t create them without adding them to some document. A node or attribute can be created at the end of node/attribute list or before/after some other node. All insertion functions return the handle to newly created object on success, and null handle on failure. Even if the operation fails (for example, if you&#8217;re trying to add a child node to PCDATA node), the document remains in consistent state, but the requested node/attribute is not added.</p>
905</div>
906<div class="admonitionblock caution">
907<table>
908<tr>
909<td class="icon">
910<div class="title">Caution</div>
911</td>
912<td class="content">
913<code>attribute()</code> and <code>child()</code> functions do not add attributes or nodes to the tree, so code like <code>node.attribute("id") = 123;</code> will not do anything if <code>node</code> does not have an attribute with name <code>"id"</code>. Make sure you&#8217;re operating with existing attributes/nodes by adding them if necessary.
914</td>
915</tr>
916</table>
917</div>
918<div class="paragraph">
919<p>This is an example of adding new attributes/nodes to the document (<a href="samples/modify_add.cpp" class="bare">samples/modify_add.cpp</a>):</p>
920</div>
921<div class="listingblock">
922<div class="content">
923<pre class="pygments highlight"><code data-lang="c++"><span class="tok-c1">// add node with some name</span>
924<span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span> <span class="tok-n">node</span> <span class="tok-o">=</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">append_child</span><span class="tok-p">(</span><span class="tok-s">&quot;node&quot;</span><span class="tok-p">);</span>
925
926<span class="tok-c1">// add description node with text child</span>
927<span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span> <span class="tok-n">descr</span> <span class="tok-o">=</span> <span class="tok-n">node</span><span class="tok-p">.</span><span class="tok-n">append_child</span><span class="tok-p">(</span><span class="tok-s">&quot;description&quot;</span><span class="tok-p">);</span>
928<span class="tok-n">descr</span><span class="tok-p">.</span><span class="tok-n">append_child</span><span class="tok-p">(</span><span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">node_pcdata</span><span class="tok-p">).</span><span class="tok-n">set_value</span><span class="tok-p">(</span><span class="tok-s">&quot;Simple node&quot;</span><span class="tok-p">);</span>
929
930<span class="tok-c1">// add param node before the description</span>
931<span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span> <span class="tok-n">param</span> <span class="tok-o">=</span> <span class="tok-n">node</span><span class="tok-p">.</span><span class="tok-n">insert_child_before</span><span class="tok-p">(</span><span class="tok-s">&quot;param&quot;</span><span class="tok-p">,</span> <span class="tok-n">descr</span><span class="tok-p">);</span>
932
933<span class="tok-c1">// add attributes to param node</span>
934<span class="tok-n">param</span><span class="tok-p">.</span><span class="tok-n">append_attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;name&quot;</span><span class="tok-p">)</span> <span class="tok-o">=</span> <span class="tok-s">&quot;version&quot;</span><span class="tok-p">;</span>
935<span class="tok-n">param</span><span class="tok-p">.</span><span class="tok-n">append_attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;value&quot;</span><span class="tok-p">)</span> <span class="tok-o">=</span> <span class="tok-mf">1.1</span><span class="tok-p">;</span>
936<span class="tok-n">param</span><span class="tok-p">.</span><span class="tok-n">insert_attribute_after</span><span class="tok-p">(</span><span class="tok-s">&quot;type&quot;</span><span class="tok-p">,</span> <span class="tok-n">param</span><span class="tok-p">.</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;name&quot;</span><span class="tok-p">))</span> <span class="tok-o">=</span> <span class="tok-s">&quot;float&quot;</span><span class="tok-p">;</span></code></pre>
937</div>
938</div>
939<div class="paragraph">
940<p>If you do not want your document to contain some node or attribute, you can remove it with <code>remove_attribute</code> and <code>remove_child</code> functions. Removing the attribute or node invalidates all handles to the same underlying object, and also invalidates all iterators pointing to the same object. Removing node also invalidates all past-the-end iterators to its attribute or child node list. Be careful to ensure that all such handles and iterators either do not exist or are not used after the attribute/node is removed.</p>
941</div>
942<div class="paragraph">
943<p>This is an example of removing attributes/nodes from the document (<a href="samples/modify_remove.cpp" class="bare">samples/modify_remove.cpp</a>):</p>
944</div>
945<div class="listingblock">
946<div class="content">
947<pre class="pygments highlight"><code data-lang="c++"><span class="tok-c1">// remove description node with the whole subtree</span>
948<span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span> <span class="tok-n">node</span> <span class="tok-o">=</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">child</span><span class="tok-p">(</span><span class="tok-s">&quot;node&quot;</span><span class="tok-p">);</span>
949<span class="tok-n">node</span><span class="tok-p">.</span><span class="tok-n">remove_child</span><span class="tok-p">(</span><span class="tok-s">&quot;description&quot;</span><span class="tok-p">);</span>
950
951<span class="tok-c1">// remove id attribute</span>
952<span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_node</span> <span class="tok-n">param</span> <span class="tok-o">=</span> <span class="tok-n">node</span><span class="tok-p">.</span><span class="tok-n">child</span><span class="tok-p">(</span><span class="tok-s">&quot;param&quot;</span><span class="tok-p">);</span>
953<span class="tok-n">param</span><span class="tok-p">.</span><span class="tok-n">remove_attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;value&quot;</span><span class="tok-p">);</span>
954
955<span class="tok-c1">// we can also remove nodes/attributes by handles</span>
956<span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_attribute</span> <span class="tok-n">id</span> <span class="tok-o">=</span> <span class="tok-n">param</span><span class="tok-p">.</span><span class="tok-n">attribute</span><span class="tok-p">(</span><span class="tok-s">&quot;name&quot;</span><span class="tok-p">);</span>
957<span class="tok-n">param</span><span class="tok-p">.</span><span class="tok-n">remove_attribute</span><span class="tok-p">(</span><span class="tok-n">id</span><span class="tok-p">);</span></code></pre>
958</div>
959</div>
960</div>
961</div>
962<div class="sect1">
963<h2 id="saving"><a class="anchor" href="#saving"></a><a class="link" href="#saving">Saving document</a></h2>
964<div class="sectionbody">
965<div class="paragraph">
966<p>Often after creating a new document or loading the existing one and processing it, it is necessary to save the result back to file. Also it is occasionally useful to output the whole document or a subtree to some stream; use cases include debug printing, serialization via network or other text-oriented medium, etc. pugixml provides several functions to output any subtree of the document to a file, stream or another generic transport interface; these functions allow to customize the output format, and also perform necessary encoding conversions.</p>
967</div>
968<div class="paragraph">
969<p>Before writing to the destination the node/attribute data is properly formatted according to the node type; all special XML symbols, such as &lt; and &amp;, are properly escaped. In order to guard against forgotten node/attribute names, empty node/attribute names are printed as <code>":anonymous"</code>. For well-formed output, make sure all node and attribute names are set to meaningful values.</p>
970</div>
971<div class="paragraph">
972<p>If you want to save the whole document to a file, you can use the <code>save_file</code> function, which returns <code>true</code> on success. This is a simple example of saving XML document to file (<a href="samples/save_file.cpp" class="bare">samples/save_file.cpp</a>):</p>
973</div>
974<div class="listingblock">
975<div class="content">
976<pre class="pygments highlight"><code data-lang="c++"><span class="tok-c1">// save document to file</span>
977<span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;Saving result: &quot;</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">save_file</span><span class="tok-p">(</span><span class="tok-s">&quot;save_file_output.xml&quot;</span><span class="tok-p">)</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">endl</span><span class="tok-p">;</span></code></pre>
978</div>
979</div>
980<div class="paragraph">
981<p>To enhance interoperability pugixml provides functions for saving document to any object which implements C&#43;&#43; <code>std::ostream</code> interface. This allows you to save documents to any standard C&#43;&#43; stream (i.e. file stream) or any third-party compliant implementation (i.e. Boost Iostreams). Most notably, this allows for easy debug output, since you can use <code>std::cout</code> stream as saving target. There are two functions, one works with narrow character streams, another handles wide character ones.</p>
982</div>
983<div class="paragraph">
984<p>This is a simple example of saving XML document to standard output (<a href="samples/save_stream.cpp" class="bare">samples/save_stream.cpp</a>):</p>
985</div>
986<div class="listingblock">
987<div class="content">
988<pre class="pygments highlight"><code data-lang="c++"><span class="tok-c1">// save document to standard output</span>
989<span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span> <span class="tok-o">&lt;&lt;</span> <span class="tok-s">&quot;Document:</span><span class="tok-se">\n</span><span class="tok-s">&quot;</span><span class="tok-p">;</span>
990<span class="tok-n">doc</span><span class="tok-p">.</span><span class="tok-n">save</span><span class="tok-p">(</span><span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">cout</span><span class="tok-p">);</span></code></pre>
991</div>
992</div>
993<div class="paragraph">
994<p>All of the above saving functions are implemented in terms of writer interface. This is a simple interface with a single function, which is called several times during output process with chunks of document data as input. In order to output the document via some custom transport, for example sockets, you should create an object which implements <code>xml_writer_file</code> interface and pass it to <code>xml_document::save</code> function.</p>
995</div>
996<div class="paragraph">
997<p>This is a simple example of custom writer for saving document data to STL string (<a href="samples/save_custom_writer.cpp" class="bare">samples/save_custom_writer.cpp</a>); read the sample code for more complex examples:</p>
998</div>
999<div class="listingblock">
1000<div class="content">
1001<pre class="pygments highlight"><code data-lang="c++"><span class="tok-k">struct</span> <span class="tok-nl">xml_string_writer</span><span class="tok-p">:</span> <span class="tok-n">pugi</span><span class="tok-o">::</span><span class="tok-n">xml_writer</span>
1002<span class="tok-p">{</span>
1003    <span class="tok-n">std</span><span class="tok-o">::</span><span class="tok-n">string</span> <span class="tok-n">result</span><span class="tok-p">;</span>
1004
1005    <span class="tok-k">virtual</span> <span class="tok-kt">void</span> <span class="tok-nf">write</span><span class="tok-p">(</span><span class="tok-k">const</span> <span class="tok-kt">void</span><span class="tok-o">*</span> <span class="tok-n">data</span><span class="tok-p">,</span> <span class="tok-kt">size_t</span> <span class="tok-n">size</span><span class="tok-p">)</span>
1006    <span class="tok-p">{</span>
1007        <span class="tok-n">result</span><span class="tok-p">.</span><span class="tok-n">append</span><span class="tok-p">(</span><span class="tok-k">static_cast</span><span class="tok-o">&lt;</span><span class="tok-k">const</span> <span class="tok-kt">char</span><span class="tok-o">*&gt;</span><span class="tok-p">(</span><span class="tok-n">data</span><span class="tok-p">),</span> <span class="tok-n">size</span><span class="tok-p">);</span>
1008    <span class="tok-p">}</span>
1009<span class="tok-p">};</span></code></pre>
1010</div>
1011</div>
1012<div class="paragraph">
1013<p>While the previously described functions save the whole document to the destination, it is easy to save a single subtree. Instead of calling <code>xml_document::save</code>, just call <code>xml_node::print</code> function on the target node. You can save node contents to C&#43;&#43; IOstream object or custom writer in this way. Saving a subtree slightly differs from saving the whole document; <a href="manual/saving.html#saving.subtree">read the manual</a> for more information.</p>
1014</div>
1015</div>
1016</div>
1017<div class="sect1">
1018<h2 id="feedback"><a class="anchor" href="#feedback"></a><a class="link" href="#feedback">Feedback</a></h2>
1019<div class="sectionbody">
1020<div class="paragraph">
1021<p>If you believe you&#8217;ve found a bug in pugixml, please file an issue via <a href="https://github.com/zeux/pugixml/issues/new">issue submission form</a>. Be sure to include the relevant information so that the bug can be reproduced: the version of pugixml, compiler version and target architecture, the code that uses pugixml and exhibits the bug, etc. Feature requests and contributions can be filed as issues, too.</p>
1022</div>
1023<div class="paragraph">
1024<p>If filing an issue is not possible due to privacy or other concerns, you can contact pugixml author by e-mail directly: <a href="mailto:arseny.kapoulkine@gmail.com">arseny.kapoulkine@gmail.com</a>.</p>
1025</div>
1026</div>
1027</div>
1028<div class="sect1">
1029<h2 id="license"><a class="anchor" href="#license"></a><a class="link" href="#license">License</a></h2>
1030<div class="sectionbody">
1031<div class="paragraph">
1032<p>The pugixml library is distributed under the MIT license:</p>
1033</div>
1034<div class="literalblock">
1035<div class="content">
1036<pre>Copyright (c) 2006-2016 Arseny Kapoulkine
1037
1038Permission is hereby granted, free of charge, to any person
1039obtaining a copy of this software and associated documentation
1040files (the "Software"), to deal in the Software without
1041restriction, including without limitation the rights to use,
1042copy, modify, merge, publish, distribute, sublicense, and/or sell
1043copies of the Software, and to permit persons to whom the
1044Software is furnished to do so, subject to the following
1045conditions:
1046
1047The above copyright notice and this permission notice shall be
1048included in all copies or substantial portions of the Software.
1049
1050THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1051EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
1052OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1053NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
1054HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
1055WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1056FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1057OTHER DEALINGS IN THE SOFTWARE.</pre>
1058</div>
1059</div>
1060<div class="paragraph">
1061<p>This means that you can freely use pugixml in your applications, both open-source and proprietary. If you use pugixml in a product, it is sufficient to add an acknowledgment like this to the product distribution:</p>
1062</div>
1063<div class="literalblock">
1064<div class="content">
1065<pre>This software is based on pugixml library (http://pugixml.org).
1066pugixml is Copyright (C) 2006-2016 Arseny Kapoulkine.</pre>
1067</div>
1068</div>
1069</div>
1070</div>
1071</div>
1072<div id="footnotes">
1073<hr>
1074<div class="footnote" id="_footnote_1">
1075<a href="#_footnoteref_1">1</a>. All trademarks used are properties of their respective owners.
1076</div>
1077</div>
1078<div id="footer">
1079<div id="footer-text">
1080Last updated 2016-11-24 00:29:22 STD
1081</div>
1082</div>
1083</body>
1084</html>
Note: See TracBrowser for help on using the repository browser.