From 7e7153457722ff2272bf094cca5387bd2e2ebd71 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine@gmail.com" Date: Sun, 29 Apr 2012 22:51:21 +0000 Subject: docs: Regenerated HTML documentation git-svn-id: http://pugixml.googlecode.com/svn/trunk@908 99668b35-9821-0410-8761-19e4c4f06640 --- docs/manual/access.html | 208 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 188 insertions(+), 20 deletions(-) (limited to 'docs/manual/access.html') diff --git a/docs/manual/access.html b/docs/manual/access.html index d4b38c2..dcb072d 100644 --- a/docs/manual/access.html +++ b/docs/manual/access.html @@ -4,15 +4,15 @@ Accessing document data - - + +
-pugixml 1.0 manual | +pugixml 1.2 manual | Overview | Installation | Document: @@ -35,11 +35,13 @@
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 with predicates
+
Working with text contents
Miscellaneous functions

@@ -167,10 +169,11 @@ 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 - provides two helper functions to parse such data: + provides several helper functions to parse such data:

const char_t* xml_node::child_value() const;
 const char_t* xml_node::child_value(const char_t* name) const;
+xml_text xml_node::text() const;
 

child_value() @@ -181,6 +184,12 @@ child with relevant type, or if the handle is null, child_value functions return empty string.

+

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

There is an example of using some of these functions at the end of the next section. @@ -201,26 +210,40 @@ 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: +

+
const char_t* xml_attribute::as_string(const char_t* def = "") const;
+
+

+ It returns def argument if + 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:

-
int xml_attribute::as_int() const;
-unsigned int xml_attribute::as_uint() const;
-double xml_attribute::as_double() const;
-float xml_attribute::as_float() const;
-bool xml_attribute::as_bool() const;
+
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;
 

as_int, as_uint, as_double and as_float convert attribute values to numbers. - If attribute handle is null or attribute value is empty, 0 - is returned. 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 + 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". @@ -241,10 +264,11 @@

as_bool converts attribute - value to boolean as follows: if attribute handle is null or attribute value - is empty, false is returned. - Otherwise, true is returned - if the first character is one of '1', 't', + value to boolean as follows: if attribute handle is null, def + argument is returned (which is false + by default). If attribute value is empty, false + is returned. Otherwise, true + is returned if the first character is one of '1', 't', 'T', 'y', 'Y'. This means that strings like "true" and "yes" are recognized @@ -347,6 +371,56 @@

+

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

+
implementation-defined type xml_node::children() const;
+implementation-defined type xml_node::children(const char_t* name) const;
+implementation-defined type xml_node::attributes() const;
+
+

+ children function allows + you to enumerate all child nodes; children + function with name argument + allows you to enumerate all child nodes with a specific name; attributes function allows you to enumerate + all attributes of the node. Note that you can also use node object itself + in a range-based for construct, which is equivalent to using children(). +

+

+ This is an example of using these functions (samples/traverse_rangefor.cpp): +

+

+ +

+
for (pugi::xml_node tool: tools.children("Tool"))
+{
+    std::cout << "Tool:";
+
+    for (pugi::xml_attribute attr: tool.attributes())
+    {
+        std::cout << " " << attr.name() << "=" << attr.value();
+    }
+
+    for (pugi::xml_node child: tool.children())
+    {
+        std::cout << ", child " << child.name();
+    }
+
+    std::cout << std::endl;
+}
+
+

+

+
+
+

+ 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 + provides a special class, xml_text, + to work with such data. Working with text objects to modify data is described + 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: +

+
xml_text xml_node::text() const;
+
+

+ If the node has a type node_pcdata + or node_cdata, then the node + 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 + (!text) { ... + }. Alternatively you can check it + by using the empty() + method: +

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

+
const char_t* xml_text::get() const;
+
+

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

+
const char_t* xml_text::as_string(const char_t* def = "") const;
+int xml_text::as_int(int def = 0) const;
+unsigned int xml_text::as_uint(unsigned int def = 0) const;
+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;
+
+

+ All of the above functions have the same semantics as similar xml_attribute members: they return the + default argument if the text object is empty, they convert the text contents + 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 + values. It is bound to a node of type node_pcdata + or [node_cdata]. You can use the following function to retrieve this node: +

+
xml_node xml_text::data() const;
+
+

+ Essentially, assuming text + is an xml_text object, callling + text.get() is + equivalent to calling text.data().value(). +

+

+ This is an example of using xml_text + 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;
+std::cout << "Project visibility: " << (project.child("public").text().as_bool(/* def= */ true) ? "public" : "private") << std::endl;
+std::cout << "Project description: " << project.child("description").text().get() << std::endl;
+
+

+

+
+
+

@@ -698,7 +866,7 @@

- @@ -706,7 +874,7 @@
-pugixml 1.0 manual | +pugixml 1.2 manual | Overview | Installation | Document: -- cgit v1.2.3