From 2094a4fd3da85c1972f215cb5977f6157590ff79 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Fri, 28 Feb 2014 06:01:16 +0000 Subject: docs: Regenerate HTML documentation git-svn-id: https://pugixml.googlecode.com/svn/trunk@993 99668b35-9821-0410-8761-19e4c4f06640 --- docs/manual.html | 44 +++--- docs/manual/access.html | 327 ++++++++++++++++++++++-------------------- docs/manual/apiref.html | 240 +++++++++++++++---------------- docs/manual/changes.html | 194 ++++++++++++++++++------- docs/manual/dom.html | 220 ++++++++++++++-------------- docs/manual/install.html | 123 +++++++++------- docs/manual/loading.html | 313 +++++++++++++++++++++------------------- docs/manual/modify.html | 274 ++++++++++++++++++++++------------- docs/manual/saving.html | 226 +++++++++++++++-------------- docs/manual/toc.html | 160 ++++++++++----------- docs/manual/xpath.html | 362 +++++++++++++++++++++++++---------------------- docs/quickstart.html | 180 +++++++++++------------ 12 files changed, 1441 insertions(+), 1222 deletions(-) diff --git a/docs/manual.html b/docs/manual.html index 8f3089b..016927f 100644 --- a/docs/manual.html +++ b/docs/manual.html @@ -1,16 +1,16 @@ -pugixml 1.2 +pugixml 1.4 - - + +
-pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: @@ -24,17 +24,17 @@

No documentation is perfect, neither is this one. If you encounter a description - that is unclear, please file an issue as described in Feedback. + that is unclear, please file an issue as described in Feedback. Also if you can spare the time for a full proof-reading, including spelling and grammar, that would be great! Please send me an e-mail; as a token of appreciation, your name will be included @@ -80,7 +80,7 @@

If you believe you've found a bug in pugixml (bugs include compilation problems @@ -107,14 +107,14 @@ Your contribution has to be distributed under the terms of a license that's compatible with pugixml license; i.e. GPL/LGPL licensed code is not accepted.

-

- If filing an issue is not possible due to privacy or other concerns, you - can contact pugixml author by e-mail directly: arseny.kapoulkine@gmail.com. +

+ If filing an issue is not possible due to privacy or + other concerns, you can contact pugixml author by e-mail directly: arseny.kapoulkine@gmail.com.

pugixml could not be developed without the help from many people; some of @@ -140,14 +140,14 @@

The pugixml library is distributed under the MIT license:

- Copyright (c) 2006-2012 Arseny Kapoulkine + Copyright (c) 2006-2014 Arseny Kapoulkine

Permission is hereby granted, free of charge, to any person obtaining a @@ -179,18 +179,18 @@

This software is based on pugixml library (http://pugixml.org).
pugixml - is Copyright (C) 2006-2012 Arseny Kapoulkine. + is Copyright (C) 2006-2014 Arseny Kapoulkine.

- +

Last revised: April 30, 2012 at 15:36:33 GMT

Last revised: February 28, 2014 at 03:52:52 GMT


-pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: diff --git a/docs/manual/access.html b/docs/manual/access.html index c6abd05..4d4e9c2 100644 --- a/docs/manual/access.html +++ b/docs/manual/access.html @@ -3,16 +3,16 @@ Accessing document data - - - + + +
-pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: @@ -28,27 +28,27 @@
-
-
Basic traversal functions
-
Getting node data
-
Getting attribute data
-
Contents-based traversal functions
-
Range-based for-loop support
-
Traversing node/attribute lists +

pugixml features an extensive interface for getting various types of data from the document and for traversing the document. This section provides documentation for all such functions that do not modify the tree except for XPath-related - functions; see XPath for XPath reference. As discussed in C++ interface, + functions; see XPath for XPath reference. As discussed in C++ interface, there are two types of handles to tree data - xml_node and xml_attribute. The handles have special null (empty) values which propagate through various functions and thus are @@ -58,11 +58,12 @@

-

- The internal representation of the document is a tree, where each node has - a list of child nodes (the order of children corresponds to their order in +

+ The + internal representation of the document is a tree, where each node has a + list of child nodes (the order of children corresponds to their order in the XML representation), and additionally element nodes have a list of attributes, which is also ordered. Several functions are provided in order to let you get from one node in the tree to the other. These functions roughly correspond @@ -123,7 +124,6 @@ all attributes like this (samples/traverse_base.cpp):

-

for (pugi::xml_node tool = tools.first_child(); tool; tool = tool.next_sibling())
 {
@@ -142,15 +142,15 @@
 
-

- Apart from structural information (parent, child nodes, attributes), nodes - can have name and value, both of which are strings. Depending on node type, - name or value may be absent. node_document - nodes do not have a name or value, node_element - and node_declaration nodes always - have a name but never have a value, node_pcdata, +

+ Apart from structural + information (parent, child nodes, attributes), nodes can have name and value, + both of which are strings. Depending on node type, name or value may be absent. + node_document nodes do not have a name + or value, node_element and node_declaration + nodes always have a name but never have a value, node_pcdata, node_cdata, node_comment and node_doctype nodes never have a name but always have a value (it may be empty though), node_pi @@ -164,8 +164,9 @@ In case node does not have a name or value or if the node handle is null, both functions return empty strings - they never return null pointers.

-

- It is common to store data as text contents of some node - i.e. <node><description>This is a node</description></node>. +

+ It is common to store data as text contents + of some node - i.e. <node><description>This is a node</description></node>. In this case, <description> node does not have a value, but instead has a child of type node_pcdata with value "This is a node". pugixml @@ -188,7 +189,7 @@ text() returns a special object that can be used for working with PCDATA contents in more complex cases than just retrieving the value; it is described in - Working with text contents sections. + Working with text contents sections.

There is an example of using some of these functions at @@ -197,11 +198,12 @@

-

- All attributes have name and value, both of which are strings (value may - be empty). There are two corresponding accessors, like for xml_node: +

+ All + attributes have name and value, both of which are strings (value may be empty). + There are two corresponding accessors, like for xml_node:

const char_t* xml_attribute::name() const;
 const char_t* xml_attribute::value() const;
@@ -210,12 +212,12 @@
         In case the attribute handle is null, both functions return empty strings
         - they never return null pointers.
       

-

- If you need a non-empty string if the attribute handle is null (for example, - you need to get the option value from XML attribute, but if it is not specified, - you need it to default to "sorted" - instead of ""), you - can use as_string accessor: +

+ If you need a non-empty string if + the attribute handle is null (for example, you need to get the option value + from XML attribute, but if it is not specified, you need it to default to + "sorted" instead of + ""), you can use as_string accessor:

const char_t* xml_attribute::as_string(const char_t* def = "") const;
 
@@ -224,29 +226,36 @@ the attribute handle is null. If you do not specify the argument, the function is equivalent to value().

-

- 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: +

+ 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:

int xml_attribute::as_int(int def = 0) const;
 unsigned int xml_attribute::as_uint(unsigned int def = 0) const;
 double xml_attribute::as_double(double def = 0) const;
 float xml_attribute::as_float(float def = 0) const;
 bool xml_attribute::as_bool(bool def = false) const;
+long long xml_attribute::as_llong(long long def = 0) const;
+unsigned long long xml_attribute::as_ullong(unsigned long long def = 0) const;
 

as_int, as_uint, + as_llong, as_ullong, as_double and as_float convert attribute values to numbers. If attribute handle is null or attribute value is empty, def argument is returned (which is 0 by default). Otherwise, all leading whitespace - characters are truncated, and the remaining string is parsed as a decimal - number (as_int or as_uint) or as a floating point number - in either decimal or scientific form (as_double - or as_float). Any extra characters - are silently discarded, i.e. as_int - will return 1 for string "1abc". + characters are truncated, and the remaining string is parsed as an integer + number in either decimal or hexadecimal form (applicable to as_int, as_uint, + as_llong and as_ullong; hexadecimal format is used if + the number has 0x + or 0X + prefix) or as a floating point number in either decimal or scientific form + (as_double or as_float). Any extra characters are silently + discarded, i.e. as_int will + return 1 for string "1abc".

In case the input string contains a number that is out of the target numeric @@ -282,17 +291,16 @@

Note

- There are no portable 64-bit types in C++, so there is no corresponding - conversion function. If your platform has a 64-bit integer, you can easily - write a conversion function yourself. + as_llong and as_ullong are only available if your + platform has reliable support for the long + long type, including string conversions.

-

- This is an example of using these functions, along with node data retrieval - ones (samples/traverse_base.cpp): +

+ This is an example of using these functions, + along with node data retrieval ones (samples/traverse_base.cpp):

-

for (pugi::xml_node tool = tools.child("Tool"); tool; tool = tool.next_sibling("Tool"))
 {
@@ -307,11 +315,12 @@
 
 
-

- Since a lot of document traversal consists of finding the node/attribute - with the correct name, there are special functions for that purpose: +

+ Since a lot of document traversal consists + of finding the node/attribute with the correct name, there are special functions + for that purpose:

xml_node xml_node::child(const char_t* name) const;
 xml_attribute xml_node::attribute(const char_t* name) const;
@@ -333,11 +342,15 @@
       

for (pugi::xml_node tool = tools.child("Tool"); tool; tool = tool.next_sibling("Tool"))
 
-

- Occasionally the needed node is specified not by the unique name but instead - by the value of some attribute; for example, it is common to have node collections - with each node having a unique id: <group><item id="1"/> <item id="2"/></group>. There are two functions for finding - child nodes based on the attribute values: +

+ Occasionally the needed node + is specified not by the unique name but instead by the value of some attribute; + for example, it is common to have node collections with each node having + a unique id: <group><item + id="1"/> + <item + id="2"/></group>. + There are two functions for finding child nodes based on the attribute values:

xml_node xml_node::find_child_by_attribute(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
 xml_node xml_node::find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const;
@@ -357,7 +370,6 @@
         This is an example of using these functions (samples/traverse_base.cpp):
       

-

std::cout << "Tool for *.dae generation: " << tools.find_child_by_attribute("Tool", "OutputFileMasks", "*.dae").attribute("Filename").value() << "\n";
 
@@ -371,12 +383,13 @@
 
-

- If your C++ compiler supports range-based for-loop (this is a C++11 feature, - at the time of writing it's supported by Microsoft Visual Studio 11 Beta, - GCC 4.6 and Clang 3.0), you can use it to enumerate nodes/attributes. Additional +

+ If your + C++ compiler supports range-based for-loop (this is a C++11 feature, at the + time of writing it'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 Boost Foreach, and possibly other pre-C++11 foreach facilities. @@ -397,7 +410,6 @@ This is an example of using these functions (samples/traverse_rangefor.cpp):

-

for (pugi::xml_node tool: tools.children("Tool"))
 {
@@ -421,12 +433,12 @@
 
-

- Child node lists and attribute lists are simply double-linked lists; while - you can use previous_sibling/next_sibling and other such functions for +

+ Child node lists and attribute lists are simply + double-linked lists; while you can use previous_sibling/next_sibling 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:

@@ -474,7 +486,6 @@ Here is an example of using iterators for document traversal (samples/traverse_iter.cpp):

-

for (pugi::xml_node_iterator it = tools.begin(); it != tools.end(); ++it)
 {
@@ -507,14 +518,14 @@
 
-

- The methods described above allow traversal of immediate children of some - node; if you want to do a deep tree traversal, you'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 xml_tree_walker +

+ The methods described above allow traversal + of immediate children of some node; if you want to do a deep tree traversal, + you'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 xml_tree_walker interface and to call traverse function:

@@ -530,11 +541,12 @@ bool xml_node::traverse(xml_tree_walker& walker);
-

- The traversal is launched by calling traverse +

+ The traversal + is launched by calling traverse function on traversal root and proceeds as follows:

-
    +
    • First, begin function is called with traversal root as its argument. @@ -558,10 +570,10 @@ begin or end functions; their default implementations return true.

      -

      - You can get the node's depth relative to the traversal root at any point - by calling depth function. - It returns -1 +

      + You can get the node's depth relative + to the traversal root at any point by calling depth + function. It returns -1 if called from begin/end, and returns 0-based depth if called from for_each - depth is 0 for all children of the traversal root, 1 for all grandchildren and so @@ -571,24 +583,22 @@ This is an example of traversing tree hierarchy with xml_tree_walker (samples/traverse_walker.cpp):

      -

      struct simple_walker: pugi::xml_tree_walker
       {
           virtual bool for_each(pugi::xml_node& node)
           {
      -        for (int i = 0; i < depth(); ++i) std::cout << "  "; // indentation
      -
      +        for (int i = 0; i < depth(); ++i) std::cout << "  "; // indentation
      +
               std::cout << node_types[node.type()] << ": name='" << node.name() << "', value='" << node.value() << "'\n";
       
      -        return true; // continue traversal
      -    }
      +        return true; // continue traversal
      +    }
       };
       

      -

      simple_walker walker;
       doc.traverse(walker);
      @@ -598,15 +608,15 @@
       
    -

    - While there are existing functions for getting a node/attribute with known - contents, they are often not sufficient for simple queries. As an alternative - for manual iteration through nodes/attributes until the needed one is found, - you can make a predicate and call one of find_ - functions: +

    + While there are existing functions for getting + a node/attribute with known contents, they are often not sufficient for simple + queries. As an alternative for manual iteration through nodes/attributes + until the needed one is found, you can make a predicate and call one of + find_ functions:

    template <typename Predicate> xml_attribute xml_node::find_attribute(Predicate pred) const;
     template <typename Predicate> xml_node xml_node::find_child(Predicate pred) const;
    @@ -648,7 +658,6 @@
             This is an example of using predicate-based functions (samples/traverse_predicate.cpp):
           

    -

    bool small_timeout(pugi::xml_node node)
     {
    @@ -671,29 +680,29 @@
     

    -

    -
    // Find child via predicate (looks for direct children only)
    -std::cout << tools.find_child(allow_remote_predicate()).attribute("Filename").value() << std::endl;
    +
    // Find child via predicate (looks for direct children only)
    +std::cout << tools.find_child(allow_remote_predicate()).attribute("Filename").value() << std::endl;
     
    -// Find node via predicate (looks for all descendants in depth-first order)
    -std::cout << doc.find_node(allow_remote_predicate()).attribute("Filename").value() << std::endl;
    +// Find node via predicate (looks for all descendants in depth-first order)
    +std::cout << doc.find_node(allow_remote_predicate()).attribute("Filename").value() << std::endl;
     
    -// Find attribute via predicate
    -std::cout << tools.last_child().find_attribute(allow_remote_predicate()).value() << std::endl;
    +// Find attribute via predicate
    +std::cout << tools.last_child().find_attribute(allow_remote_predicate()).value() << std::endl;
     
    -// We can use simple functions instead of function objects
    -std::cout << tools.find_child(small_timeout).attribute("Filename").value() << std::endl;
    +// We can use simple functions instead of function objects
    +std::cout << tools.find_child(small_timeout).attribute("Filename").value() << std::endl;
     

    -

    - It is common to store data as text contents of some node - i.e. <node><description>This is a node</description></node>. +

    + It is common to store data as text contents of some + node - i.e. <node><description>This is a node</description></node>. In this case, <description> node does not have a value, but instead has a child of type node_pcdata with value "This is a node". pugixml @@ -702,8 +711,10 @@ in the documentation for modifying document data; this section describes the access interface of xml_text.

    -

    - You can get the text object from a node by using text() method: +

    + You can get the text object from a node by using + text() + method:

    xml_text xml_node::text() const;
     
    @@ -713,11 +724,11 @@ itself is used to return data; otherwise, a first child node of type node_pcdata or node_cdata is used.

    -

    - You can check if the text object is bound to a valid PCDATA/CDATA node by - using it as a boolean value, i.e. if - (text) { ... - } or if +

    + You + can check if the text object is bound to a valid PCDATA/CDATA node by using + it as a boolean value, i.e. if (text) + { ... } or if (!text) { ... }. Alternatively you can check it by using the empty() @@ -725,9 +736,9 @@

    bool xml_text::empty() const;
     
    -

    - Given a text object, you can get the contents (i.e. the value of PCDATA/CDATA - node) by using the following function: +

    + Given a text object, you can get the contents + (i.e. the value of PCDATA/CDATA node) by using the following function:

    const char_t* xml_text::get() const;
     
    @@ -735,10 +746,11 @@ In case text object is empty, the function returns an empty string - it never returns a null pointer.

    -

    - If you need a non-empty string if the text object is empty, or if the text - contents is actually a number or a boolean that is stored as a string, you - can use the following accessors: +

    + If + you need a non-empty string if the text object is empty, or if the text contents + is actually a number or a boolean that is stored as a string, you can use + the following accessors:

    const char_t* xml_text::as_string(const char_t* def = "") const;
     int xml_text::as_int(int def = 0) const;
    @@ -746,6 +758,8 @@
     double xml_text::as_double(double def = 0) const;
     float xml_text::as_float(float def = 0) const;
     bool xml_text::as_bool(bool def = false) const;
    +long long xml_text::as_llong(long long def = 0) const;
    +unsigned long long xml_text::as_ullong(unsigned long long def = 0) const;
     

    All of the above functions have the same semantics as similar xml_attribute members: they return the @@ -753,9 +767,9 @@ to a target type using the same rules and restrictions. You can refer to documentation for the attribute functions for details.

    -

    - xml_text is essentially a - helper class that operates on xml_node +

    + xml_text + is essentially a helper class that operates on xml_node values. It is bound to a node of type node_pcdata or node_cdata. You can use the following function to retrieve this node: @@ -773,7 +787,6 @@ object (samples/text.cpp):

    -

    std::cout << "Project name: " << project.child("name").text().get() << std::endl;
     std::cout << "Project version: " << project.child("version").text().as_double() << std::endl;
    @@ -785,11 +798,11 @@
     
    -

    - If you need to get the document root of some node, you can use the following - function: +

    + If you need to get the document root of some + node, you can use the following function:

    xml_node xml_node::root() const;
     
    @@ -798,10 +811,11 @@ which is the root node of the document the node belongs to (unless the node is null, in which case null node is returned).

    -

    - While pugixml supports complex XPath expressions, sometimes a simple path - handling facility is needed. There are two functions, for getting node path - and for converting path to a node: +

    + While + pugixml supports complex XPath expressions, sometimes a simple path handling + facility is needed. There are two functions, for getting node path and for + converting path to a node:

    string_t xml_node::path(char_t delimiter = '/') const;
     xml_node xml_node::first_element_by_path(const char_t* path, char_t delimiter = '/') const;
    @@ -846,12 +860,13 @@
               is defined.
             

-

- pugixml does not record row/column information for nodes upon parsing for - efficiency reasons. However, if the node has not changed in a significant - way since parsing (the name/value are not changed, and the node itself is - the original one, i.e. it was not deleted from the tree and re-added later), - it is possible to get the offset from the beginning of XML buffer: +

+ pugixml does not record row/column information + for nodes upon parsing for efficiency reasons. However, if the node has not + changed in a significant way since parsing (the name/value are not changed, + and the node itself is the original one, i.e. it was not deleted from the + tree and re-added later), it is possible to get the offset from the beginning + of XML buffer:

ptrdiff_t xml_node::offset_debug() const;
 
@@ -867,7 +882,7 @@ - @@ -875,7 +890,7 @@
-pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: diff --git a/docs/manual/apiref.html b/docs/manual/apiref.html index cf1a137..80e59e8 100644 --- a/docs/manual/apiref.html +++ b/docs/manual/apiref.html @@ -3,16 +3,16 @@ API Reference - - - + + +
-pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: @@ -28,7 +28,7 @@

This is the reference for all macros, types, enumerations, classes and functions @@ -38,7 +38,7 @@

Macros:

-
    +

    Types:

    -
      +
      • typedef configuration-defined type char_t; @@ -97,10 +100,10 @@

        Enumerations:

        -
          +
          • enum xml_node_type -
              +
            • enum xml_parse_status -
                +
              • enum xml_encoding -
                  +
                • enum xpath_value_type -
                    +
                    • xpath_type_none
                    • @@ -243,10 +249,10 @@

                      Constants:

                      -
                        +
                        • Formatting options bit flags: -
                            +
                          • Parsing options bit flags: -
                              +
                              • parse_cdata
                              • @@ -295,6 +300,9 @@
                              • parse_escapes
                              • +
                              • + parse_fragment +
                              • parse_full
                              • @@ -304,6 +312,9 @@
                              • parse_pi
                              • +
                              • + parse_trim_pcdata +
                              • parse_ws_pcdata
                              • @@ -322,20 +333,18 @@

                                Classes:

                                -
                                  +
                                  • class xml_attribute -
                                      +
                                    • class xml_node -
                                        +
                                        • xml_node();

                                          -
                                        • bool empty() const;
                                        • operator unspecified_bool_type() const;

                                          -
                                        • bool operator==(const xml_node& @@ -518,24 +549,20 @@ r) const;

                                          -
                                        • size_t hash_value() const;

                                          -
                                        • xml_node_type type() const;

                                          -
                                        • const char_t* name() const;
                                        • const char_t* value() const;

                                          -
                                        • xml_node parent() const; @@ -551,14 +578,12 @@
                                        • xml_node previous_sibling() const;

                                          -
                                        • xml_attribute first_attribute() const;
                                        • xml_attribute last_attribute() const;

                                          -
                                        • implementation-defined type children() const; @@ -570,7 +595,6 @@
                                        • implementation-defined type attributes() const;

                                          -
                                        • xml_node child(const char_t* @@ -602,7 +626,6 @@ xml_node find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const;

                                          -
                                        • const char_t* child_value() const; @@ -614,7 +637,6 @@
                                        • xml_text text() const;

                                          -
                                        • typedef xml_node_iterator @@ -625,7 +647,6 @@
                                        • iterator end() const;

                                          -
                                        • typedef xml_attribute_iterator @@ -636,11 +657,9 @@
                                        • attribute_iterator attributes_end() const;

                                          -
                                        • bool traverse(xml_tree_walker& walker);

                                          -
                                        • template <typename Predicate> xml_attribute @@ -660,7 +679,6 @@ pred) const;

                                          -
                                        • string_t path(char_t @@ -679,7 +697,6 @@
                                        • ptrdiff_t offset_debug() const;

                                          -
                                        • bool set_name(const char_t* @@ -689,7 +706,6 @@ bool set_value(const char_t* rhs);

                                          -
                                        • xml_attribute append_attribute(const char_t* @@ -708,7 +724,6 @@ xml_attribute insert_attribute_before(const char_t* name, const xml_attribute& attr);

                                          -
                                        • xml_node append_child(xml_node_type @@ -729,7 +744,6 @@ xml_node insert_child_before(xml_node_type type, const xml_node& node);

                                          -
                                        • xml_node append_child(const char_t* @@ -748,7 +762,6 @@ xml_node insert_child_before(const char_t* name, const xml_node& node);

                                          -
                                        • xml_attribute append_copy(const xml_attribute& proto); @@ -766,7 +779,6 @@ xml_attribute insert_copy_before(const xml_attribute& proto, const xml_attribute& attr);

                                          -
                                        • xml_node append_copy(const xml_node& @@ -785,7 +797,6 @@ xml_node insert_copy_before(const xml_node& proto, const xml_node& node);

                                          -
                                        • bool remove_attribute(const xml_attribute& @@ -803,7 +814,15 @@ bool remove_child(const char_t* name);

                                          - +
                                        • +
                                        • + xml_parse_result append_buffer(const void* contents, + size_t size, unsigned + int options + = parse_default, xml_encoding + encoding = + encoding_auto); +

                                        • void print(xml_writer& writer, const @@ -844,7 +863,6 @@ 0) const;

                                          -
                                        • xpath_node select_single_node(const char_t* @@ -872,19 +890,17 @@ query) const;

                                          -
                                      • class xml_document -
                                          +
                                          • xml_document();
                                          • ~xml_document();

                                            -
                                          • void reset(); @@ -893,7 +909,6 @@ void reset(const xml_document& proto);

                                            -
                                          • xml_parse_result load(std::istream& @@ -911,13 +926,11 @@ options = parse_default);

                                            -
                                          • xml_parse_result load(const char_t* contents, unsigned int options = parse_default);

                                            -
                                          • xml_parse_result load_file(const char* path, unsigned @@ -934,7 +947,6 @@ parse_default, xml_encoding encoding = encoding_auto);

                                            -
                                          • xml_parse_result load_buffer(const void* contents, @@ -961,7 +973,6 @@ parse_default, xml_encoding encoding = encoding_auto);

                                            -
                                          • bool save_file(const char* path, @@ -984,7 +995,6 @@ encoding_auto) const;

                                            -
                                          • void save(std::ostream& stream, const @@ -1007,7 +1017,6 @@ format_default) const;

                                            -
                                          • void save(xml_writer& writer, const @@ -1019,17 +1028,15 @@ format_default, xml_encoding encoding = encoding_auto) const;

                                            -
                                          • xml_node document_element() const;

                                            -
                                        • struct xml_parse_result -
                                            +
                                            @@ -1055,11 +1060,10 @@
                                          • class xml_attribute_iterator

                                            -
                                          • class xml_tree_walker -
                                              +
                                              • virtual bool begin(xml_node& node); @@ -1071,27 +1075,23 @@
                                              • virtual bool end(xml_node& node);

                                                -
                                              • int depth() const;

                                                -
                                            • class xml_text -
                                                +
                                                • bool empty() const;
                                                • operator xml_text::unspecified_bool_type() const;

                                                  -
                                                • const char_t* xml_text::get() const;

                                                  -
                                                • const char_t* as_string(const char_t* @@ -1125,14 +1125,25 @@ bool as_bool(bool def = false) const; +
                                                • +
                                                • + long long + as_llong(long long def + = 0) const; +
                                                • +
                                                • + unsigned long + long as_ullong(unsigned + long long + def = + 0) + const;

                                                  -
                                                • bool set(const char_t* rhs);

                                                  -
                                                • bool set(int rhs); @@ -1147,8 +1158,15 @@
                                                • bool set(bool rhs); +
                                                • +
                                                • + bool set(long long rhs); +
                                                • +
                                                • + bool set(unsigned + long long + rhs);

                                                  -
                                                • xml_text& @@ -1172,47 +1190,52 @@
                                                • xml_text& operator=(bool rhs); +
                                                • +
                                                • + xml_text& + operator=(long long rhs); +
                                                • +
                                                • + xml_text& + operator=(unsigned + long long + rhs);

                                                  -
                                                • xml_node data() const;

                                                  -
                                              • class xml_writer -
                                                • +
                                                  • virtual void write(const void* data, size_t size) = 0;

                                                    -
                                                • class xml_writer_file: public xml_writer -
                                                  • +
                                                  • class xml_writer_stream: public xml_writer -
                                                      +
                                                    • struct xpath_parse_result -
                                                        +
                                                      • class xpath_query -
                                                          +
                                                        • class xpath_exception: public std::exception -
                                                            +
                                                            • virtual const char* what() const throw();

                                                              -
                                                            • const xpath_parse_result& result() const;

                                                              -
                                                          • class xpath_node -
                                                              +
                                                              • xpath_node();
                                                              • @@ -1311,7 +1327,6 @@ xml_node& parent);

                                                                -
                                                              • xml_node node() const; @@ -1322,7 +1337,6 @@
                                                              • xml_node parent() const;

                                                                -
                                                              • operator unspecified_bool_type() const; @@ -1337,13 +1351,12 @@ n) const;

                                                                -
                                                            • class xpath_node_set -
                                                                +
                                                                • xpath_node_set();
                                                                • @@ -1354,7 +1367,6 @@ type = type_unsorted);

                                                                  -
                                                                • typedef const @@ -1369,7 +1381,6 @@ const_iterator end() const;

                                                                  -
                                                                • const xpath_node& operator[](size_t @@ -1381,13 +1392,11 @@
                                                                • bool empty() const;

                                                                  -
                                                                • xpath_node first() const;

                                                                  -
                                                                • enum type_t @@ -1402,13 +1411,12 @@ void sort(bool reverse = false);

                                                                  -
                                                              • class xpath_variable -
                                                                  +
                                                                  • const char_t* name() const;
                                                                  • @@ -1416,7 +1424,6 @@ xpath_value_type type() const;

                                                                    -
                                                                  • bool get_boolean() const; @@ -1429,7 +1436,6 @@
                                                                  • const xpath_node_set& get_node_set() const;

                                                                    -
                                                                  • bool set(bool value); @@ -1446,19 +1452,17 @@ bool set(const xpath_node_set& value);

                                                                    -
                                                                • class xpath_variable_set -
                                                                    +
                                                                    • xpath_variable* add(const char_t* name, xpath_value_type type);

                                                                      -
                                                                    • bool set(const char_t* @@ -1479,7 +1483,6 @@ bool set(const char_t* name, const xpath_node_set& value);

                                                                      -
                                                                    • xpath_variable* @@ -1491,7 +1494,6 @@ name) const;

                                                                      -
                                                                    @@ -1499,7 +1501,7 @@

                                                                    Functions:

                                                                    -
                                                                      +
                                                                      • std::string as_utf8(const wchar_t* str);
                                                                      • @@ -1529,7 +1531,7 @@
                                                                      - @@ -1537,7 +1539,7 @@
                                                                      -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: diff --git a/docs/manual/changes.html b/docs/manual/changes.html index d119532..48644a3 100644 --- a/docs/manual/changes.html +++ b/docs/manual/changes.html @@ -3,16 +3,16 @@ Changelog - - - + + +
                                                                      -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: @@ -28,18 +28,102 @@
                                                                      -
                                                                      - 1.05.2012 - version - 1.2 +
                                                                      + + 1.03.2014 + - version 1.4 +
                                                                      +

                                                                      + Major release, featuring various new features, bug fixes and compatibility + improvements. +

                                                                      +
                                                                        +
                                                                      • + Specification changes: +
                                                                        1. + Documents without element nodes are now rejected with status_no_document_element + error, unless parse_fragment option is used +
                                                                        +
                                                                      • +
                                                                      • + New features: +
                                                                          +
                                                                        1. + Added XML fragment parsing (parse_fragment flag) +
                                                                        2. +
                                                                        3. + Added PCDATA whitespace trimming (parse_trim_pcdata flag) +
                                                                        4. +
                                                                        5. + Added long long support for xml_attribute and xml_text (as_llong, + as_ullong and set_value/set overloads) +
                                                                        6. +
                                                                        7. + Added hexadecimal integer parsing support for as_int/as_uint/as_llong/as_ullong +
                                                                        8. +
                                                                        9. + Added xml_node::append_buffer to improve performance of assembling + documents from fragments +
                                                                        10. +
                                                                        11. + xml_named_node_iterator is now bidirectional +
                                                                        12. +
                                                                        13. + Reduced XPath stack consumption during compilation and evaluation + (useful for embedded systems) +
                                                                        14. +
                                                                        +
                                                                      • +
                                                                      • + Compatibility improvements: +
                                                                          +
                                                                        1. + Improved support for platforms without wchar_t support +
                                                                        2. +
                                                                        3. + Fixed several false positives in clang static analysis +
                                                                        4. +
                                                                        5. + Fixed several compilation warnings for various GCC versions +
                                                                        6. +
                                                                        +
                                                                      • +
                                                                      • + Bug fixes: +
                                                                          +
                                                                        1. + Fixed undefined pointer arithmetic in XPath implementation +
                                                                        2. +
                                                                        3. + Fixed non-seekable iostream support for certain stream types, i.e. + boost file_source with pipe input +
                                                                        4. +
                                                                        5. + Fixed xpath_query::return_type() for some expressions +
                                                                        6. +
                                                                        7. + Fixed dllexport issues with xml_named_node_iterator +
                                                                        8. +
                                                                        9. + Fixed find_child_by_attribute assertion for attributes with null + name/value +
                                                                        10. +
                                                                        +
                                                                      • +
                                                                      +
                                                                      + + 1.05.2012 + - version 1.2

                                                                      Major release, featuring header-only mode, various interface enhancements (i.e. PCDATA manipulation and C++11 iteration), many other features and compatibility improvements.

                                                                      -
                                                                        +
                                                                        • New features:
                                                                            @@ -124,15 +208,16 @@
                                                                        -
                                                                        - 1.11.2010 - version - 1.0 +
                                                                        + + 1.11.2010 + - version 1.0

                                                                        Major release, featuring many XPath enhancements, wide character filename support, miscellaneous performance improvements, bug fixes and more.

                                                                        -
                                                                          +
                                                                          • XPath:
                                                                              @@ -342,15 +427,16 @@
                                                                          -
                                                                          - 1.07.2010 - version - 0.9 +
                                                                          + + 1.07.2010 + - version 0.9

                                                                          Major release, featuring extended and improved Unicode support, miscellaneous performance improvements, bug fixes and more.

                                                                          -
                                                                            +
                                                                            • Major Unicode improvements:
                                                                                @@ -463,14 +549,15 @@
                                                                            -
                                                                            - 8.11.2009 - version - 0.5 +
                                                                            + + 8.11.2009 + - version 0.5

                                                                            Major bugfix release. Changes:

                                                                            -
                                                                              +
                                                                              • XPath bugfixes:
                                                                                  @@ -574,14 +661,15 @@
                                                                              -
                                                                              - 17.09.2009 - version - 0.42 +
                                                                              + + 17.09.2009 + - version 0.42

                                                                              Maintenance release. Changes:

                                                                              -
                                                                                +
                                                                                • Bug fixes:
                                                                                    @@ -619,28 +707,30 @@
                                                                                -
                                                                                - 8.02.2009 - version - 0.41 +
                                                                                + + 8.02.2009 + - version 0.41

                                                                                Maintenance release. Changes:

                                                                                -
                                                                                • +
                                                                                  • Bug fixes:
                                                                                    1. Fixed bug with node printing (occasionally some content was not written to output stream)
                                                                                  -
                                                                                  - 18.01.2009 - version - 0.4 +
                                                                                  + + 18.01.2009 + - version 0.4

                                                                                  Changes:

                                                                                  -
                                                                                    +
                                                                                    • Bug fixes:
                                                                                        @@ -711,14 +801,15 @@
                                                                                    -
                                                                                    - 31.10.2007 - version - 0.34 +
                                                                                    + + 31.10.2007 + - version 0.34

                                                                                    Maintenance release. Changes:

                                                                                    -
                                                                                      +
                                                                                      • Bug fixes:
                                                                                          @@ -749,14 +840,15 @@
                                                                                      -
                                                                                      - 21.02.2007 - version - 0.3 +
                                                                                      + + 21.02.2007 + - version 0.3

                                                                                      Refactored, reworked and improved version. Changes:

                                                                                      -
                                                                                        +
                                                                                        • Interface:
                                                                                            @@ -810,14 +902,15 @@
                                                                                        -
                                                                                        - 6.11.2006 - version - 0.2 +
                                                                                        + + 6.11.2006 + - version 0.2

                                                                                        First public release. Changes:

                                                                                        -
                                                                                        - @@ -862,7 +956,7 @@
                                                                                        -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: diff --git a/docs/manual/dom.html b/docs/manual/dom.html index 22d8d83..57d3ea0 100644 --- a/docs/manual/dom.html +++ b/docs/manual/dom.html @@ -3,16 +3,16 @@ Document object model - - - + + +
                                                                                        -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: @@ -28,20 +28,20 @@
                                                                                        -
                                                                                        -
                                                                                        Tree structure
                                                                                        -
                                                                                        C++ interface
                                                                                        -
                                                                                        Unicode interface
                                                                                        -
                                                                                        Thread-safety guarantees
                                                                                        -
                                                                                        Exception guarantees
                                                                                        -
                                                                                        Memory management
                                                                                        + @@ -56,7 +56,7 @@

                                                                                        The XML document is represented with a tree data structure. The root of the @@ -66,11 +66,11 @@ which correspond to C++ type xml_attribute, and some additional data (i.e. name).

                                                                                        -

                                                                                        - The tree nodes can be of one of the following types (which together form - the enumeration xml_node_type): +

                                                                                        + The tree nodes can be of one of the following + types (which together form the enumeration xml_node_type):

                                                                                        -
                                                                                          +
                                                                                          • Document node (node_document) - this is the root of the tree, which consists of several child nodes. This @@ -81,7 +81,6 @@ several ways, which are covered below. There can be only one document node in the tree; document node does not have any XML representation.

                                                                                            -
                                                                                          • Element/tag node (node_element) - this @@ -100,7 +99,7 @@ another has name "child" and does not have any attributes or child nodes.

                                                                                          -
                                                                                          • +
                                                                                            • Plain character data nodes (node_pcdata) represent plain text in XML. PCDATA nodes have a value, but do not have a name or children/attributes. Note that plain @@ -115,7 +114,7 @@ has three children, two of which are PCDATA nodes with values " text1 " and " text2 ".

                                                                                            -
                                                                                            • +
                                                                                              • Character data nodes (node_cdata) represent text in XML that is quoted in a special way. CDATA nodes do not differ from PCDATA nodes except in XML representation - the above text example @@ -128,7 +127,7 @@ in plain text. CDATA value can not contain the character sequence ]]>, since it is used to determine the end of node contents.

                                                                                              -
                                                                                              • +
                                                                                                • Comment nodes (node_comment) represent comments in XML. Comment nodes have a value, but do not have a name or children/attributes. The example XML representation of a comment node @@ -143,7 +142,7 @@ this behavior with parse_comments flag.

                                                                                                -
                                                                                                • +
                                                                                                  • Processing instruction node (node_pi) represent processing instructions (PI) in XML. PI nodes have a name and an optional value, but do not have children/attributes. The example XML representation @@ -158,7 +157,7 @@ are not loaded during XML parsing. You can override this behavior with parse_pi flag.

                                                                                                  -
                                                                                                  • +
                                                                                                    • Declaration node (node_declaration) represents document declarations in XML. Declaration nodes have a name ("xml") and an @@ -180,7 +179,7 @@ there is already a declaration in the document; you can disable this with format_no_declaration flag.

                                                                                                    -
                                                                                                    • +
                                                                                                      • Document type declaration node (node_doctype) represents document type declarations in XML. Document type declaration nodes have a value, which corresponds to the entire document type contents; @@ -189,7 +188,7 @@ (its parent should be the document). The example XML representation of a document type declaration node is as follows:
                                                                                                      -
                                                                                                      <!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)> ]>
                                                                                                      +
                                                                                                      <!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)> ]>
                                                                                                       

                                                                                                      Here the node has value "greeting [ <!ELEMENT @@ -209,7 +208,6 @@

                                                                                        -

                                                                                        <?xml version="1.0"?>
                                                                                         <mesh name="mesh_root">
                                                                                        @@ -237,7 +235,7 @@
                                                                                         
                                                                                         
                                                                                        @@ -261,21 +259,18 @@ some operations on xml_node are only valid for certain node types. The classes are described below.

                                                                                        -

                                                                                        - xml_document is the owner - of the entire document structure; it is a non-copyable class. The interface - of xml_document consists - of loading functions (see Loading document), saving functions (see Saving document) - and the entire interface of xml_node, - which allows for document inspection and/or modification. Note that while - xml_document is a sub-class - of xml_node, xml_node is not a polymorphic type; the - inheritance is present only to simplify usage. Alternatively you can use - the document_element function - to get the element node that's the immediate child of the document. +

                                                                                        + xml_document is the owner of the entire + document structure; it is a non-copyable class. The interface of xml_document consists of loading functions + (see Loading document), saving functions (see Saving document) and the entire + interface of xml_node, which + allows for document inspection and/or modification. Note that while xml_document is a sub-class of xml_node, xml_node + is not a polymorphic type; the inheritance is present only to simplify usage. + Alternatively you can use the document_element + function to get the element node that's the immediate child of the document.

                                                                                        -

                                                                                        - Default constructor of xml_document +

                                                                                        + Default constructor of xml_document initializes the document to the tree with only a root node (document node). You can then populate it with data using either tree modification functions or loading functions; all loading functions destroy the previous tree with @@ -300,12 +295,12 @@ are destroyed.

                                                                                        -

                                                                                        - xml_node is the handle to - document node; it can point to any node in the document, including the document - node itself. There is a common interface for nodes of all types; the actual - node type can be queried via the xml_node::type() - method. Note that xml_node +

                                                                                        + xml_node + is the handle to document node; it can point to any node in the document, + including the document node itself. There is a common interface for nodes + of all types; the actual node type can + be queried via the xml_node::type() method. Note that xml_node is only a handle to the actual node, not the node itself - you can have several xml_node handles pointing to the same underlying object. Destroying xml_node @@ -315,8 +310,8 @@ a pointer; you can safely pass or return xml_node objects by value without additional overhead.

                                                                                        -

                                                                                        - There is a special value of xml_node +

                                                                                        + There is a special value of xml_node type, known as null node or empty node (such nodes have type node_null). 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't do anything and @@ -326,37 +321,40 @@ have a parent, the first parent() call returns null node; the second parent() call then also returns null node, which makes error handling easier.

                                                                                        -

                                                                                        - xml_attribute is the handle - to an XML attribute; it has the same semantics as xml_node, - i.e. there can be several xml_attribute - handles pointing to the same underlying object and there is a special null - attribute value, which propagates to function results. +

                                                                                        + xml_attribute + is the handle to an XML attribute; it has the same semantics as xml_node, i.e. there can be several xml_attribute handles pointing to the same + underlying object and there is a special null attribute value, which propagates + to function results.

                                                                                        -

                                                                                        - Both xml_node and xml_attribute have the default constructor - which initializes them to null objects. +

                                                                                        + Both xml_node and xml_attribute + have the default constructor which initializes them to null objects.

                                                                                        -

                                                                                        - xml_node and xml_attribute try to behave like pointers, - that is, they can be compared with other objects of the same type, making - it possible to use them as keys in associative containers. All handles to - the same underlying object are equal, and any two handles to different underlying - objects are not equal. Null handles only compare as equal to themselves. - The result of relational comparison can not be reliably determined from the - order of nodes in file or in any other way. Do not use relational comparison - operators except for search optimization (i.e. associative container keys). +

                                                                                        + xml_node and xml_attribute + try to behave like pointers, that is, they can be compared with other objects + of the same type, making it possible to use them as keys in associative containers. + All handles to the same underlying object are equal, and any two handles + to different underlying objects are not equal. Null handles only compare + as equal to themselves. The result of relational comparison can not be reliably + determined from the order of nodes in file or in any other way. Do not use + relational comparison operators except for search optimization (i.e. associative + container keys).

                                                                                        -

                                                                                        - If you want to use xml_node +

                                                                                        + If + you want to use xml_node or xml_attribute objects as keys in hash-based associative containers, you can use the hash_value member functions. They return the hash values that are guaranteed to be the same for all handles to the same underlying object. The hash value for null handles is 0.

                                                                                        -

                                                                                        - Finally handles can be implicitly cast to boolean-like objects, so that you - can test if the node/attribute is empty with the following code: if (node) { ... +

                                                                                        + Finally handles + can be implicitly cast to boolean-like objects, so that you can test if the + node/attribute is empty with the following code: if + (node) { ... } or if (!node) { ... } else { ... }. @@ -379,14 +377,14 @@

                                                                                        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 PUGIXML_WCHAR_MODE define; you can set it via pugiconfig.hpp or via preprocessor options, as - discussed in Additional configuration + discussed in Additional configuration options. If this define is set, the wchar_t interface is used; otherwise (by default) the char interface is used. The exact wide character encoding is assumed to be either UTF-16 or UTF-32 and @@ -418,13 +416,13 @@

                                                                                        const wchar_t* xml_node::name() const;
                                                                                         bool xml_node::set_name(const wchar_t* value);
                                                                                         
                                                                                        -

                                                                                        - There is a special type, pugi::char_t, - that is defined as the character type and depends on the library configuration; - it will be also used in the documentation hereafter. There is also a type - pugi::string_t, which is defined as the STL string - of the character type; it corresponds to std::string - in char mode and to std::wstring in wchar_t mode. +

                                                                                        + There is a special type, pugi::char_t, that is defined as the character + type and depends on the library configuration; it will be also used in the + documentation hereafter. There is also a type pugi::string_t, + which is defined as the STL string of the character type; it corresponds + to std::string in char mode and to std::wstring + in wchar_t mode.

                                                                                        In addition to the interface, the internal implementation changes to store @@ -436,9 +434,10 @@ inconvenient to process and most of your XML data is non-ASCII, wchar_t mode is probably a better choice.

                                                                                        -

                                                                                        - There are cases when you'll have to convert string data between UTF-8 and - wchar_t encodings; the following helper functions are provided for such purposes: +

                                                                                        + There are cases when you'll have + to convert string data between UTF-8 and wchar_t encodings; the following + helper functions are provided for such purposes:

                                                                                        std::string as_utf8(const wchar_t* str);
                                                                                         std::wstring as_wide(const char* str);
                                                                                        @@ -485,12 +484,12 @@
                                                                                         

                                                                                        Almost all functions in pugixml have the following thread-safety guarantees:

                                                                                        -
                                                                                          +

                                                                                          With the exception of XPath, pugixml itself does not throw any exceptions. @@ -541,7 +540,7 @@

                                                                                          pugixml requests the memory needed for document storage in big chunks, and @@ -550,21 +549,22 @@

                                                                                          -

                                                                                          - All memory for tree structure, tree data and XPath objects is allocated - via globally specified functions, which default to malloc/free. You can - set your own allocation functions with set_memory_management function. - The function interfaces are the same as that of malloc/free: +

                                                                                          + All + memory for tree structure, tree data and XPath objects is allocated via + globally specified functions, which default to malloc/free. You can set + your own allocation functions with set_memory_management function. The + function interfaces are the same as that of malloc/free:

                                                                                          typedef void* (*allocation_function)(size_t size);
                                                                                           typedef void (*deallocation_function)(void* ptr);
                                                                                           
                                                                                          -

                                                                                          - You can use the following accessor functions to change or get current memory - management functions: +

                                                                                          + You can use the following accessor + functions to change or get current memory management functions:

                                                                                          void set_memory_management_functions(allocation_function allocate, deallocation_function deallocate);
                                                                                           allocation_function get_memory_allocation_function();
                                                                                          @@ -589,7 +589,6 @@
                                                                                                     This is a simple example of custom memory management (samples/custom_memory_management.cpp):
                                                                                                   

                                                                                          -

                                                                                          void* custom_allocate(size_t size)
                                                                                           {
                                                                                          @@ -604,7 +603,6 @@
                                                                                           

                                                                                          -

                                                                                          pugi::set_memory_management_functions(custom_allocate, custom_deallocate);
                                                                                           
                                                                                          @@ -619,7 +617,7 @@

                                                                                          There are several important buffering optimizations in pugixml that rely @@ -631,10 +629,10 @@

                                                                                          These constants can be tuned via configuration defines, as discussed in - Additional configuration + Additional configuration options; it is recommended to set them in pugiconfig.hpp.

                                                                                          -
                                                                                            +
                                                                                            • PUGIXML_MEMORY_PAGE_SIZE controls the page size for document memory allocation. Memory for node/attribute @@ -642,7 +640,6 @@ is 32 Kb; for some applications the size is too large (i.e. embedded systems with little heap space or applications that keep lots of XML documents in memory). A minimum size of 1 Kb is recommended.

                                                                                              -
                                                                                            • PUGIXML_MEMORY_OUTPUT_STACK @@ -652,7 +649,6 @@ using node output from threads with little stack space, decreasing this value can prevent stack overflows. A minimum size of 1 Kb is recommended.

                                                                                              -
                                                                                            • PUGIXML_MEMORY_XPATH_PAGE_SIZE @@ -667,7 +663,7 @@

                                                                                            @@ -677,7 +673,7 @@

                                                                                            When the document is loaded from file/buffer, unless an inplace loading - function is used (see Loading document from memory), a complete copy of character + function is used (see Loading document from memory), a complete copy of character stream is made; all names/values of nodes and attributes are allocated in this buffer. This buffer is allocated via a single large allocation and is only freed when document memory is reclaimed (i.e. if the xml_document object is destroyed or if another @@ -707,7 +703,7 @@

                                                                                            - @@ -715,7 +711,7 @@
                                                                                            -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: diff --git a/docs/manual/install.html b/docs/manual/install.html index df7b322..5675651 100644 --- a/docs/manual/install.html +++ b/docs/manual/install.html @@ -3,16 +3,16 @@ Installation - - - - + + + +
                                                                                            -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: @@ -28,32 +28,33 @@
                                                                                            -
                                                                                            -
                                                                                            Getting pugixml
                                                                                            +

                                                                                            pugixml is distributed in source form. You can either download a source distribution @@ -61,14 +62,14 @@

                                                                                            The Subversion repository is located at http://pugixml.googlecode.com/svn/. @@ -96,7 +97,7 @@

                                                                                            For example, to checkout the current version, you can use this command:

                                                                                            -
                                                                                            svn checkout http://pugixml.googlecode.com/svn/tags/release-1.2 pugixml
                                                                                            +
                                                                                            svn checkout http://pugixml.googlecode.com/svn/tags/release-1.4 pugixml

                                                                                            To checkout the latest version, you can use this command:

                                                                                            @@ -115,10 +116,20 @@ that occasionally the code can be broken in some configurations.

                                                                                            +
                                                                                            + +

                                                                                            + The Subversion repository is mirrored by a Git repository at https://github.com/zeux/pugixml. + The mirror is frequently updated and has the same structure in terms of + tags and contents as Subversion repository. +

                                                                                            +

                                                                                            pugixml is distributed in source form without any pre-built binaries; you @@ -128,7 +139,7 @@ The complete pugixml source consists of three files - one source file, pugixml.cpp, and two header files, pugixml.hpp and pugiconfig.hpp. pugixml.hpp is the primary header which you need to include in order to use pugixml classes/functions; - pugiconfig.hpp is a supplementary configuration file (see Additional configuration + pugiconfig.hpp is a supplementary configuration file (see Additional configuration options). The rest of this guide assumes that pugixml.hpp is either in the current directory or in one of include directories of your projects, so that #include "pugixml.hpp" @@ -138,14 +149,14 @@

                                                                                            The easiest way to build pugixml is to compile the source file, pugixml.cpp, along with the existing library/executable. This process depends on the method of building your application; for example, if you're using Microsoft - Visual Studio[1], Apple Xcode, Code::Blocks or any other IDE, just add pugixml.cpp to + Visual Studio[1], Apple Xcode, Code::Blocks or any other IDE, just add pugixml.cpp to one of your projects.

                                                                                            @@ -173,7 +184,7 @@

                                                                                            @@ -183,7 +194,7 @@ are project files for Apple XCode3, Code::Blocks, Codelite, Microsoft Visual Studio 2005, 2008, 2010, and configuration scripts for CMake and premake4. You're welcome to submit project files/build scripts for other software; - see Feedback. + see Feedback.

                                                                                            There are two projects for each version of Microsoft Visual Studio: one @@ -236,7 +247,7 @@

                                                                                            -
                                                                                            +

                                                                                            It's possible to use pugixml in header-only mode. This means that all source @@ -313,7 +324,7 @@

                                                                                            Note that it is safe to compile pugixml.cpp if PUGIXML_HEADER_ONLY is defined - so if you want to i.e. use header-only mode only in Release - configuration, you can include pugixml.cpp in your project (see Building pugixml as + configuration, you can include pugixml.cpp in your project (see Building pugixml as a part of another static library/executable), and conditionally enable header-only mode in pugiconfig.hpp, i.e.:

                                                                                            @@ -325,7 +336,7 @@

                                                                                            @@ -347,7 +358,7 @@ as character type) and UTF-16/32 style interface (the in-memory text encoding is assumed to be UTF-16/32, depending on wchar_t size, most functions use wchar_t - as character type). See Unicode interface for more details. + as character type). See Unicode interface for more details.

                                                                                            PUGIXML_NO_XPATH define disables XPath. @@ -377,7 +388,7 @@ is used instead. For example, to specify fixed calling convention, you can define PUGIXML_FUNCTION to i.e. __fastcall. Another - example is DLL import/export attributes in MSVC (see Building pugixml as + example is DLL import/export attributes in MSVC (see Building pugixml as a standalone shared library).

                                                                                            @@ -395,24 +406,34 @@ PUGIXML_MEMORY_PAGE_SIZE, PUGIXML_MEMORY_OUTPUT_STACK and PUGIXML_MEMORY_XPATH_PAGE_SIZE can be used to customize certain important sizes to optimize memory usage - for the application-specific patterns. For details see Memory consumption tuning. + for the application-specific patterns. For details see Memory consumption tuning. +

                                                                                            +

                                                                                            + PUGIXML_HAS_LONG_LONG define enables + support for long long + type in pugixml. This define is automatically enabled if your platform + is known to have long long + support (i.e. has C++-11 support or uses a reasonably modern version of + a known compiler); if pugixml does not recognize that your platform supports + long long + but in fact it does, you can enable the define manually.

                                                                                            pugixml is written in standard-compliant C++ with some compiler-specific - workarounds where appropriate. pugixml is compatible with the upcoming C++0x - standard (verified using GCC 4.5). Each version is tested with a unit test + workarounds where appropriate. pugixml is compatible with the C++11 standard, + but does not require C++11 support. Each version is tested with a unit test suite (with code coverage about 99%) on the following platforms:

                                                                                            -
                                                                                              +
                                                                                              • Microsoft Windows: -
                                                                                                  +
                                                                                                  • Borland C++ Compiler 5.82
                                                                                                  • @@ -427,8 +448,8 @@
                                                                                                  • Microsoft Visual C++ 6.0, 7.0 (2002), 7.1 (2003), 8.0 (2005) x86/x64, - 9.0 (2008) x86/x64, 10.0 (2010) x86/x64, 11.0 x86/x64/ARM and some - CLR versions + 9.0 (2008) x86/x64, 10.0 (2010) x86/x64, 11.0 (2011) x86/x64/ARM, + 12.0 (2013) x86/x64/ARM and some CLR versions
                                                                                                  • MinGW (GCC) 3.4, 4.4, 4.5, 4.6 x64 @@ -436,7 +457,7 @@
                                                                                                • - Linux (GCC 4.4.3 x86/x64) + Linux (GCC 4.4.3 x86/x64, GCC 4.8.1 x64, Clang 3.2 x64)
                                                                                                • FreeBSD (GCC 4.2.1 x86/x64) @@ -466,14 +487,14 @@
                                                                                              -

                                                                                              -

                                                                                              [1] All trademarks used are properties of their respective +


                                                                                              +

                                                                                              [1] All trademarks used are properties of their respective owners.

                                                                                            - @@ -481,7 +502,7 @@
                                                                                            -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: diff --git a/docs/manual/loading.html b/docs/manual/loading.html index a26b62c..e18cde6 100644 --- a/docs/manual/loading.html +++ b/docs/manual/loading.html @@ -3,16 +3,16 @@ Loading document - - - + + +
                                                                                            -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: @@ -28,16 +28,16 @@
                                                                                            -
                                                                                            -
                                                                                            Loading document from file
                                                                                            -
                                                                                            Loading document from memory
                                                                                            -
                                                                                            Loading document from C++ IOstreams
                                                                                            -
                                                                                            Handling parsing errors
                                                                                            -
                                                                                            Parsing options
                                                                                            -
                                                                                            Encodings
                                                                                            -
                                                                                            Conformance to W3C specification
                                                                                            +

                                                                                            pugixml provides several functions for loading XML data from various places @@ -49,25 +49,26 @@ EOL handling or attribute value normalization) can impact parsing speed and thus can be disabled. However for vast majority of XML documents there is no performance difference between different parsing options. Parsing options also - control whether certain XML nodes are parsed; see Parsing options for + control whether certain XML nodes are parsed; see Parsing options for more information.

                                                                                            - XML data is always converted to internal character format (see Unicode interface) + XML data is always converted to internal character format (see Unicode interface) 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's a strict subset of UTF-16) and handles all encoding conversions automatically. Unless explicit encoding is specified, loading functions perform automatic encoding detection based on first few characters of XML data, so in almost all cases you do not have to specify document encoding. Encoding - conversion is described in more detail in Encodings. + conversion is described in more detail in Encodings.

                                                                                            -

                                                                                            - The most common source of XML data is files; pugixml provides dedicated functions +

                                                                                            + The + most common source of XML data is files; pugixml provides dedicated functions for loading an XML document from file:

                                                                                            xml_parse_result xml_document::load_file(const char* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
                                                                                            @@ -75,8 +76,8 @@
                                                                                             

                                                                                            These functions accept the file path as its first argument, and also two - optional arguments, which specify parsing options (see Parsing options) - and input data encoding (see Encodings). The path has the target + optional arguments, which specify parsing options (see Parsing options) + and input data encoding (see Encodings). The path has the target operating system format, so it can be a relative or absolute one, it should have the delimiters of the target system, it should have the exact case if the target file system is case-sensitive, etc. @@ -94,13 +95,12 @@ The result of the operation is returned in an xml_parse_result object; this object contains the operation status and the related information (i.e. last successfully parsed position in the input file, if parsing fails). - See Handling parsing errors for error handling details. + See Handling parsing errors for error handling details.

                                                                                            This is an example of loading XML document from file (samples/load_file.cpp):

                                                                                            -

                                                                                            pugi::xml_document doc;
                                                                                             
                                                                                            @@ -113,19 +113,19 @@
                                                                                             
                                                                                            -

                                                                                            - Sometimes XML data should be loaded from some other source than a 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. All these scenarios require loading document - from memory. First you should prepare a contiguous memory block with all - XML data; then you have to invoke one of buffer loading functions. These - functions will handle the necessary encoding conversions, if any, and then - will parse the data into the corresponding XML tree. There are several buffer - loading functions, which differ in the behavior and thus in performance/memory - usage: +

                                                                                            + Sometimes XML data should be + loaded from some other source than a 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. + All these scenarios require loading document from memory. First you should + prepare a contiguous memory block with all XML data; then you have to invoke + one of buffer loading functions. These functions will handle the necessary + encoding conversions, if any, and then will parse the data into the corresponding + XML tree. There are several buffer loading functions, which differ in the + behavior and thus in performance/memory usage:

                                                                                            xml_parse_result xml_document::load_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
                                                                                             xml_parse_result xml_document::load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
                                                                                            @@ -135,7 +135,7 @@
                                                                                                     All functions accept the buffer which is represented by a pointer to XML
                                                                                                     data, contents, and data
                                                                                                     size in bytes. Also there are two optional arguments, which specify parsing
                                                                                            -        options (see  Parsing options) and input data encoding (see  Encodings).
                                                                                            +        options (see Parsing options) and input data encoding (see Encodings).
                                                                                                     The buffer does not have to be zero-terminated.
                                                                                                   

                                                                                            @@ -163,9 +163,10 @@ is the recommended function if you have to load the document from memory and performance is critical.

                                                                                            -

                                                                                            - There is also a simple helper function for cases when you want to load the - XML document from null-terminated character string: +

                                                                                            + There is also a simple helper function + for cases when you want to load the XML document from null-terminated character + string:

                                                                                            xml_parse_result xml_document::load(const char_t* contents, unsigned int options = parse_default);
                                                                                             
                                                                                            @@ -183,7 +184,6 @@ (samples/load_memory.cpp):

                                                                                            -

                                                                                            const char source[] = "<mesh name='sphere'><bounds>0 0 1 1</bounds></mesh>";
                                                                                             size_t size = sizeof(source);
                                                                                            @@ -191,61 +191,57 @@
                                                                                             

                                                                                            -

                                                                                            -
                                                                                            // You can use load_buffer to load document from immutable memory block:
                                                                                            -pugi::xml_parse_result result = doc.load_buffer(source, size);
                                                                                            +
                                                                                            // You can use load_buffer to load document from immutable memory block:
                                                                                            +pugi::xml_parse_result result = doc.load_buffer(source, size);
                                                                                             

                                                                                            -

                                                                                            -
                                                                                            // You can use load_buffer_inplace to load document from mutable memory block; the block's lifetime must exceed that of document
                                                                                            -char* buffer = new char[size];
                                                                                            +
                                                                                            // You can use load_buffer_inplace to load document from mutable memory block; the block's lifetime must exceed that of document
                                                                                            +char* buffer = new char[size];
                                                                                             memcpy(buffer, source, size);
                                                                                             
                                                                                            -// The block can be allocated by any method; the block is modified during parsing
                                                                                            -pugi::xml_parse_result result = doc.load_buffer_inplace(buffer, size);
                                                                                            +// The block can be allocated by any method; the block is modified during parsing
                                                                                            +pugi::xml_parse_result result = doc.load_buffer_inplace(buffer, size);
                                                                                             
                                                                                            -// You have to destroy the block yourself after the document is no longer used
                                                                                            -delete[] buffer;
                                                                                            +// You have to destroy the block yourself after the document is no longer used
                                                                                            +delete[] buffer;
                                                                                             

                                                                                            -

                                                                                            -
                                                                                            // You can use load_buffer_inplace_own to load document from mutable memory block and to pass the ownership of this block
                                                                                            -// The block has to be allocated via pugixml allocation function - using i.e. operator new here is incorrect
                                                                                            -char* buffer = static_cast<char*>(pugi::get_memory_allocation_function()(size));
                                                                                            +
                                                                                            // You can use load_buffer_inplace_own to load document from mutable memory block and to pass the ownership of this block
                                                                                            +// The block has to be allocated via pugixml allocation function - using i.e. operator new here is incorrect
                                                                                            +char* buffer = static_cast<char*>(pugi::get_memory_allocation_function()(size));
                                                                                             memcpy(buffer, source, size);
                                                                                             
                                                                                            -// The block will be deleted by the document
                                                                                            -pugi::xml_parse_result result = doc.load_buffer_inplace_own(buffer, size);
                                                                                            +// The block will be deleted by the document
                                                                                            +pugi::xml_parse_result result = doc.load_buffer_inplace_own(buffer, size);
                                                                                             

                                                                                            -

                                                                                            -
                                                                                            // You can use load to load document from null-terminated strings, for example literals:
                                                                                            -pugi::xml_parse_result result = doc.load("<mesh name='sphere'><bounds>0 0 1 1</bounds></mesh>");
                                                                                            +
                                                                                            // You can use load to load document from null-terminated strings, for example literals:
                                                                                            +pugi::xml_parse_result result = doc.load("<mesh name='sphere'><bounds>0 0 1 1</bounds></mesh>");
                                                                                             

                                                                                            -

                                                                                            - To enhance interoperability, pugixml provides functions for loading document - from any object which implements C++ std::istream - interface. This allows you to load documents from any standard C++ stream - (i.e. file stream) or any third-party compliant implementation (i.e. Boost - Iostreams). There are two functions, one works with narrow character streams, - another handles wide character ones: +

                                                                                            + To enhance interoperability, pugixml + provides functions for loading document from any object which implements + C++ std::istream interface. This allows you to load + documents from any standard C++ stream (i.e. file stream) or any third-party + compliant implementation (i.e. Boost Iostreams). There are two functions, + one works with narrow character streams, another handles wide character ones:

                                                                                            xml_parse_result xml_document::load(std::istream& stream, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
                                                                                             xml_parse_result xml_document::load(std::wistream& stream, unsigned int options = parse_default);
                                                                                            @@ -275,7 +271,6 @@
                                                                                                     the sample code for more complex examples involving wide streams and locales:
                                                                                                   

                                                                                            -

                                                                                            std::ifstream stream("weekly-utf-8.xml");
                                                                                             pugi::xml_parse_result result = doc.load(stream);
                                                                                            @@ -285,12 +280,14 @@
                                                                                             
                                                                                            -

                                                                                            - All document loading functions return the parsing result via xml_parse_result object. It contains parsing - status, the offset of last successfully parsed character from the beginning - of the source stream, and the encoding of the source stream: +

                                                                                            + All document loading functions return the + parsing result via xml_parse_result + object. It contains parsing status, the offset of last successfully parsed + character from the beginning of the source stream, and the encoding of the + source stream:

                                                                                            struct xml_parse_result
                                                                                             {
                                                                                            @@ -302,16 +299,16 @@
                                                                                                 const char* description() const;
                                                                                             };
                                                                                             
                                                                                            -

                                                                                            - Parsing status is represented as the xml_parse_status +

                                                                                            + Parsing + status is represented as the xml_parse_status enumeration and can be one of the following:

                                                                                            -
                                                                                              +
                                                                                              • status_ok means that no error was encountered during parsing; the source stream represents the valid XML document which was fully parsed and converted to a tree.

                                                                                                -
                                                                                              • status_file_not_found is only @@ -330,7 +327,6 @@
                                                                                              • status_internal_error means that something went horribly wrong; currently this error does not occur

                                                                                                -
                                                                                              • status_unrecognized_tag means @@ -371,15 +367,18 @@ opening one (i.e. <node></nedo>) or because some tag was not closed at all
                                                                                              • +
                                                                                              • + status_no_document_element + means that no element nodes were discovered during parsing; this usually + indicates an empty or invalid document +
                                                                                              -

                                                                                              - description() - member function can be used to convert parsing status to a string; the returned - message is always in English, so you'll have to write your own function if - you need a localized string. However please note that the exact messages - returned by description() - function may change from version to version, so any complex status handling - should be based on status +

                                                                                              + description() member function can be used to convert + parsing status to a string; the returned message is always in English, so + you'll have to write your own function if you need a localized string. However + please note that the exact messages returned by description() function may change from version to version, + so any complex status handling should be based on status value. Note that description() returns a char string even in PUGIXML_WCHAR_MODE; you'll have to call as_wide to get the wchar_t string. @@ -394,16 +393,18 @@ attribute attr will contain the string value>some data</node>.

                                                                                              -

                                                                                              - In addition to the status code, parsing result has an offset - member, which contains the offset of last successfully parsed character if - parsing failed because of an error in source data; otherwise offset is 0. For parsing efficiency reasons, - pugixml does not track the current line during parsing; this offset is in - units of pugi::char_t (bytes for character - mode, wide characters for wide character mode). Many text editors support - 'Go To Position' feature - you can use it to locate the exact error position. - Alternatively, if you're loading the document from memory, you can display - the error chunk along with the error description (see the example code below). +

                                                                                              + In addition to the status code, parsing + result has an offset member, + which contains the offset of last successfully parsed character if parsing + failed because of an error in source data; otherwise offset + is 0. For parsing efficiency reasons, pugixml does not track the current + line during parsing; this offset is in units of pugi::char_t + (bytes for character mode, wide characters for wide character mode). Many + text editors support 'Go To Position' feature - you can use it to locate + the exact error position. Alternatively, if you're loading the document from + memory, you can display the error chunk along with the error description + (see the example code below).

                                                                                              @@ -416,16 +417,17 @@ track the error position.

                                                                                              -

                                                                                              - Parsing result also has an encoding - member, which can be used to check that the source data encoding was correctly - guessed. It is equal to the exact encoding used during parsing (i.e. with - the exact endianness); see Encodings for more information. -

                                                                                              -

                                                                                              - Parsing result object can be implicitly converted to bool; - 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 bool: +

                                                                                              + Parsing result also has an encoding member, which can be used to check + that the source data encoding was correctly guessed. It is equal to the exact + encoding used during parsing (i.e. with the exact endianness); see Encodings for + more information. +

                                                                                              +

                                                                                              + Parsing result object can be implicitly + converted to bool; 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 bool: if (doc.load_file("file.xml")) { ... } else { ... }.

                                                                                              @@ -433,7 +435,6 @@ This is an example of handling loading errors (samples/load_error_handling.cpp):

                                                                                              -

                                                                                              pugi::xml_document doc;
                                                                                               pugi::xml_parse_result result = doc.load(source);
                                                                                              @@ -452,7 +453,7 @@
                                                                                               

                                                                                            All document loading functions accept the optional parameter options. This is a bitmask that customizes @@ -478,20 +479,18 @@

                                                                                            These flags control the resulting tree contents:

                                                                                            -
                                                                                              +
                                                                                              • parse_declaration determines if XML document declaration (node with type node_declaration) is to be put in DOM tree. If this flag is off, it is not put in the tree, but is still parsed and checked for correctness. This flag is off by default.

                                                                                                -
                                                                                              • parse_doctype determines if XML document type declaration (node with type node_doctype) is to be put in DOM tree. If this flag is off, it is not put in the tree, but is still parsed and checked for correctness. This flag is off by default.

                                                                                                -
                                                                                              • parse_pi determines if processing instructions @@ -499,21 +498,26 @@ in DOM tree. If this flag is off, they are not put in the tree, but are still parsed and checked for correctness. Note that <?xml ...?> (document declaration) is not considered to be a PI. This flag is off by default.

                                                                                                -
                                                                                              • parse_comments determines if comments (nodes with type node_comment) are to be put in DOM tree. If this flag is off, they are not put in the tree, but are still parsed and checked for correctness. This flag is off by default.

                                                                                                -
                                                                                              • parse_cdata determines if CDATA sections (nodes with type node_cdata) are to be put in DOM tree. If this flag is off, they are not put in the tree, but are still parsed and checked for correctness. This flag is on by default.

                                                                                                - +
                                                                                              • +
                                                                                              • + parse_trim_pcdata determines if leading + and trailing whitespace characters are to be removed from PCDATA nodes. + While for some applications leading/trailing whitespace is significant, + often the application only cares about the non-whitespace contents so + it's easier to trim whitespace from text during parsing. This flag is + off by default.

                                                                                              • parse_ws_pcdata determines if PCDATA @@ -532,7 +536,6 @@ one child when parse_ws_pcdata is not set. This flag is off by default.

                                                                                                -
                                                                                              • parse_ws_pcdata_single determines @@ -550,12 +553,38 @@ and value " ". This flag has no effect if parse_ws_pcdata is enabled. This flag is off by default. +

                                                                                                +
                                                                                              • +
                                                                                              • + parse_fragment determines if document + should be treated as a fragment of a valid XML. Parsing document as a + fragment leads to top-level PCDATA content (i.e. text that is not located + inside a node) to be added to a tree, and additionally treats documents + without element nodes as valid. This flag is off + by default.
                                                                                              +
                                                                                              + + + + + +
                                                                                              [Caution]Caution

                                                                                              + Using in-place parsing (load_buffer_inplace) + with parse_fragment flag + may result in the loss of the last character of the buffer if it is a part + of PCDATA. Since PCDATA values are null-terminated strings, the only way + to resolve this is to provide a null-terminated buffer as an input to + load_buffer_inplace - i.e. + doc.load_buffer_inplace("test\0", + 5, pugi::parse_default | + pugi::parse_fragment). +

                                                                                              These flags control the transformation of tree element contents:

                                                                                              -
                                                                                                +
                                                                                                • parse_escapes determines if character and entity references are to be expanded during the parsing process. @@ -569,7 +598,6 @@ ones). If character/entity reference can not be expanded, it is left as is, so you can do additional processing later. Reference expansion is performed on attribute values and PCDATA content. This flag is on by default.

                                                                                                  -
                                                                                                • parse_eol determines if EOL handling (that @@ -579,7 +607,6 @@ be performed on input data (that is, comments contents, PCDATA/CDATA contents and attribute values). This flag is on by default.

                                                                                                  -
                                                                                                • parse_wconv_attribute determines @@ -590,7 +617,6 @@ is set, i.e. \r\n is converted to a single space. This flag is on by default.

                                                                                                  -
                                                                                                • parse_wnorm_attribute determines @@ -621,7 +647,7 @@

                                                                                                  Additionally there are three predefined option masks:

                                                                                                  -
                                                                                                    +
                                                                                                    • parse_minimal has all options turned off. This option mask means that pugixml does not add declaration nodes, @@ -630,7 +656,6 @@ so theoretically it is the fastest mode. However, as mentioned above, in practice parse_default is usually equally fast.

                                                                                                      -
                                                                                                    • parse_default is the default set of flags, @@ -640,7 +665,6 @@ in attribute values and performing EOL handling. Note, that PCDATA sections consisting only of whitespace characters are not parsed (by default) for performance reasons.

                                                                                                      -
                                                                                                    • parse_full is the set of flags which adds @@ -657,24 +681,23 @@ This is an example of using different parsing options (samples/load_options.cpp):

                                                                                                      -

                                                                                                      const char* source = "<!--comment--><node>&lt;</node>";
                                                                                                       
                                                                                                      -// Parsing with default options; note that comment node is not added to the tree, and entity reference &lt; is expanded
                                                                                                      -doc.load(source);
                                                                                                      +// Parsing with default options; note that comment node is not added to the tree, and entity reference &lt; is expanded
                                                                                                      +doc.load(source);
                                                                                                       std::cout << "First node value: [" << doc.first_child().value() << "], node child value: [" << doc.child_value("node") << "]\n";
                                                                                                       
                                                                                                      -// Parsing with additional parse_comments option; comment node is now added to the tree
                                                                                                      -doc.load(source, pugi::parse_default | pugi::parse_comments);
                                                                                                      +// Parsing with additional parse_comments option; comment node is now added to the tree
                                                                                                      +doc.load(source, pugi::parse_default | pugi::parse_comments);
                                                                                                       std::cout << "First node value: [" << doc.first_child().value() << "], node child value: [" << doc.child_value("node") << "]\n";
                                                                                                       
                                                                                                      -// Parsing with additional parse_comments option and without the (default) parse_escapes option; &lt; is not expanded
                                                                                                      -doc.load(source, (pugi::parse_default | pugi::parse_comments) & ~pugi::parse_escapes);
                                                                                                      +// Parsing with additional parse_comments option and without the (default) parse_escapes option; &lt; is not expanded
                                                                                                      +doc.load(source, (pugi::parse_default | pugi::parse_comments) & ~pugi::parse_escapes);
                                                                                                       std::cout << "First node value: [" << doc.first_child().value() << "], node child value: [" << doc.child_value("node") << "]\n";
                                                                                                       
                                                                                                      -// Parsing with minimal option mask; comment node is not added to the tree, and &lt; is not expanded
                                                                                                      -doc.load(source, pugi::parse_minimal);
                                                                                                      +// Parsing with minimal option mask; comment node is not added to the tree, and &lt; is not expanded
                                                                                                      +doc.load(source, pugi::parse_minimal);
                                                                                                       std::cout << "First node value: [" << doc.first_child().value() << "], node child value: [" << doc.child_value("node") << "]\n";
                                                                                                       

                                                                                                      @@ -682,24 +705,25 @@

                                                                                                    -

                                                                                                    - 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's a strict subset of UTF-16) and handles all encoding conversions. Most - loading functions accept the optional parameter encoding. - This is a value of enumeration type xml_encoding, +

                                                                                                    + 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's a strict subset of UTF-16) and handles + all encoding conversions. Most loading functions accept the optional parameter + encoding. This is a value + of enumeration type xml_encoding, that can have the following values:

                                                                                                    -
                                                                                                      +
                                                                                                      • encoding_auto means that pugixml will try to guess the encoding based on source XML data. The algorithm is a modified version of the one presented in Appendix F.1 of XML recommendation; it tries to match the first few bytes of input data with the following patterns in strict order:

                                                                                                        -
                                                                                                          +
                                                                                                          • If first four bytes match UTF-32 BOM (Byte Order Mark), encoding is assumed to be UTF-32 with the endianness equal to that of BOM; @@ -727,7 +751,6 @@
                                                                                                          • Otherwise encoding is assumed to be UTF-8.

                                                                                                            -
                                                                                                          @@ -799,7 +822,7 @@

                                                                                                        pugixml is not fully W3C conformant - it can load any valid XML document, @@ -818,7 +841,7 @@ As for rejecting invalid XML documents, there are a number of incompatibilities with W3C specification, including:

                                                                                                        -
                                                                                                          +
                                                                                                          • Multiple attributes of the same node can have equal names.
                                                                                                          • @@ -848,7 +871,7 @@
                                                                                                          - @@ -856,7 +879,7 @@
                                                                                                          -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: diff --git a/docs/manual/modify.html b/docs/manual/modify.html index f2f7785..05b0fbe 100644 --- a/docs/manual/modify.html +++ b/docs/manual/modify.html @@ -3,16 +3,16 @@ Modifying document data - - - + + +
                                                                                                          -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: @@ -28,15 +28,16 @@
                                                                                                          -
                                                                                                          -
                                                                                                          Setting node data
                                                                                                          -
                                                                                                          Setting attribute data
                                                                                                          -
                                                                                                          Adding nodes/attributes
                                                                                                          -
                                                                                                          Removing nodes/attributes
                                                                                                          -
                                                                                                          Working with text contents
                                                                                                          -
                                                                                                          Cloning nodes/attributes
                                                                                                          +

                                                                                                          The document in pugixml is fully mutable: you can completely change the document @@ -60,11 +61,12 @@

                                                                                                          -

                                                                                                          - As discussed before, nodes can have name and value, both of which are strings. - Depending on node type, name or value may be absent. node_document +

                                                                                                          + As discussed + before, nodes can have name and value, both of which are strings. Depending + on node type, name or value may be absent. node_document nodes do not have a name or value, node_element and node_declaration nodes always have a name but never have a value, node_pcdata, @@ -96,31 +98,31 @@ This is an example of setting node name and value (samples/modify_base.cpp):

                                                                                                          -

                                                                                                          pugi::xml_node node = doc.child("node");
                                                                                                           
                                                                                                          -// change node name
                                                                                                          -std::cout << node.set_name("notnode");
                                                                                                          +// change node name
                                                                                                          +std::cout << node.set_name("notnode");
                                                                                                           std::cout << ", new node name: " << node.name() << std::endl;
                                                                                                           
                                                                                                          -// change comment text
                                                                                                          -std::cout << doc.last_child().set_value("useless comment");
                                                                                                          +// change comment text
                                                                                                          +std::cout << doc.last_child().set_value("useless comment");
                                                                                                           std::cout << ", new comment text: " << doc.last_child().value() << std::endl;
                                                                                                           
                                                                                                          -// we can't change value of the element or name of the comment
                                                                                                          -std::cout << node.set_value("1") << ", " << doc.last_child().set_name("2") << std::endl;
                                                                                                          +// we can't change value of the element or name of the comment
                                                                                                          +std::cout << node.set_value("1") << ", " << doc.last_child().set_name("2") << std::endl;
                                                                                                           

                                                                                                          -

                                                                                                          - All attributes have name and value, both of which are strings (value may - be empty). You can set them with the following functions: +

                                                                                                          + All + attributes have name and value, both of which are strings (value may be empty). + You can set them with the following functions:

                                                                                                          bool xml_attribute::set_name(const char_t* rhs);
                                                                                                           bool xml_attribute::set_value(const char_t* rhs);
                                                                                                          @@ -142,6 +144,8 @@
                                                                                                           bool xml_attribute::set_value(unsigned int rhs);
                                                                                                           bool xml_attribute::set_value(double rhs);
                                                                                                           bool xml_attribute::set_value(bool rhs);
                                                                                                          +bool xml_attribute::set_value(long long rhs);
                                                                                                          +bool xml_attribute::set_value(unsigned long long rhs);
                                                                                                           

                                                                                                          The above functions convert the argument to string and then call the base @@ -167,14 +171,14 @@

                                                                                                          Note

                                                                                                          - There are no portable 64-bit types in C++, so there is no corresponding - set_value function. If - your platform has a 64-bit integer, you can easily write such a function - yourself. + set_value overloads with + long long + type are only available if your platform has reliable support for the type, + including string conversions.

                                                                                                          -

                                                                                                          - For convenience, all set_value +

                                                                                                          + For convenience, all set_value functions have the corresponding assignment operators:

                                                                                                          xml_attribute& xml_attribute::operator=(const char_t* rhs);
                                                                                                          @@ -182,6 +186,8 @@
                                                                                                           xml_attribute& xml_attribute::operator=(unsigned int rhs);
                                                                                                           xml_attribute& xml_attribute::operator=(double rhs);
                                                                                                           xml_attribute& xml_attribute::operator=(bool rhs);
                                                                                                          +xml_attribute& xml_attribute::operator=(long long rhs);
                                                                                                          +xml_attribute& xml_attribute::operator=(unsigned long long rhs);
                                                                                                           

                                                                                                          These operators simply call the right set_value @@ -193,20 +199,19 @@ This is an example of setting attribute name and value (samples/modify_base.cpp):

                                                                                                          -

                                                                                                          pugi::xml_attribute attr = node.attribute("id");
                                                                                                           
                                                                                                          -// change attribute name/value
                                                                                                          -std::cout << attr.set_name("key") << ", " << attr.set_value("345");
                                                                                                          +// change attribute name/value
                                                                                                          +std::cout << attr.set_name("key") << ", " << attr.set_value("345");
                                                                                                           std::cout << ", new attribute: " << attr.name() << "=" << attr.value() << std::endl;
                                                                                                           
                                                                                                          -// we can use numbers or booleans
                                                                                                          -attr.set_value(1.234);
                                                                                                          +// we can use numbers or booleans
                                                                                                          +attr.set_value(1.234);
                                                                                                           std::cout << "new attribute value: " << attr.value() << std::endl;
                                                                                                           
                                                                                                          -// we can also use assignment operators for more concise code
                                                                                                          -attr = true;
                                                                                                          +// we can also use assignment operators for more concise code
                                                                                                          +attr = true;
                                                                                                           std::cout << "final attribute value: " << attr.value() << std::endl;
                                                                                                           

                                                                                                          @@ -214,10 +219,11 @@

                                                                                                          -

                                                                                                          - Nodes and attributes do not exist without a document tree, so you can't create +

                                                                                                          + Nodes + and attributes do not exist without a document tree, so you can'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:

                                                                                                          @@ -260,7 +266,7 @@ All functions return the handle to the created object on success, and null handle on failure. There are several reasons for failure:

                                                                                                          -
                                                                                                            +
                                                                                                            • Adding fails if the target node is null;
                                                                                                            • @@ -311,20 +317,19 @@ This is an example of adding new attributes/nodes to the document (samples/modify_add.cpp):

                                                                                                              -

                                                                                                              -
                                                                                                              // add node with some name
                                                                                                              -pugi::xml_node node = doc.append_child("node");
                                                                                                              +
                                                                                                              // add node with some name
                                                                                                              +pugi::xml_node node = doc.append_child("node");
                                                                                                               
                                                                                                              -// add description node with text child
                                                                                                              -pugi::xml_node descr = node.append_child("description");
                                                                                                              +// add description node with text child
                                                                                                              +pugi::xml_node descr = node.append_child("description");
                                                                                                               descr.append_child(pugi::node_pcdata).set_value("Simple node");
                                                                                                               
                                                                                                              -// add param node before the description
                                                                                                              -pugi::xml_node param = node.insert_child_before("param", descr);
                                                                                                              +// add param node before the description
                                                                                                              +pugi::xml_node param = node.insert_child_before("param", descr);
                                                                                                               
                                                                                                              -// add attributes to param node
                                                                                                              -param.append_attribute("name") = "version";
                                                                                                              +// add attributes to param node
                                                                                                              +param.append_attribute("name") = "version";
                                                                                                               param.append_attribute("value") = 1.1;
                                                                                                               param.insert_attribute_after("type", param.attribute("name")) = "float";
                                                                                                               
                                                                                                              @@ -333,10 +338,11 @@
                                                                                                            -

                                                                                                            - If you do not want your document to contain some node or attribute, you can +

                                                                                                            + If + you do not want your document to contain some node or attribute, you can remove it with one of the following functions:

                                                                                                            bool xml_node::remove_attribute(const xml_attribute& a);
                                                                                                            @@ -350,7 +356,7 @@
                                                                                                                     attributes) from the document, and returns the operation result. Removing
                                                                                                                     fails if one of the following is true:
                                                                                                                   

                                                                                                            -
                                                                                                              +
                                                                                                              • The node the function is called on is null;
                                                                                                              • @@ -388,18 +394,17 @@ This is an example of removing attributes/nodes from the document (samples/modify_remove.cpp):

                                                                                                                -

                                                                                                                -
                                                                                                                // remove description node with the whole subtree
                                                                                                                -pugi::xml_node node = doc.child("node");
                                                                                                                +
                                                                                                                // remove description node with the whole subtree
                                                                                                                +pugi::xml_node node = doc.child("node");
                                                                                                                 node.remove_child("description");
                                                                                                                 
                                                                                                                -// remove id attribute
                                                                                                                -pugi::xml_node param = node.child("param");
                                                                                                                +// remove id attribute
                                                                                                                +pugi::xml_node param = node.child("param");
                                                                                                                 param.remove_attribute("value");
                                                                                                                 
                                                                                                                -// we can also remove nodes/attributes by handles
                                                                                                                -pugi::xml_attribute id = param.attribute("name");
                                                                                                                +// we can also remove nodes/attributes by handles
                                                                                                                +pugi::xml_attribute id = param.attribute("name");
                                                                                                                 param.remove_attribute(id);
                                                                                                                 

                                                                                                                @@ -407,7 +412,7 @@

                                                                                                              pugixml provides a special class, xml_text, @@ -416,8 +421,8 @@ documentation for accessing document data; this section describes the modification interface of xml_text.

                                                                                                              -

                                                                                                              - Once you have an xml_text +

                                                                                                              + Once you have an xml_text object, you can set the text contents using the following function:

                                                                                                              bool xml_text::set(const char_t* rhs);
                                                                                                              @@ -434,14 +439,16 @@
                                                                                                                       an element node, this function creates the PCDATA child node if necessary
                                                                                                                       (i.e. if the element node does not have a PCDATA/CDATA child already).
                                                                                                                     

                                                                                                              -

                                                                                                              - In addition to a string function, several functions are provided for handling - text with numbers and booleans as contents: +

                                                                                                              + In addition to a string function, several + functions are provided for handling text with numbers and booleans as contents:

                                                                                                              bool xml_text::set(int rhs);
                                                                                                               bool xml_text::set(unsigned int rhs);
                                                                                                               bool xml_text::set(double rhs);
                                                                                                               bool xml_text::set(bool rhs);
                                                                                                              +bool xml_text::set(long long rhs);
                                                                                                              +bool xml_text::set(unsigned long long rhs);
                                                                                                               

                                                                                                              The above functions convert the argument to string and then call the base @@ -450,8 +457,8 @@ functions. You can refer to documentation for the attribute functions for details.

                                                                                                              -

                                                                                                              - For convenience, all set +

                                                                                                              + For convenience, all set functions have the corresponding assignment operators:

                                                                                                              xml_text& xml_text::operator=(const char_t* rhs);
                                                                                                              @@ -459,6 +466,8 @@
                                                                                                               xml_text& xml_text::operator=(unsigned int rhs);
                                                                                                               xml_text& xml_text::operator=(double rhs);
                                                                                                               xml_text& xml_text::operator=(bool rhs);
                                                                                                              +xml_text& xml_text::operator=(long long rhs);
                                                                                                              +xml_text& xml_text::operator=(unsigned long long rhs);
                                                                                                               

                                                                                                              These operators simply call the right set @@ -471,30 +480,29 @@ object to modify text contents (samples/text.cpp):

                                                                                                              -

                                                                                                              -
                                                                                                              // change project version
                                                                                                              -project.child("version").text() = 1.2;
                                                                                                              +
                                                                                                              // change project version
                                                                                                              +project.child("version").text() = 1.2;
                                                                                                               
                                                                                                              -// add description element and set the contents
                                                                                                              -// note that we do not have to explicitly add the node_pcdata child
                                                                                                              -project.append_child("description").text().set("a test project");
                                                                                                              +// add description element and set the contents
                                                                                                              +// note that we do not have to explicitly add the node_pcdata child
                                                                                                              +project.append_child("description").text().set("a test project");
                                                                                                               

                                                                                                              -

                                                                                                              - With the help of previously described functions, it is possible to create - trees with any contents and structure, including cloning the existing data. - However since this is an often needed operation, pugixml provides built-in - node/attribute cloning facilities. Since nodes and attributes do not exist - without a document tree, you can't create a standalone copy - you have to - immediately insert it somewhere in the tree. For this, you can use one of - the following functions: +

                                                                                                              + With + the help of previously described functions, it is possible to create trees + with any contents and structure, including cloning the existing data. However + since this is an often needed operation, pugixml provides built-in node/attribute + cloning facilities. Since nodes and attributes do not exist without a document + tree, you can't create a standalone copy - you have to immediately insert + it somewhere in the tree. For this, you can use one of the following functions:

                                                                                                              xml_attribute xml_node::append_copy(const xml_attribute& proto);
                                                                                                               xml_attribute xml_node::prepend_copy(const xml_attribute& proto);
                                                                                                              @@ -528,7 +536,7 @@
                                                                                                                       for more information. There are additional caveats specific to cloning
                                                                                                                       functions:
                                                                                                                     

                                                                                                              -
                                                                                                                +
                                                                                                                • Cloning null handles results in operation failure;
                                                                                                                • @@ -551,7 +559,6 @@ node cloning and usage of other document modification functions:

                                                                                                                  -

                                                                                                                  bool load_preprocess(pugi::xml_document& doc, const char* path);
                                                                                                                   
                                                                                                                  @@ -563,23 +570,23 @@
                                                                                                                           {
                                                                                                                               pugi::xml_node include = child;
                                                                                                                   
                                                                                                                  -            // load new preprocessed document (note: ideally this should handle relative paths)
                                                                                                                  -            const char* path = include.value();
                                                                                                                  +            // load new preprocessed document (note: ideally this should handle relative paths)
                                                                                                                  +            const char* path = include.value();
                                                                                                                   
                                                                                                                               pugi::xml_document doc;
                                                                                                                               if (!load_preprocess(doc, path)) return false;
                                                                                                                   
                                                                                                                  -            // insert the comment marker above include directive
                                                                                                                  -            node.insert_child_before(pugi::node_comment, include).set_value(path);
                                                                                                                  +            // insert the comment marker above include directive
                                                                                                                  +            node.insert_child_before(pugi::node_comment, include).set_value(path);
                                                                                                                   
                                                                                                                  -            // copy the document above the include directive (this retains the original order!)
                                                                                                                  -            for (pugi::xml_node ic = doc.first_child(); ic; ic = ic.next_sibling())
                                                                                                                  +            // copy the document above the include directive (this retains the original order!)
                                                                                                                  +            for (pugi::xml_node ic = doc.first_child(); ic; ic = ic.next_sibling())
                                                                                                                               {
                                                                                                                                   node.insert_copy_before(ic, include);
                                                                                                                               }
                                                                                                                   
                                                                                                                  -            // remove the include node and move to the next child
                                                                                                                  -            child = child.next_sibling();
                                                                                                                  +            // remove the include node and move to the next child
                                                                                                                  +            child = child.next_sibling();
                                                                                                                   
                                                                                                                               node.remove_child(include);
                                                                                                                           }
                                                                                                                  @@ -596,18 +603,83 @@
                                                                                                                   
                                                                                                                   bool load_preprocess(pugi::xml_document& doc, const char* path)
                                                                                                                   {
                                                                                                                  -    pugi::xml_parse_result result = doc.load_file(path, pugi::parse_default | pugi::parse_pi); // for <?include?>
                                                                                                                  -    
                                                                                                                  +    pugi::xml_parse_result result = doc.load_file(path, pugi::parse_default | pugi::parse_pi); // for <?include?>
                                                                                                                  +
                                                                                                                       return result ? preprocess(doc) : false;
                                                                                                                   }
                                                                                                                   

                                                                                                                +
                                                                                                                + +

                                                                                                                + pugixml provides several ways to assemble + an XML document from other XML documents. Assuming there is a set of document + fragments, represented as in-memory buffers, the implementation choices are + as follows: +

                                                                                                                +
                                                                                                                • + Use a temporary document to parse the data from a string, then clone + the nodes to a destination node. For example: +
                                                                                                                +
                                                                                                                bool append_fragment(pugi::xml_node target, const char* buffer, size_t size)
                                                                                                                +{
                                                                                                                +    pugi::xml_document doc;
                                                                                                                +    if (!doc.load_buffer(buffer, size)) return false;
                                                                                                                +
                                                                                                                +    for (pugi::xml_node child = doc.first_child(); child; child = child.next_sibling())
                                                                                                                +        target.append_copy(child);
                                                                                                                +}
                                                                                                                +
                                                                                                                +
                                                                                                                • + Cache the parsing step - instead of keeping in-memory buffers, keep document + objects that already contain the parsed fragment: +
                                                                                                                +
                                                                                                                bool append_fragment(pugi::xml_node target, const pugi::xml_document& cached_fragment)
                                                                                                                +{
                                                                                                                +    for (pugi::xml_node child = cached_fragment.first_child(); child; child = child.next_sibling())
                                                                                                                +        target.append_copy(child);
                                                                                                                +}
                                                                                                                +
                                                                                                                +
                                                                                                                • + Use xml_node::append_buffer directly: +
                                                                                                                +
                                                                                                                xml_parse_result xml_node::append_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
                                                                                                                +
                                                                                                                +

                                                                                                                + The first method is more convenient, but slower than the other two. The relative + performance of append_copy + and append_buffer depends + on the buffer format - usually append_buffer + is faster if the buffer is in native encoding (UTF-8 or wchar_t, depending + on PUGIXML_WCHAR_MODE). At + the same time it might be less efficient in terms of memory usage - the implementation + makes a copy of the provided buffer, and the copy has the same lifetime as + the document - the memory used by that copy will be reclaimed after the document + is destroyed, but no sooner. Even deleting all nodes in the document, including + the appended ones, won't reclaim the memory. +

                                                                                                                +

                                                                                                                + append_buffer behaves in + the same way as xml_document::load_buffer + - the input buffer is a byte buffer, with size in bytes; the buffer is not + modified and can be freed after the function returns. +

                                                                                                                +

                                                                                                                + Since append_buffer + needs to append child nodes to the current node, it only works if the current + node is either document or element node. Calling append_buffer + on a node with any other type results in an error with status_append_invalid_root + status. +

                                                                                                                +
                                                                                                              - @@ -615,7 +687,7 @@
                                                                                                              -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: diff --git a/docs/manual/saving.html b/docs/manual/saving.html index d0b2e02..2c05a7b 100644 --- a/docs/manual/saving.html +++ b/docs/manual/saving.html @@ -3,16 +3,16 @@ Saving document - - - + + +
                                                                                                              -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: @@ -28,16 +28,16 @@
                                                                                                              -
                                                                                                              -
                                                                                                              Saving document to a file
                                                                                                              -
                                                                                                              Saving document to C++ IOstreams
                                                                                                              -
                                                                                                              Saving document via writer interface
                                                                                                              -
                                                                                                              Saving a single subtree
                                                                                                              -
                                                                                                              Output options
                                                                                                              -
                                                                                                              Encodings
                                                                                                              -
                                                                                                              Customizing document declaration
                                                                                                              +

                                                                                                              Often after creating a new document or loading the existing one and processing @@ -46,8 +46,8 @@ 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 (see Output options), and also perform - necessary encoding conversions (see Encodings). This section documents + to customize the output format (see Output options), and also perform + necessary encoding conversions (see Encodings). This section documents the relevant functionality.

                                                                                                              @@ -68,19 +68,20 @@

                                                                                                              -

                                                                                                              - If you want to save the whole document to a file, you can use one of the - following functions: +

                                                                                                              + If + you want to save the whole document to a file, you can use one of the following + functions:

                                                                                                              bool xml_document::save_file(const char* path, const char_t* indent = "\t", unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
                                                                                                               bool xml_document::save_file(const wchar_t* path, const char_t* indent = "\t", unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
                                                                                                               

                                                                                                              These functions accept file path as its first argument, and also three optional - arguments, which specify indentation and other output options (see Output options) - and output data encoding (see Encodings). The path has the target + arguments, which specify indentation and other output options (see Output options) + and output data encoding (see Encodings). The path has the target operating system format, so it can be a relative or absolute one, it should have the delimiters of the target system, it should have the exact case if the target file system is case-sensitive, etc. @@ -92,38 +93,39 @@ a special file opening function if it is provided by the runtime library or converts the path to UTF-8 and uses the system file opening function.

                                                                                                              -

                                                                                                              - save_file opens the target - file for writing, outputs the requested header (by default a document declaration - is output, unless the document already has one), and then saves the document - contents. If the file could not be opened, the function returns false. Calling save_file - is equivalent to creating an xml_writer_file - object with FILE* +

                                                                                                              + save_file + opens the target file for writing, outputs the requested header (by default + a document declaration is output, unless the document already has one), and + then saves the document contents. If the file could not be opened, the function + returns false. Calling save_file is equivalent to creating an + xml_writer_file object with + FILE* handle as the only constructor argument and then calling save; - see Saving document via writer interface for writer interface details. + see Saving document via writer interface for writer interface details.

                                                                                                              This is a simple example of saving XML document to file (samples/save_file.cpp):

                                                                                                              -

                                                                                                              -
                                                                                                              // save document to file
                                                                                                              -std::cout << "Saving result: " << doc.save_file("save_file_output.xml") << std::endl;
                                                                                                              +
                                                                                                              // save document to file
                                                                                                              +std::cout << "Saving result: " << doc.save_file("save_file_output.xml") << std::endl;
                                                                                                               

                                                                                                              -

                                                                                                              - To enhance interoperability pugixml provides functions for saving document - to any object which implements C++ std::ostream - interface. This allows you to save documents to any standard C++ 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 std::cout +

                                                                                                              + To enhance interoperability pugixml + provides functions for saving document to any object which implements C++ + std::ostream interface. This allows you to save + documents to any standard C++ 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 std::cout stream as saving target. There are two functions, one works with narrow character streams, another handles wide character ones:

                                                                                                              @@ -143,20 +145,19 @@ you with the ability to save documents to non-Unicode encodings, i.e. you can save Shift-JIS encoded data if you set the correct locale.

                                                                                                              -

                                                                                                              - Calling save with stream - target is equivalent to creating an xml_writer_stream - object with stream as the only constructor argument and then calling save; see Saving document via writer interface for writer +

                                                                                                              + Calling save + with stream target is equivalent to creating an xml_writer_stream + object with stream as the only constructor argument and then calling save; see Saving document via writer interface for writer interface details.

                                                                                                              This is a simple example of saving XML document to standard output (samples/save_stream.cpp):

                                                                                                              -

                                                                                                              -
                                                                                                              // save document to standard output
                                                                                                              -std::cout << "Document:\n";
                                                                                                              +
                                                                                                              // save document to standard output
                                                                                                              +std::cout << "Document:\n";
                                                                                                               doc.save(std::cout);
                                                                                                               

                                                                                                              @@ -164,10 +165,11 @@

                                                                                                              -

                                                                                                              - All of the above saving functions are implemented in terms of writer interface. +

                                                                                                              + 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:

                                                                                                              @@ -203,7 +205,6 @@ read the sample code for more complex examples:

                                                                                                              -

                                                                                                              struct xml_string_writer: pugi::xml_writer
                                                                                                               {
                                                                                                              @@ -220,10 +221,11 @@
                                                                                                               
                                                                                                              -

                                                                                                              - While the previously described functions save the whole document to the destination, +

                                                                                                              + While + the previously described functions save the whole document to the destination, it is easy to save a single subtree. The following functions are provided:

                                                                                                              void xml_node::print(std::ostream& os, const char_t* indent = "\t", unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
                                                                                                              @@ -246,22 +248,21 @@
                                                                                                                       illustrates the difference:
                                                                                                                     

                                                                                                              -

                                                                                                              -
                                                                                                              // get a test document
                                                                                                              -pugi::xml_document doc;
                                                                                                              +
                                                                                                              // get a test document
                                                                                                              +pugi::xml_document doc;
                                                                                                               doc.load("<foo bar='baz'><call>hey</call></foo>");
                                                                                                               
                                                                                                              -// print document to standard output (prints <?xml version="1.0"?><foo bar="baz"><call>hey</call></foo>)
                                                                                                              -doc.save(std::cout, "", pugi::format_raw);
                                                                                                              +// print document to standard output (prints <?xml version="1.0"?><foo bar="baz"><call>hey</call></foo>)
                                                                                                              +doc.save(std::cout, "", pugi::format_raw);
                                                                                                               std::cout << std::endl;
                                                                                                               
                                                                                                              -// print document to standard output as a regular node (prints <foo bar="baz"><call>hey</call></foo>)
                                                                                                              -doc.print(std::cout, "", pugi::format_raw);
                                                                                                              +// print document to standard output as a regular node (prints <foo bar="baz"><call>hey</call></foo>)
                                                                                                              +doc.print(std::cout, "", pugi::format_raw);
                                                                                                               std::cout << std::endl;
                                                                                                               
                                                                                                              -// print a subtree to standard output (prints <call>hey</call>)
                                                                                                              -doc.child("foo").child("call").print(std::cout, "", pugi::format_raw);
                                                                                                              +// print a subtree to standard output (prints <call>hey</call>)
                                                                                                              +doc.child("foo").child("call").print(std::cout, "", pugi::format_raw);
                                                                                                               std::cout << std::endl;
                                                                                                               

                                                                                                              @@ -269,7 +270,7 @@

                                                                                                              All saving functions accept the optional parameter flags. @@ -291,7 +292,7 @@

                                                                                                              These flags control the resulting tree contents:

                                                                                                              -
                                                                                                                +
                                                                                                                • format_indent determines if all nodes should be indented with the indentation string (this is an additional @@ -301,7 +302,6 @@ node's depth relative to the output subtree. This flag has no effect if format_raw is enabled. This flag is on by default.

                                                                                                                  -
                                                                                                                • format_raw switches between formatted and @@ -312,24 +312,23 @@ with parse_ws_pcdata flag, to preserve the original document formatting as much as possible. This flag is off by default.

                                                                                                                  -
                                                                                                                • format_no_escapes disables output - escaping for attribute values and PCDATA contents. If this flag is on, + escaping for attribute values and PCDATA contents. If this flag is off, special symbols (', &, <, >) and all non-printable characters (those with codepoint values less than 32) are converted to XML escape - sequences (i.e. &amp;) during output. If this flag is off, no text + sequences (i.e. &amp;) during output. If this flag is on, no text processing is performed; therefore, output XML can be malformed if output contents contains invalid symbols (i.e. having a stray < in the PCDATA - will make the output malformed). This flag is on + will make the output malformed). This flag is off by default.

                                                                                                                These flags control the additional output information:

                                                                                                                -
                                                                                                                  +
                                                                                                                  • format_no_declaration disables default node declaration output. By default, if the document is saved @@ -338,7 +337,6 @@ the document contents. Enabling this flag disables this declaration. This flag has no effect in xml_node::print functions: they never output the default declaration. This flag is off by default.

                                                                                                                    -
                                                                                                                  • format_write_bom enables Byte Order @@ -364,7 +362,7 @@

                                                                                                                    Additionally, there is one predefined option mask:

                                                                                                                    -
                                                                                                                    • +
                                                                                                                      • format_default is the default set of flags, i.e. it has all options set to their default values. It sets formatted output with indentation, without BOM and with default node declaration, @@ -374,44 +372,43 @@ This is an example that shows the outputs of different output options (samples/save_options.cpp):

                                                                                                                        -

                                                                                                                        -
                                                                                                                        // get a test document
                                                                                                                        -pugi::xml_document doc;
                                                                                                                        +
                                                                                                                        // get a test document
                                                                                                                        +pugi::xml_document doc;
                                                                                                                         doc.load("<foo bar='baz'><call>hey</call></foo>");
                                                                                                                         
                                                                                                                        -// default options; prints
                                                                                                                        -// <?xml version="1.0"?>
                                                                                                                        -// <foo bar="baz">
                                                                                                                        -//         <call>hey</call>
                                                                                                                        -// </foo>
                                                                                                                        -doc.save(std::cout);
                                                                                                                        +// default options; prints
                                                                                                                        +// <?xml version="1.0"?>
                                                                                                                        +// <foo bar="baz">
                                                                                                                        +//         <call>hey</call>
                                                                                                                        +// </foo>
                                                                                                                        +doc.save(std::cout);
                                                                                                                         std::cout << std::endl;
                                                                                                                         
                                                                                                                        -// default options with custom indentation string; prints
                                                                                                                        -// <?xml version="1.0"?>
                                                                                                                        -// <foo bar="baz">
                                                                                                                        -// --<call>hey</call>
                                                                                                                        -// </foo>
                                                                                                                        -doc.save(std::cout, "--");
                                                                                                                        +// default options with custom indentation string; prints
                                                                                                                        +// <?xml version="1.0"?>
                                                                                                                        +// <foo bar="baz">
                                                                                                                        +// --<call>hey</call>
                                                                                                                        +// </foo>
                                                                                                                        +doc.save(std::cout, "--");
                                                                                                                         std::cout << std::endl;
                                                                                                                         
                                                                                                                        -// default options without indentation; prints
                                                                                                                        -// <?xml version="1.0"?>
                                                                                                                        -// <foo bar="baz">
                                                                                                                        -// <call>hey</call>
                                                                                                                        -// </foo>
                                                                                                                        -doc.save(std::cout, "\t", pugi::format_default & ~pugi::format_indent); // can also pass "" instead of indentation string for the same effect
                                                                                                                        -std::cout << std::endl;
                                                                                                                        +// default options without indentation; prints
                                                                                                                        +// <?xml version="1.0"?>
                                                                                                                        +// <foo bar="baz">
                                                                                                                        +// <call>hey</call>
                                                                                                                        +// </foo>
                                                                                                                        +doc.save(std::cout, "\t", pugi::format_default & ~pugi::format_indent); // can also pass "" instead of indentation string for the same effect
                                                                                                                        +std::cout << std::endl;
                                                                                                                         
                                                                                                                        -// raw output; prints
                                                                                                                        -// <?xml version="1.0"?><foo bar="baz"><call>hey</call></foo>
                                                                                                                        -doc.save(std::cout, "\t", pugi::format_raw);
                                                                                                                        +// raw output; prints
                                                                                                                        +// <?xml version="1.0"?><foo bar="baz"><call>hey</call></foo>
                                                                                                                        +doc.save(std::cout, "\t", pugi::format_raw);
                                                                                                                         std::cout << std::endl << std::endl;
                                                                                                                         
                                                                                                                        -// raw output without declaration; prints
                                                                                                                        -// <foo bar="baz"><call>hey</call></foo>
                                                                                                                        -doc.save(std::cout, "\t", pugi::format_raw | pugi::format_no_declaration);
                                                                                                                        +// raw output without declaration; prints
                                                                                                                        +// <foo bar="baz"><call>hey</call></foo>
                                                                                                                        +doc.save(std::cout, "\t", pugi::format_raw | pugi::format_no_declaration);
                                                                                                                         std::cout << std::endl;
                                                                                                                         

                                                                                                                        @@ -419,7 +416,7 @@

                                                                                                                      pugixml supports all popular Unicode encodings (UTF-8, UTF-16 (big and little @@ -427,7 +424,7 @@ it's a strict subset of UTF-16) and handles all encoding conversions during output. The output encoding is set via the encoding parameter of saving functions, which is of type xml_encoding. - The possible values for the encoding are documented in Encodings; + The possible values for the encoding are documented in Encodings; the only flag that has a different meaning is encoding_auto.

                                                                                                                      @@ -460,7 +457,7 @@

                                                                                                                      When you are saving the document using xml_document::save() or xml_document::save_file(), a default XML document declaration is @@ -493,23 +490,22 @@ This is an example that shows how to create a custom declaration node (samples/save_declaration.cpp):

                                                                                                                      -

                                                                                                                      -
                                                                                                                      // get a test document
                                                                                                                      -pugi::xml_document doc;
                                                                                                                      +
                                                                                                                      // get a test document
                                                                                                                      +pugi::xml_document doc;
                                                                                                                       doc.load("<foo bar='baz'><call>hey</call></foo>");
                                                                                                                       
                                                                                                                      -// add a custom declaration node
                                                                                                                      -pugi::xml_node decl = doc.prepend_child(pugi::node_declaration);
                                                                                                                      +// add a custom declaration node
                                                                                                                      +pugi::xml_node decl = doc.prepend_child(pugi::node_declaration);
                                                                                                                       decl.append_attribute("version") = "1.0";
                                                                                                                       decl.append_attribute("encoding") = "UTF-8";
                                                                                                                       decl.append_attribute("standalone") = "no";
                                                                                                                       
                                                                                                                      -// <?xml version="1.0" encoding="UTF-8" standalone="no"?> 
                                                                                                                      -// <foo bar="baz">
                                                                                                                      -//         <call>hey</call>
                                                                                                                      -// </foo>
                                                                                                                      -doc.save(std::cout);
                                                                                                                      +// <?xml version="1.0" encoding="UTF-8" standalone="no"?> 
                                                                                                                      +// <foo bar="baz">
                                                                                                                      +//         <call>hey</call>
                                                                                                                      +// </foo>
                                                                                                                      +doc.save(std::cout);
                                                                                                                       std::cout << std::endl;
                                                                                                                       

                                                                                                                      @@ -518,7 +514,7 @@

                                                                                                                      - @@ -526,7 +522,7 @@
                                                                                                                      -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: diff --git a/docs/manual/toc.html b/docs/manual/toc.html index d9fe5f8..3bedd68 100644 --- a/docs/manual/toc.html +++ b/docs/manual/toc.html @@ -3,15 +3,15 @@ Table of Contents - - - + + +
                                                                                                                      -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: @@ -27,115 +27,117 @@
                                                                                                                      -
                                                                                                                      -
                                                                                                                      Overview
                                                                                                                      +
                                                                                                                      +
                                                                                                                      Overview
                                                                                                                      -
                                                                                                                      Introduction
                                                                                                                      -
                                                                                                                      Feedback
                                                                                                                      -
                                                                                                                      Acknowledgments
                                                                                                                      -
                                                                                                                      License
                                                                                                                      +
                                                                                                                      Introduction
                                                                                                                      +
                                                                                                                      Feedback
                                                                                                                      +
                                                                                                                      Acknowledgments
                                                                                                                      +
                                                                                                                      License
                                                                                                                      -
                                                                                                                      Installation
                                                                                                                      +
                                                                                                                      Installation
                                                                                                                      -
                                                                                                                      Getting pugixml
                                                                                                                      +
                                                                                                                      Getting pugixml
                                                                                                                      -
                                                                                                                      Source distributions
                                                                                                                      -
                                                                                                                      Subversion repository
                                                                                                                      +
                                                                                                                      Source distributions
                                                                                                                      +
                                                                                                                      Subversion repository
                                                                                                                      +
                                                                                                                      Git repository
                                                                                                                      -
                                                                                                                      Building pugixml
                                                                                                                      +
                                                                                                                      Building pugixml
                                                                                                                      -
                                                                                                                      Building pugixml as +
                                                                                                                      Building pugixml as a part of another static library/executable
                                                                                                                      -
                                                                                                                      Building pugixml as +
                                                                                                                      Building pugixml as a standalone static library
                                                                                                                      -
                                                                                                                      Building pugixml as +
                                                                                                                      Building pugixml as a standalone shared library
                                                                                                                      -
                                                                                                                      Using pugixml in header-only - mode
                                                                                                                      -
                                                                                                                      Additional configuration +
                                                                                                                      Using + pugixml in header-only mode
                                                                                                                      +
                                                                                                                      Additional configuration options
                                                                                                                      -
                                                                                                                      Portability
                                                                                                                      +
                                                                                                                      Portability
                                                                                                                      -
                                                                                                                      Document object model
                                                                                                                      +
                                                                                                                      Document object model
                                                                                                                      -
                                                                                                                      Tree structure
                                                                                                                      -
                                                                                                                      C++ interface
                                                                                                                      -
                                                                                                                      Unicode interface
                                                                                                                      -
                                                                                                                      Thread-safety guarantees
                                                                                                                      -
                                                                                                                      Exception guarantees
                                                                                                                      -
                                                                                                                      Memory management
                                                                                                                      +
                                                                                                                      Tree structure
                                                                                                                      +
                                                                                                                      C++ interface
                                                                                                                      +
                                                                                                                      Unicode interface
                                                                                                                      +
                                                                                                                      Thread-safety guarantees
                                                                                                                      +
                                                                                                                      Exception guarantees
                                                                                                                      +
                                                                                                                      Memory management
                                                                                                                      -
                                                                                                                      Custom memory allocation/deallocation +
                                                                                                                      Custom memory allocation/deallocation functions
                                                                                                                      -
                                                                                                                      Memory consumption tuning
                                                                                                                      -
                                                                                                                      Document memory management +
                                                                                                                      Memory consumption tuning
                                                                                                                      +
                                                                                                                      Document memory management internals
                                                                                                                      -
                                                                                                                      Loading document
                                                                                                                      +
                                                                                                                      Loading document
                                                                                                                      -
                                                                                                                      Loading document from file
                                                                                                                      -
                                                                                                                      Loading document from memory
                                                                                                                      -
                                                                                                                      Loading document from C++ IOstreams
                                                                                                                      -
                                                                                                                      Handling parsing errors
                                                                                                                      -
                                                                                                                      Parsing options
                                                                                                                      -
                                                                                                                      Encodings
                                                                                                                      -
                                                                                                                      Conformance to W3C specification
                                                                                                                      +
                                                                                                                      Loading document from file
                                                                                                                      +
                                                                                                                      Loading document from memory
                                                                                                                      +
                                                                                                                      Loading document from C++ IOstreams
                                                                                                                      +
                                                                                                                      Handling parsing errors
                                                                                                                      +
                                                                                                                      Parsing options
                                                                                                                      +
                                                                                                                      Encodings
                                                                                                                      +
                                                                                                                      Conformance to W3C specification
                                                                                                                      -
                                                                                                                      Accessing document data
                                                                                                                      +
                                                                                                                      Accessing document data
                                                                                                                      -
                                                                                                                      Basic traversal functions
                                                                                                                      -
                                                                                                                      Getting node data
                                                                                                                      -
                                                                                                                      Getting attribute data
                                                                                                                      -
                                                                                                                      Contents-based traversal functions
                                                                                                                      -
                                                                                                                      Range-based for-loop support
                                                                                                                      -
                                                                                                                      Traversing node/attribute lists +
                                                                                                                      Basic traversal functions
                                                                                                                      +
                                                                                                                      Getting node data
                                                                                                                      +
                                                                                                                      Getting attribute data
                                                                                                                      +
                                                                                                                      Contents-based traversal functions
                                                                                                                      +
                                                                                                                      Range-based for-loop support
                                                                                                                      +
                                                                                                                      Traversing node/attribute lists via iterators
                                                                                                                      -
                                                                                                                      Recursive traversal with xml_tree_walker
                                                                                                                      -
                                                                                                                      Searching for nodes/attributes +
                                                                                                                      Recursive traversal with xml_tree_walker
                                                                                                                      +
                                                                                                                      Searching for nodes/attributes with predicates
                                                                                                                      -
                                                                                                                      Working with text contents
                                                                                                                      -
                                                                                                                      Miscellaneous functions
                                                                                                                      +
                                                                                                                      Working with text contents
                                                                                                                      +
                                                                                                                      Miscellaneous functions
                                                                                                                      -
                                                                                                                      Modifying document data
                                                                                                                      +
                                                                                                                      Modifying document data
                                                                                                                      -
                                                                                                                      Setting node data
                                                                                                                      -
                                                                                                                      Setting attribute data
                                                                                                                      -
                                                                                                                      Adding nodes/attributes
                                                                                                                      -
                                                                                                                      Removing nodes/attributes
                                                                                                                      -
                                                                                                                      Working with text contents
                                                                                                                      -
                                                                                                                      Cloning nodes/attributes
                                                                                                                      +
                                                                                                                      Setting node data
                                                                                                                      +
                                                                                                                      Setting attribute data
                                                                                                                      +
                                                                                                                      Adding nodes/attributes
                                                                                                                      +
                                                                                                                      Removing nodes/attributes
                                                                                                                      +
                                                                                                                      Working with text contents
                                                                                                                      +
                                                                                                                      Cloning nodes/attributes
                                                                                                                      +
                                                                                                                      Assembling document from fragments
                                                                                                                      -
                                                                                                                      Saving document
                                                                                                                      +
                                                                                                                      Saving document
                                                                                                                      -
                                                                                                                      Saving document to a file
                                                                                                                      -
                                                                                                                      Saving document to C++ IOstreams
                                                                                                                      -
                                                                                                                      Saving document via writer interface
                                                                                                                      -
                                                                                                                      Saving a single subtree
                                                                                                                      -
                                                                                                                      Output options
                                                                                                                      -
                                                                                                                      Encodings
                                                                                                                      -
                                                                                                                      Customizing document declaration
                                                                                                                      +
                                                                                                                      Saving document to a file
                                                                                                                      +
                                                                                                                      Saving document to C++ IOstreams
                                                                                                                      +
                                                                                                                      Saving document via writer interface
                                                                                                                      +
                                                                                                                      Saving a single subtree
                                                                                                                      +
                                                                                                                      Output options
                                                                                                                      +
                                                                                                                      Encodings
                                                                                                                      +
                                                                                                                      Customizing document declaration
                                                                                                                      -
                                                                                                                      XPath
                                                                                                                      +
                                                                                                                      XPath
                                                                                                                      -
                                                                                                                      XPath types
                                                                                                                      -
                                                                                                                      Selecting nodes via XPath expression
                                                                                                                      -
                                                                                                                      Using query objects
                                                                                                                      -
                                                                                                                      Using variables
                                                                                                                      -
                                                                                                                      Error handling
                                                                                                                      -
                                                                                                                      Conformance to W3C specification
                                                                                                                      +
                                                                                                                      XPath types
                                                                                                                      +
                                                                                                                      Selecting nodes via XPath expression
                                                                                                                      +
                                                                                                                      Using query objects
                                                                                                                      +
                                                                                                                      Using variables
                                                                                                                      +
                                                                                                                      Error handling
                                                                                                                      +
                                                                                                                      Conformance to W3C specification
                                                                                                                      -
                                                                                                                      Changelog
                                                                                                                      -
                                                                                                                      API Reference
                                                                                                                      -
                                                                                                                      Table of Contents
                                                                                                                      +
                                                                                                                      Changelog
                                                                                                                      +
                                                                                                                      API Reference
                                                                                                                      +
                                                                                                                      Table of Contents
                                                                                                                      - @@ -143,7 +145,7 @@
                                                                                                                      -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: diff --git a/docs/manual/xpath.html b/docs/manual/xpath.html index bb37f64..e2290e5 100644 --- a/docs/manual/xpath.html +++ b/docs/manual/xpath.html @@ -3,16 +3,16 @@ XPath - - - + + +
                                                                                                                      -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: @@ -28,15 +28,15 @@
                                                                                                                      -
                                                                                                                      -
                                                                                                                      XPath types
                                                                                                                      -
                                                                                                                      Selecting nodes via XPath expression
                                                                                                                      -
                                                                                                                      Using query objects
                                                                                                                      -
                                                                                                                      Using variables
                                                                                                                      -
                                                                                                                      Error handling
                                                                                                                      -
                                                                                                                      Conformance to W3C specification
                                                                                                                      +

                                                                                                                      If the task at hand is to select a subset of document nodes that match some @@ -48,7 +48,7 @@ for these cases. pugixml implements an almost complete subset of XPath 1.0. Because of differences in document object model and some performance implications, there are minor violations of the official specifications, which can be found - in Conformance to W3C specification. The rest of this section describes the interface for XPath + in Conformance to W3C specification. The rest of this section describes the interface for XPath functionality. Please note that if you wish to learn to use XPath language, you have to look for other tutorials or manuals; for example, you can read W3Schools XPath tutorial, @@ -58,11 +58,12 @@

                                                                                                                      -

                                                                                                                      - Each XPath expression can have one of the following types: boolean, number, - string or node set. Boolean type corresponds to bool +

                                                                                                                      + Each + XPath expression can have one of the following types: boolean, number, string + or node set. Boolean type corresponds to bool type, number type corresponds to double type, string type corresponds to either std::string or std::wstring, depending on whether wide @@ -72,11 +73,11 @@ xpath_type_number, xpath_type_string or xpath_type_node_set, accordingly.

                                                                                                                      -

                                                                                                                      - Because an XPath node can be either a node or an attribute, there is a special - type, xpath_node, which is - a discriminated union of these types. A value of this type contains two node - handles, one of xml_node +

                                                                                                                      + Because an XPath node can be either a node or an + attribute, there is a special type, xpath_node, + which is a discriminated union of these types. A value of this type contains + two node handles, one of xml_node type, and another one of xml_attribute type; at most one of them can be non-null. The accessors to get these handles are available: @@ -101,30 +102,33 @@ handle. For null nodes, parent returns null handle.

                                                                                                                      -

                                                                                                                      - Like node and attribute handles, XPath node handles can be implicitly cast - to boolean-like object to check if it is a null node, and also can be compared +

                                                                                                                      + Like + node and attribute handles, XPath node handles can be implicitly cast to + boolean-like object to check if it is a null node, and also can be compared for equality with each other.

                                                                                                                      -

                                                                                                                      - You can also create XPath nodes with one of the three constructors: the default - constructor, the constructor that takes node argument, and the constructor - that takes attribute and node arguments (in which case the attribute must - belong to the attribute list of the node). The constructor from xml_node is implicit, so you can usually - pass xml_node to functions - that expect xpath_node. Apart - from that you usually don't need to create your own XPath node objects, since - they are returned to you via selection functions. -

                                                                                                                      -

                                                                                                                      - XPath expressions operate not on single nodes, but instead on node sets. - A node set is a collection of nodes, which can be optionally ordered in either - a forward document order or a reverse one. Document order is defined in XPath - specification; an XPath node is before another node in document order if - it appears before it in XML representation of the corresponding document. -

                                                                                                                      -

                                                                                                                      - Node sets are represented by xpath_node_set +

                                                                                                                      + You can also create XPath nodes with one of + the three constructors: the default constructor, the constructor that takes + node argument, and the constructor that takes attribute and node arguments + (in which case the attribute must belong to the attribute list of the node). + The constructor from xml_node + is implicit, so you can usually pass xml_node + to functions that expect xpath_node. + Apart from that you usually don't need to create your own XPath node objects, + since they are returned to you via selection functions. +

                                                                                                                      +

                                                                                                                      + XPath expressions operate not on single nodes, + but instead on node sets. A node set is a collection of nodes, which can + be optionally ordered in either a forward document order or a reverse one. + Document order is defined in XPath specification; an XPath node is before + another node in document order if it appears before it in XML representation + of the corresponding document. +

                                                                                                                      +

                                                                                                                      + Node sets are represented by xpath_node_set object, which has an interface that resembles one of sequential random-access containers. It has an iterator type along with usual begin/past-the-end iterator accessors: @@ -133,8 +137,9 @@ const_iterator xpath_node_set::begin() const; const_iterator xpath_node_set::end() const; -

                                                                                                                      - And it also can be iterated via indices, just like std::vector: +

                                                                                                                      + And it also can be iterated via indices, just + like std::vector:

                                                                                                                      const xpath_node& xpath_node_set::operator[](size_t index) const;
                                                                                                                       size_t xpath_node_set::size() const;
                                                                                                                      @@ -147,9 +152,9 @@
                                                                                                                               set size results in undefined behavior. You can use both iterator-based and
                                                                                                                               index-based access for iteration, however the iterator-based one can be faster.
                                                                                                                             

                                                                                                                      -

                                                                                                                      - The order of iteration depends on the order of nodes inside the set; the - order can be queried via the following function: +

                                                                                                                      + The order of iteration depends on the order of + nodes inside the set; the order can be queried via the following function:

                                                                                                                      enum xpath_node_set::type_t {type_unsorted, type_sorted, type_sorted_reverse};
                                                                                                                       type_t xpath_node_set::type() const;
                                                                                                                      @@ -173,9 +178,10 @@
                                                                                                                               will return type_sorted or
                                                                                                                               type_sorted_reverse.
                                                                                                                             

                                                                                                                      -

                                                                                                                      - Often the actual iteration is not needed; instead, only the first element - in document order is required. For this, a special accessor is provided: +

                                                                                                                      + Often the actual iteration is not needed; + instead, only the first element in document order is required. For this, + a special accessor is provided:

                                                                                                                      xpath_node xpath_node_set::first() const;
                                                                                                                       
                                                                                                                      @@ -187,10 +193,11 @@ the complexity does - if the set is sorted, the complexity is constant, otherwise it is linear in the number of elements or worse.

                                                                                                                      -

                                                                                                                      - While in the majority of cases the node set is returned by XPath functions, - sometimes there is a need to manually construct a node set. For such cases, - a constructor is provided which takes an iterator range (const_iterator +

                                                                                                                      + While in the majority of cases the node + set is returned by XPath functions, sometimes there is a need to manually + construct a node set. For such cases, a constructor is provided which takes + an iterator range (const_iterator is a typedef for const xpath_node*), and an optional type:

                                                                                                                      xpath_node_set::xpath_node_set(const_iterator begin, const_iterator end, type_t type = type_unsorted);
                                                                                                                      @@ -205,11 +212,12 @@
                                                                                                                       
                                                                                                                      -

                                                                                                                      - If you want to select nodes that match some XPath expression, you can do - it with the following functions: +

                                                                                                                      + If + you want to select nodes that match some XPath expression, you can do it + with the following functions:

                                                                                                                      xpath_node xml_node::select_single_node(const char_t* query, xpath_variable_set* variables = 0) const;
                                                                                                                       xpath_node_set xml_node::select_nodes(const char_t* query, xpath_variable_set* variables = 0) const;
                                                                                                                      @@ -228,15 +236,15 @@
                                                                                                                       

                                                                                                                      If exception handling is not disabled, both functions throw xpath_exception if the query can not be compiled or if it returns a value with type other - than node set; see Error handling for details. + than node set; see Error handling for details.

                                                                                                                      -

                                                                                                                      - While compiling expressions is fast, the compilation time can introduce a - significant overhead if the same expression is used many times on small subtrees. - If you're doing many similar queries, consider compiling them into query - objects (see Using query objects for further reference). Once you get a compiled - query object, you can pass it to select functions instead of an expression - string: +

                                                                                                                      + While + compiling expressions is fast, the compilation time can introduce a significant + overhead if the same expression is used many times on small subtrees. If + you're doing many similar queries, consider compiling them into query objects + (see Using query objects for further reference). Once you get a compiled query + object, you can pass it to select functions instead of an expression string:

                                                                                                                      xpath_node xml_node::select_single_node(const xpath_query& query) const;
                                                                                                                       xpath_node_set xml_node::select_nodes(const xpath_query& query) const;
                                                                                                                      @@ -249,36 +257,36 @@
                                                                                                                               This is an example of selecting nodes using XPath expressions (samples/xpath_select.cpp):
                                                                                                                             

                                                                                                                      -

                                                                                                                      pugi::xpath_node_set tools = doc.select_nodes("/Profile/Tools/Tool[@AllowRemote='true' and @DeriveCaptionFrom='lastparam']");
                                                                                                                       
                                                                                                                      -std::cout << "Tools:";
                                                                                                                      +std::cout << "Tools:\n";
                                                                                                                       
                                                                                                                       for (pugi::xpath_node_set::const_iterator it = tools.begin(); it != tools.end(); ++it)
                                                                                                                       {
                                                                                                                           pugi::xpath_node node = *it;
                                                                                                                      -    std::cout << " " << node.node().attribute("Filename").value();
                                                                                                                      +    std::cout << node.node().attribute("Filename").value() << "\n";
                                                                                                                       }
                                                                                                                       
                                                                                                                       pugi::xpath_node build_tool = doc.select_single_node("//Tool[contains(Description, 'build system')]");
                                                                                                                       
                                                                                                                      -std::cout << "\nBuild tool: " << build_tool.node().attribute("Filename").value() << "\n";
                                                                                                                      +if (build_tool)
                                                                                                                      +    std::cout << "Build tool: " << build_tool.node().attribute("Filename").value() << "\n";
                                                                                                                       

                                                                                                                      -

                                                                                                                      - When you call select_nodes +

                                                                                                                      + When you call select_nodes with an expression string as an argument, a query object is created behind the scenes. A query object represents a compiled XPath expression. Query objects can be needed in the following circumstances:

                                                                                                                      -
                                                                                                                        +
                                                                                                                        • You can precompile expressions to query objects to save compilation time if it becomes an issue; @@ -299,23 +307,25 @@ operator and store pointers to xpath_query in the container.

                                                                                                                          -

                                                                                                                          - You can create a query object with the constructor that takes XPath expression - as an argument: +

                                                                                                                          + You can create a query object with the constructor + that takes XPath expression as an argument:

                                                                                                                          explicit xpath_query::xpath_query(const char_t* query, xpath_variable_set* variables = 0);
                                                                                                                           
                                                                                                                          -

                                                                                                                          - The expression is compiled and the compiled representation is stored in the - new query object. If compilation fails, xpath_exception - is thrown if exception handling is not disabled (see Error handling for - details). After the query is created, you can query the type of the evaluation - result using the following function: +

                                                                                                                          + The expression is compiled and the + compiled representation is stored in the new query object. If compilation + fails, xpath_exception is thrown if + exception handling is not disabled (see Error handling for details). + After the query is created, you can query the type of the evaluation result + using the following function:

                                                                                                                          xpath_value_type xpath_query::return_type() const;
                                                                                                                           
                                                                                                                          -

                                                                                                                          - You can evaluate the query using one of the following functions: +

                                                                                                                          + You + can evaluate the query using one of the following functions:

                                                                                                                          bool xpath_query::evaluate_boolean(const xpath_node& n) const;
                                                                                                                           double xpath_query::evaluate_number(const xpath_node& n) const;
                                                                                                                          @@ -330,7 +340,7 @@
                                                                                                                                   of this, evaluate_boolean,
                                                                                                                                   evaluate_number and evaluate_string always return a result,
                                                                                                                                   but evaluate_node_set results
                                                                                                                          -        in an error if the return type is not node set (see  Error handling).
                                                                                                                          +        in an error if the return type is not node set (see Error handling).
                                                                                                                                 

                                                                                                                          @@ -342,9 +352,9 @@ is equivalent to calling xpath_query("query").evaluate_node_set(node).

                                                                                                                          -

                                                                                                                          - Note that evaluate_string - function returns the STL string; as such, it's not available in PUGIXML_NO_STL +

                                                                                                                          + Note that evaluate_string function returns the STL + string; as such, it's not available in PUGIXML_NO_STL mode and also usually allocates memory. There is another string evaluation function:

                                                                                                                          @@ -357,7 +367,7 @@ is not 0, the resulting buffer is always zero-terminated. You can use this function as follows:

                                                                                                                          -
                                                                                                                            +
                                                                                                                            • First call the function with buffer = 0 @@ -376,21 +386,20 @@ This is an example of using query objects (samples/xpath_query.cpp):

                                                                                                                              -

                                                                                                                              -
                                                                                                                              // Select nodes via compiled query
                                                                                                                              -pugi::xpath_query query_remote_tools("/Profile/Tools/Tool[@AllowRemote='true']");
                                                                                                                              +
                                                                                                                              // Select nodes via compiled query
                                                                                                                              +pugi::xpath_query query_remote_tools("/Profile/Tools/Tool[@AllowRemote='true']");
                                                                                                                               
                                                                                                                               pugi::xpath_node_set tools = query_remote_tools.evaluate_node_set(doc);
                                                                                                                               std::cout << "Remote tool: ";
                                                                                                                               tools[2].node().print(std::cout);
                                                                                                                               
                                                                                                                              -// Evaluate numbers via compiled query
                                                                                                                              -pugi::xpath_query query_timeouts("sum(//Tool/@Timeout)");
                                                                                                                              +// Evaluate numbers via compiled query
                                                                                                                              +pugi::xpath_query query_timeouts("sum(//Tool/@Timeout)");
                                                                                                                               std::cout << query_timeouts.evaluate_number(doc) << std::endl;
                                                                                                                               
                                                                                                                              -// Evaluate strings via compiled query for different context nodes
                                                                                                                              -pugi::xpath_query query_name_valid("string-length(substring-before(@Filename, '_')) > 0 and @OutputFileMasks");
                                                                                                                              +// Evaluate strings via compiled query for different context nodes
                                                                                                                              +pugi::xpath_query query_name_valid("string-length(substring-before(@Filename, '_')) > 0 and @OutputFileMasks");
                                                                                                                               pugi::xpath_query query_name("concat(substring-before(@Filename, '_'), ' produces ', @OutputFileMasks)");
                                                                                                                               
                                                                                                                               for (pugi::xml_node tool = doc.first_element_by_path("Profile/Tools/Tool"); tool; tool = tool.next_sibling())
                                                                                                                              @@ -405,7 +414,7 @@
                                                                                                                               

                                                                                                                            XPath queries may contain references to variables; this is useful if you @@ -438,12 +447,13 @@ that the lifetime of the set exceeds that of query object.

                                                                                                                      -

                                                                                                                      - Variable sets correspond to xpath_variable_set - type, which is essentially a variable container. +

                                                                                                                      + Variable sets correspond to xpath_variable_set type, which is essentially + a variable container.

                                                                                                                      -

                                                                                                                      - You can add new variables with the following function: +

                                                                                                                      + You can add new variables with the + following function:

                                                                                                                      xpath_variable* xpath_variable_set::add(const char_t* name, xpath_value_type type);
                                                                                                                       
                                                                                                                      @@ -460,8 +470,9 @@ 0 for numbers, false for booleans, empty string for strings and empty set for node sets.

                                                                                                                      -

                                                                                                                      - You can get the existing variables with the following functions: +

                                                                                                                      + You can get the existing variables + with the following functions:

                                                                                                                      xpath_variable* xpath_variable_set::get(const char_t* name);
                                                                                                                       const xpath_variable* xpath_variable_set::get(const char_t* name) const;
                                                                                                                      @@ -470,13 +481,14 @@
                                                                                                                               The functions return the variable handle, or null pointer if the variable
                                                                                                                               with the specified name is not found.
                                                                                                                             

                                                                                                                      -

                                                                                                                      - Additionally, there are the helper functions for setting the variable value - by name; they try to add the variable with the corresponding type, if it - does not exist, and to set the value. If the variable with the same name - but with different type is already present, they return false; - they also return false on allocation - failure. Note that these functions do not perform any type conversions. +

                                                                                                                      + Additionally, there are the helper + functions for setting the variable value by name; they try to add the variable + with the corresponding type, if it does not exist, and to set the value. + If the variable with the same name but with different type is already present, + they return false; they also + return false on allocation failure. + Note that these functions do not perform any type conversions.

                                                                                                                      bool xpath_variable_set::set(const char_t* name, bool value);
                                                                                                                       bool xpath_variable_set::set(const char_t* name, double value);
                                                                                                                      @@ -487,14 +499,15 @@
                                                                                                                               The variable values are copied to the internal variable storage, so you can
                                                                                                                               modify or destroy them after the functions return.
                                                                                                                             

                                                                                                                      -

                                                                                                                      - If setting variables by name is not efficient enough, or if you have to inspect - variable information or get variable values, you can use variable handles. - A variable corresponds to the xpath_variable - type, and a variable handle is simply a pointer to xpath_variable. +

                                                                                                                      + If setting variables by name is not efficient + enough, or if you have to inspect variable information or get variable values, + you can use variable handles. A variable corresponds to the xpath_variable type, and a variable handle + is simply a pointer to xpath_variable.

                                                                                                                      -

                                                                                                                      - In order to get variable information, you can use one of the following functions: +

                                                                                                                      + In + order to get variable information, you can use one of the following functions:

                                                                                                                      const char_t* xpath_variable::name() const;
                                                                                                                       xpath_value_type xpath_variable::type() const;
                                                                                                                      @@ -503,8 +516,9 @@
                                                                                                                               Note that each variable has a distinct type which is specified upon variable
                                                                                                                               creation and can not be changed later.
                                                                                                                             

                                                                                                                      -

                                                                                                                      - In order to get variable value, you should use one of the following functions, +

                                                                                                                      + In + order to get variable value, you should use one of the following functions, depending on the variable type:

                                                                                                                      bool xpath_variable::get_boolean() const;
                                                                                                                      @@ -517,9 +531,9 @@
                                                                                                                               are performed; if the type mismatch occurs, a dummy value is returned (false for booleans, NaN
                                                                                                                               for numbers, empty string for strings and empty set for node sets).
                                                                                                                             

                                                                                                                      -

                                                                                                                      - In order to set variable value, you should use one of the following functions, - depending on the variable type: +

                                                                                                                      + In order to set variable value, you should + use one of the following functions, depending on the variable type:

                                                                                                                      bool xpath_variable::set(bool value);
                                                                                                                       bool xpath_variable::set(double value);
                                                                                                                      @@ -536,10 +550,9 @@
                                                                                                                               This is an example of using variables in XPath queries (samples/xpath_variables.cpp):
                                                                                                                             

                                                                                                                      -

                                                                                                                      -
                                                                                                                      // Select nodes via compiled query
                                                                                                                      -pugi::xpath_variable_set vars;
                                                                                                                      +
                                                                                                                      // Select nodes via compiled query
                                                                                                                      +pugi::xpath_variable_set vars;
                                                                                                                       vars.add("remote", pugi::xpath_type_boolean);
                                                                                                                       
                                                                                                                       pugi::xpath_query query_remote_tools("/Profile/Tools/Tool[@AllowRemote = string($remote)]", &vars);
                                                                                                                      @@ -556,8 +569,8 @@
                                                                                                                       std::cout << "Local tool: ";
                                                                                                                       tools_local[0].node().print(std::cout);
                                                                                                                       
                                                                                                                      -// You can pass the context directly to select_nodes/select_single_node
                                                                                                                      -pugi::xpath_node_set tools_local_imm = doc.select_nodes("/Profile/Tools/Tool[@AllowRemote = string($remote)]", &vars);
                                                                                                                      +// You can pass the context directly to select_nodes/select_single_node
                                                                                                                      +pugi::xpath_node_set tools_local_imm = doc.select_nodes("/Profile/Tools/Tool[@AllowRemote = string($remote)]", &vars);
                                                                                                                       
                                                                                                                       std::cout << "Local tool imm: ";
                                                                                                                       tools_local_imm[0].node().print(std::cout);
                                                                                                                      @@ -567,7 +580,7 @@
                                                                                                                       
                                                                                                                       

                                                                                                                      There are two different mechanisms for error handling in XPath implementation; @@ -575,21 +588,23 @@ is controlled with PUGIXML_NO_EXCEPTIONS define).

                                                                                                                      -

                                                                                                                      - By default, XPath functions throw xpath_exception - object in case of errors; additionally, in the event any memory allocation - fails, an std::bad_alloc exception is thrown. Also xpath_exception is thrown if the query - is evaluated to a node set, but the return type is not node set. If the query - constructor succeeds (i.e. no exception is thrown), the query object is valid. - Otherwise you can get the error details via one of the following functions: +

                                                                                                                      + By default, XPath functions throw xpath_exception object in case of errors; + additionally, in the event any memory allocation fails, an std::bad_alloc + exception is thrown. Also xpath_exception + is thrown if the query is evaluated to a node set, but the return type is + not node set. If the query constructor succeeds (i.e. no exception is thrown), + the query object is valid. Otherwise you can get the error details via one + of the following functions:

                                                                                                                      virtual const char* xpath_exception::what() const throw();
                                                                                                                       const xpath_parse_result& xpath_exception::result() const;
                                                                                                                       
                                                                                                                      -

                                                                                                                      - If exceptions are disabled, then in the event of parsing failure the query - is initialized to invalid state; you can test if the query object is valid - by using it in a boolean expression: if +

                                                                                                                      + If + exceptions are disabled, then in the event of parsing failure the query is + initialized to invalid state; you can test if the query object is valid by + using it in a boolean expression: if (query) { ... }. Additionally, you can get parsing result via the result() accessor: @@ -602,8 +617,9 @@ a query as a node set results in an empty node set if the return type is not node set.

                                                                                                                      -

                                                                                                                      - The information about parsing result is returned via xpath_parse_result +

                                                                                                                      + The information about parsing result is + returned via xpath_parse_result object. It contains parsing status and the offset of last successfully parsed character from the beginning of the source stream:

                                                                                                                      @@ -616,39 +632,39 @@ const char* description() const; };
                                                                                                                      -

                                                                                                                      - Parsing result is represented as the error message; it is either a null pointer, - in case there is no error, or the error message in the form of ASCII zero-terminated - string. +

                                                                                                                      + Parsing result is represented as + the error message; it is either a null pointer, in case there is no error, + or the error message in the form of ASCII zero-terminated string.

                                                                                                                      -

                                                                                                                      - description() - member function can be used to get the error message; it never returns the - null pointer, so you can safely use description() even if query parsing succeeded. Note that +

                                                                                                                      + description() member function can be used to get the + error message; it never returns the null pointer, so you can safely use description() - returns a char string even in - PUGIXML_WCHAR_MODE; you'll - have to call as_wide to get the wchar_t string. + even if query parsing succeeded. Note that description() returns a char + string even in PUGIXML_WCHAR_MODE; + you'll have to call as_wide to get the wchar_t string.

                                                                                                                      -

                                                                                                                      - In addition to the error message, parsing result has an offset +

                                                                                                                      + In addition to the error message, + parsing result has an offset member, which contains the offset of last successfully parsed character. This offset is in units of pugi::char_t (bytes for character mode, wide characters for wide character mode).

                                                                                                                      -

                                                                                                                      - Parsing result object can be implicitly converted to bool - like this: if (result) { ... } +

                                                                                                                      + Parsing result object can be implicitly + converted to bool like this: + if (result) { ... } else { ... }.

                                                                                                                      This is an example of XPath error handling (samples/xpath_error.cpp):

                                                                                                                      -

                                                                                                                      -
                                                                                                                      // Exception is thrown for incorrect query syntax
                                                                                                                      -try
                                                                                                                      +
                                                                                                                      // Exception is thrown for incorrect query syntax
                                                                                                                      +try
                                                                                                                       {
                                                                                                                           doc.select_nodes("//nodes[#true()]");
                                                                                                                       }
                                                                                                                      @@ -657,8 +673,8 @@
                                                                                                                           std::cout << "Select failed: " << e.what() << std::endl;
                                                                                                                       }
                                                                                                                       
                                                                                                                      -// Exception is thrown for incorrect query semantics
                                                                                                                      -try
                                                                                                                      +// Exception is thrown for incorrect query semantics
                                                                                                                      +try
                                                                                                                       {
                                                                                                                           doc.select_nodes("(123)/next");
                                                                                                                       }
                                                                                                                      @@ -667,8 +683,8 @@
                                                                                                                           std::cout << "Select failed: " << e.what() << std::endl;
                                                                                                                       }
                                                                                                                       
                                                                                                                      -// Exception is thrown for query with incorrect return type
                                                                                                                      -try
                                                                                                                      +// Exception is thrown for query with incorrect return type
                                                                                                                      +try
                                                                                                                       {
                                                                                                                           doc.select_nodes("123");
                                                                                                                       }
                                                                                                                      @@ -682,18 +698,18 @@
                                                                                                                       
                                                                                                                       

                                                                                                                      Because of the differences in document object models, performance considerations and implementation complexity, pugixml does not provide a fully conformant XPath 1.0 implementation. This is the current list of incompatibilities:

                                                                                                                      -
                                                                                                                        +
                                                                                                                        • Consecutive text nodes sharing the same parent are not merged, i.e. in <node>text1 - <![CDATA[data]]> text2</node> node should have one text node children, + <![CDATA[data]]> text2</node> node should have one text node child, but instead has three.
                                                                                                                        • @@ -721,7 +737,7 @@
                                                                                                                        - @@ -729,7 +745,7 @@
                                                                                                                        -pugixml 1.2 manual | +pugixml 1.4 manual | Overview | Installation | Document: diff --git a/docs/quickstart.html b/docs/quickstart.html index 6afd25d..8f8fa4e 100644 --- a/docs/quickstart.html +++ b/docs/quickstart.html @@ -1,31 +1,31 @@ -pugixml 1.2 +pugixml 1.4 - - + +

                                                                                                                        No documentation is perfect, neither is this one. If you encounter a description - that is unclear, please file an issue as described in Feedback. Also if + that is unclear, please file an issue as described in Feedback. Also if you can spare the time for a full proof-reading, including spelling and grammar, that would be great! Please send me an e-mail; as a token of appreciation, your name will be included into the corresponding @@ -69,14 +69,14 @@

                                                                                                                        pugixml is distributed in source form. You can download a source distribution via one of the following links:

                                                                                                                        -
                                                                                                                        http://pugixml.googlecode.com/files/pugixml-1.2.zip
                                                                                                                        -http://pugixml.googlecode.com/files/pugixml-1.2.tar.gz
                                                                                                                        +
                                                                                                                        https://github.com/zeux/pugixml/releases/download/v1.4/pugixml-1.4.zip
                                                                                                                        +https://github.com/zeux/pugixml/releases/download/v1.4/pugixml-1.4.tar.gz
                                                                                                                         

                                                                                                                        The distribution contains library source, documentation (the guide you're @@ -100,7 +100,7 @@ The easiest way to build pugixml is to compile the source file, pugixml.cpp, along with the existing library/executable. This process depends on the method of building your application; for example, if you're using Microsoft Visual - Studio[1], + Studio[1], Apple Xcode, Code::Blocks or any other IDE, just add pugixml.cpp to one of your projects. There are other building methods available, including building pugixml as a standalone static/shared library; read @@ -109,7 +109,7 @@

                                                                                                                        pugixml stores XML data in DOM-like way: the entire XML document (both document @@ -132,7 +132,7 @@

                                                                                                                        The most common node types are:

                                                                                                                        -
                                                                                                                          +
                                                                                                                          • Document node (node_document) - this is the root of the tree, which consists of several child nodes. @@ -226,7 +226,7 @@

                                                                                                                          pugixml provides several functions for loading XML data from various places @@ -250,7 +250,6 @@ This is an example of loading XML document from file (samples/load_file.cpp):

                                                                                                                          -

                                                                                                                          pugi::xml_document doc;
                                                                                                                           
                                                                                                                          @@ -282,7 +281,6 @@
                                                                                                                                   This is an example of handling loading errors (samples/load_error_handling.cpp):
                                                                                                                                 

                                                                                                                          -

                                                                                                                          pugi::xml_document doc;
                                                                                                                           pugi::xml_parse_result result = doc.load(source);
                                                                                                                          @@ -324,7 +322,6 @@
                                                                                                                                   read the sample code for more examples:
                                                                                                                                 

                                                                                                                          -

                                                                                                                          const char source[] = "<mesh name='sphere'><bounds>0 0 1 1</bounds></mesh>";
                                                                                                                           size_t size = sizeof(source);
                                                                                                                          @@ -332,17 +329,16 @@
                                                                                                                           

                                                                                                                          -

                                                                                                                          -
                                                                                                                          // You can use load_buffer_inplace to load document from mutable memory block; the block's lifetime must exceed that of document
                                                                                                                          -char* buffer = new char[size];
                                                                                                                          +
                                                                                                                          // You can use load_buffer_inplace to load document from mutable memory block; the block's lifetime must exceed that of document
                                                                                                                          +char* buffer = new char[size];
                                                                                                                           memcpy(buffer, source, size);
                                                                                                                           
                                                                                                                          -// The block can be allocated by any method; the block is modified during parsing
                                                                                                                          -pugi::xml_parse_result result = doc.load_buffer_inplace(buffer, size);
                                                                                                                          +// The block can be allocated by any method; the block is modified during parsing
                                                                                                                          +pugi::xml_parse_result result = doc.load_buffer_inplace(buffer, size);
                                                                                                                           
                                                                                                                          -// You have to destroy the block yourself after the document is no longer used
                                                                                                                          -delete[] buffer;
                                                                                                                          +// You have to destroy the block yourself after the document is no longer used
                                                                                                                          +delete[] buffer;
                                                                                                                           

                                                                                                                          @@ -352,7 +348,6 @@ the sample code for more complex examples involving wide streams and locales:

                                                                                                                          -

                                                                                                                          std::ifstream stream("weekly-utf-8.xml");
                                                                                                                           pugi::xml_parse_result result = doc.load(stream);
                                                                                                                          @@ -362,7 +357,7 @@
                                                                                                                           

                                                                                                                          pugixml features an extensive interface for getting various types of data @@ -377,7 +372,7 @@ or an empty string if name/value is absent or if the handle is null. Also there are two notable things for reading values:

                                                                                                                          -
                                                                                                                            +
                                                                                                                            • It is common to store data as text contents of some node - i.e. <node><description>This is a @@ -399,7 +394,6 @@ This is an example of using these functions (samples/traverse_base.cpp):

                                                                                                                              -

                                                                                                                              for (pugi::xml_node tool = tools.child("Tool"); tool; tool = tool.next_sibling("Tool"))
                                                                                                                               {
                                                                                                                              @@ -420,7 +414,6 @@
                                                                                                                                       functions (samples/traverse_base.cpp):
                                                                                                                                     

                                                                                                                              -

                                                                                                                              std::cout << "Tool for *.dae generation: " << tools.find_child_by_attribute("Tool", "OutputFileMasks", "*.dae").attribute("Filename").value() << "\n";
                                                                                                                               
                                                                                                                              @@ -445,7 +438,6 @@
                                                                                                                                       Here is an example of using iterators for document traversal (samples/traverse_iter.cpp):
                                                                                                                                     

                                                                                                                              -

                                                                                                                              for (pugi::xml_node_iterator it = tools.begin(); it != tools.end(); ++it)
                                                                                                                               {
                                                                                                                              @@ -474,7 +466,6 @@
                                                                                                                                       (samples/traverse_rangefor.cpp):
                                                                                                                                     

                                                                                                                              -

                                                                                                                              for (pugi::xml_node tool: tools.children("Tool"))
                                                                                                                               {
                                                                                                                              @@ -508,24 +499,22 @@
                                                                                                                                       This is an example of traversing tree hierarchy with xml_tree_walker (samples/traverse_walker.cpp):
                                                                                                                                     

                                                                                                                              -

                                                                                                                              struct simple_walker: pugi::xml_tree_walker
                                                                                                                               {
                                                                                                                                   virtual bool for_each(pugi::xml_node& node)
                                                                                                                                   {
                                                                                                                              -        for (int i = 0; i < depth(); ++i) std::cout << "  "; // indentation
                                                                                                                              -
                                                                                                                              +        for (int i = 0; i < depth(); ++i) std::cout << "  "; // indentation
                                                                                                                              +
                                                                                                                                       std::cout << node_types[node.type()] << ": name='" << node.name() << "', value='" << node.value() << "'\n";
                                                                                                                               
                                                                                                                              -        return true; // continue traversal
                                                                                                                              -    }
                                                                                                                              +        return true; // continue traversal
                                                                                                                              +    }
                                                                                                                               };
                                                                                                                               

                                                                                                                              -

                                                                                                                              simple_walker walker;
                                                                                                                               doc.traverse(walker);
                                                                                                                              @@ -539,21 +528,21 @@
                                                                                                                                       examples:
                                                                                                                                     

                                                                                                                              -

                                                                                                                              pugi::xpath_node_set tools = doc.select_nodes("/Profile/Tools/Tool[@AllowRemote='true' and @DeriveCaptionFrom='lastparam']");
                                                                                                                               
                                                                                                                              -std::cout << "Tools:";
                                                                                                                              +std::cout << "Tools:\n";
                                                                                                                               
                                                                                                                               for (pugi::xpath_node_set::const_iterator it = tools.begin(); it != tools.end(); ++it)
                                                                                                                               {
                                                                                                                                   pugi::xpath_node node = *it;
                                                                                                                              -    std::cout << " " << node.node().attribute("Filename").value();
                                                                                                                              +    std::cout << node.node().attribute("Filename").value() << "\n";
                                                                                                                               }
                                                                                                                               
                                                                                                                               pugi::xpath_node build_tool = doc.select_single_node("//Tool[contains(Description, 'build system')]");
                                                                                                                               
                                                                                                                              -std::cout << "\nBuild tool: " << build_tool.node().attribute("Filename").value() << "\n";
                                                                                                                              +if (build_tool)
                                                                                                                              +    std::cout << "Build tool: " << build_tool.node().attribute("Filename").value() << "\n";
                                                                                                                               

                                                                                                                              @@ -570,7 +559,7 @@

                                                                                                                            The document in pugixml is fully mutable: you can completely change the document @@ -601,38 +590,36 @@ example of setting node/attribute name and value (samples/modify_base.cpp):

                                                                                                                            -

                                                                                                                            pugi::xml_node node = doc.child("node");
                                                                                                                             
                                                                                                                            -// change node name
                                                                                                                            -std::cout << node.set_name("notnode");
                                                                                                                            +// change node name
                                                                                                                            +std::cout << node.set_name("notnode");
                                                                                                                             std::cout << ", new node name: " << node.name() << std::endl;
                                                                                                                             
                                                                                                                            -// change comment text
                                                                                                                            -std::cout << doc.last_child().set_value("useless comment");
                                                                                                                            +// change comment text
                                                                                                                            +std::cout << doc.last_child().set_value("useless comment");
                                                                                                                             std::cout << ", new comment text: " << doc.last_child().value() << std::endl;
                                                                                                                             
                                                                                                                            -// we can't change value of the element or name of the comment
                                                                                                                            -std::cout << node.set_value("1") << ", " << doc.last_child().set_name("2") << std::endl;
                                                                                                                            +// we can't change value of the element or name of the comment
                                                                                                                            +std::cout << node.set_value("1") << ", " << doc.last_child().set_name("2") << std::endl;
                                                                                                                             

                                                                                                                            -

                                                                                                                            pugi::xml_attribute attr = node.attribute("id");
                                                                                                                             
                                                                                                                            -// change attribute name/value
                                                                                                                            -std::cout << attr.set_name("key") << ", " << attr.set_value("345");
                                                                                                                            +// change attribute name/value
                                                                                                                            +std::cout << attr.set_name("key") << ", " << attr.set_value("345");
                                                                                                                             std::cout << ", new attribute: " << attr.name() << "=" << attr.value() << std::endl;
                                                                                                                             
                                                                                                                            -// we can use numbers or booleans
                                                                                                                            -attr.set_value(1.234);
                                                                                                                            +// we can use numbers or booleans
                                                                                                                            +attr.set_value(1.234);
                                                                                                                             std::cout << "new attribute value: " << attr.value() << std::endl;
                                                                                                                             
                                                                                                                            -// we can also use assignment operators for more concise code
                                                                                                                            -attr = true;
                                                                                                                            +// we can also use assignment operators for more concise code
                                                                                                                            +attr = true;
                                                                                                                             std::cout << "final attribute value: " << attr.value() << std::endl;
                                                                                                                             

                                                                                                                            @@ -662,20 +649,19 @@ This is an example of adding new attributes/nodes to the document (samples/modify_add.cpp):

                                                                                                                            -

                                                                                                                            -
                                                                                                                            // add node with some name
                                                                                                                            -pugi::xml_node node = doc.append_child("node");
                                                                                                                            +
                                                                                                                            // add node with some name
                                                                                                                            +pugi::xml_node node = doc.append_child("node");
                                                                                                                             
                                                                                                                            -// add description node with text child
                                                                                                                            -pugi::xml_node descr = node.append_child("description");
                                                                                                                            +// add description node with text child
                                                                                                                            +pugi::xml_node descr = node.append_child("description");
                                                                                                                             descr.append_child(pugi::node_pcdata).set_value("Simple node");
                                                                                                                             
                                                                                                                            -// add param node before the description
                                                                                                                            -pugi::xml_node param = node.insert_child_before("param", descr);
                                                                                                                            +// add param node before the description
                                                                                                                            +pugi::xml_node param = node.insert_child_before("param", descr);
                                                                                                                             
                                                                                                                            -// add attributes to param node
                                                                                                                            -param.append_attribute("name") = "version";
                                                                                                                            +// add attributes to param node
                                                                                                                            +param.append_attribute("name") = "version";
                                                                                                                             param.append_attribute("value") = 1.1;
                                                                                                                             param.insert_attribute_after("type", param.attribute("name")) = "float";
                                                                                                                             
                                                                                                                            @@ -695,18 +681,17 @@ This is an example of removing attributes/nodes from the document (samples/modify_remove.cpp):

                                                                                                                            -

                                                                                                                            -
                                                                                                                            // remove description node with the whole subtree
                                                                                                                            -pugi::xml_node node = doc.child("node");
                                                                                                                            +
                                                                                                                            // remove description node with the whole subtree
                                                                                                                            +pugi::xml_node node = doc.child("node");
                                                                                                                             node.remove_child("description");
                                                                                                                             
                                                                                                                            -// remove id attribute
                                                                                                                            -pugi::xml_node param = node.child("param");
                                                                                                                            +// remove id attribute
                                                                                                                            +pugi::xml_node param = node.child("param");
                                                                                                                             param.remove_attribute("value");
                                                                                                                             
                                                                                                                            -// we can also remove nodes/attributes by handles
                                                                                                                            -pugi::xml_attribute id = param.attribute("name");
                                                                                                                            +// we can also remove nodes/attributes by handles
                                                                                                                            +pugi::xml_attribute id = param.attribute("name");
                                                                                                                             param.remove_attribute(id);
                                                                                                                             

                                                                                                                            @@ -714,7 +699,7 @@

                                                                                                                            Often after creating a new document or loading the existing one and processing @@ -739,10 +724,9 @@ of saving XML document to file (samples/save_file.cpp):

                                                                                                                            -

                                                                                                                            -
                                                                                                                            // save document to file
                                                                                                                            -std::cout << "Saving result: " << doc.save_file("save_file_output.xml") << std::endl;
                                                                                                                            +
                                                                                                                            // save document to file
                                                                                                                            +std::cout << "Saving result: " << doc.save_file("save_file_output.xml") << std::endl;
                                                                                                                             

                                                                                                                            @@ -759,10 +743,9 @@ This is a simple example of saving XML document to standard output (samples/save_stream.cpp):

                                                                                                                            -

                                                                                                                            -
                                                                                                                            // save document to standard output
                                                                                                                            -std::cout << "Document:\n";
                                                                                                                            +
                                                                                                                            // save document to standard output
                                                                                                                            +std::cout << "Document:\n";
                                                                                                                             doc.save(std::cout);
                                                                                                                             

                                                                                                                            @@ -782,7 +765,6 @@ read the sample code for more complex examples:

                                                                                                                            -

                                                                                                                            struct xml_string_writer: pugi::xml_writer
                                                                                                                             {
                                                                                                                            @@ -807,7 +789,7 @@
                                                                                                                             

                                                                                                                            If you believe you've found a bug in pugixml, please file an issue via issue submission form. @@ -816,21 +798,21 @@ that uses pugixml and exhibits the bug, etc. Feature requests and contributions can be filed as issues, too.

                                                                                                                            -

                                                                                                                            - If filing an issue is not possible due to privacy or other concerns, you - can contact pugixml author by e-mail directly: arseny.kapoulkine@gmail.com. +

                                                                                                                            + If filing an issue is not possible due to privacy or + other concerns, you can contact pugixml author by e-mail directly: arseny.kapoulkine@gmail.com.

                                                                                                                            The pugixml library is distributed under the MIT license:

                                                                                                                            - Copyright (c) 2006-2012 Arseny Kapoulkine + Copyright (c) 2006-2014 Arseny Kapoulkine

                                                                                                                            Permission is hereby granted, free of charge, to any person obtaining a @@ -862,17 +844,17 @@

                                                                                                                            This software is based on pugixml library (http://pugixml.org).
                                                                                                                            pugixml - is Copyright (C) 2006-2012 Arseny Kapoulkine. + is Copyright (C) 2006-2014 Arseny Kapoulkine.

                                                                                                                            -

                                                                                                                            -

                                                                                                                            [1] All trademarks used are properties of their respective owners.

                                                                                                                            +

                                                                                                                            +

                                                                                                                            [1] All trademarks used are properties of their respective owners.

                                                                                                                          - +

                                                                                                                          Last revised: April 30, 2012 at 03:25:55 GMT

                                                                                                                          Last revised: February 28, 2014 at 03:52:54 GMT

                                                                                                                          -- cgit v1.2.3