From ef50ba81d403514b603dbff366d3e1e504f73717 Mon Sep 17 00:00:00 2001
From: "arseny.kapoulkine"
- void parse(std::istream& stream, unsigned int optmsk = parse_noset); |
_Winnie C++ Colorizer |
stream
,
read the chunk of data from the stream and parse it with provided options (optmsk
).
The stream does not have to persist after the call to the function, the lifetime of internal buffer
@@ -181,7 +181,7 @@ with stream's data is managed by pugixml.
char* parse(char* xmlstr, unsigned int optmsk = parse_noset); - |
_Winnie C++ Colorizer |
- xml_parser(std::istream& stream, unsigned int optmsk = parse_default); |
_Winnie C++ Colorizer |
- xml_parser(char* xmlstr, unsigned int optmsk = parse_default); |
_Winnie C++ Colorizer |
operator xml_node() const; xml_node document() const; - |
_Winnie C++ Colorizer |
Ok, easy part behind - now let's dive into parsing options. There is a variety of them, and you
must choose them wisely to get the needed results and the best speed/least memory overhead. At first,
@@ -262,8 +262,9 @@ is performed for PCDATA content
Default value: on
In W3C mode: off
unsigned int options() const; unsigned int options(unsigned int optmsk); - |
_Winnie C++ Colorizer |
Functions, returning the iterators to walk through children/siblings/attributes. More on that in Iterators section.
operator unspecified_bool_type() const; - |
_Winnie C++ Colorizer |
This is a safe bool-like conversion operator. You can check node's validity (if (xml_node), if (!xml_node), if (node1 && node2 && !node3 && cond1 && ...) - you get the idea) with @@ -390,13 +396,13 @@ it. bool operator>(const xml_node& r) const; bool operator<=(const xml_node& r) const; bool operator>=(const xml_node& r) const; -
Comparison operators
bool empty() const; - |
_Winnie C++ Colorizer |
if (node.empty())
is equivalent to if (!node)
Access node's properties (type, name and value). If there is no name/value, the corresponding functions return "" - they never return NULL.
@@ -412,7 +418,7 @@ return "" - they never return NULL.xml_node child(const char* name) const; xml_node child_w(const char* name) const; - |
_Winnie C++ Colorizer |
Get a child node with specified name, or xml_node() (this is an invalid node) if nothing is found
@@ -420,7 +426,7 @@ foundxml_attribute attribute(const char* name) const; xml_attribute attribute_w(const char* name) const; - |
_Winnie C++ Colorizer |
Get an attribute with specified name, or xml_attribute() (this is an invalid attribute) if nothing is found
@@ -428,7 +434,7 @@ nothing is foundxml_node sibling(const char* name) const; xml_node sibling_w(const char* name) const; - |
_Winnie C++ Colorizer |
Get a node's sibling with specified name, or xml_node() if nothing is found.
node.sibling(name)
is equivalent to node.parent().child(name)
.
These functions get the next sibling, that is, one of the siblings of that node, that is to the
right. next_sibling()
just returns the right brother of the node (or xml_node()),
@@ -447,29 +453,41 @@ the two other functions are searching for the sibling with the given name
These functions do exactly the same as next_sibling
ones, with the exception that they
search for the left siblings.
xml_node parent() const; - |
_Winnie C++ Colorizer |
Get a parent node. The parent node for the root one (the document) is considered to be the document itself.
const char* child_value() const; - |
_Winnie C++ Colorizer |
Look for the first node of type node_pcdata or node_cdata among the children of the current node and return its contents (or "" if nothing is found)
++ const char* child_value(const char* name) const; + |
This is the convenient way of looking into child's child value - that is, node.child_value(name) is equivalent to node.child(name).child_value().
+ ++ const char* child_value_w(const char* name) const; + |
This is the convenient way of looking into child's child value - that is, node.child_value_w(name) is equivalent to node.child_w(name).child_value().
+xml_attribute first_attribute() const; xml_attribute last_attribute() const; - |
_Winnie C++ Colorizer |
These functions get the first and last attributes of the node (or xml_attribute() if the node has no attributes).
@@ -477,7 +495,7 @@ has no attributes).xml_node first_child() const; xml_node last_child() const; - |
_Winnie C++ Colorizer |
These functions get the first and last children of the node (or xml_node() if the node has no children).
@@ -485,7 +503,7 @@ no children).template <typename OutputIterator> void all_elements_by_name(const char* name, OutputIterator it) const; template <typename OutputIterator> void all_elements_by_name_w(const char* name, OutputIterator it) const; - |
_Winnie C++ Colorizer |
Get all elements with the specified name in the subtree (depth-first search) and return them with the help of output iterator (i.e. std::back_inserter)
@@ -494,7 +512,7 @@ the help of output iterator (i.e. std::back_inserter) template <typename Predicate> xml_attribute find_attribute(Predicate pred) const; template <typename Predicate> xml_node find_child(Predicate pred) const; template <typename Predicate> xml_node find_element(Predicate pred) const; -Find attribute, child or a node in the subtree (find_element - depth-first search) with the help of the given predicate. Predicate should behave like a function which accepts a xml_node or @@ -514,7 +532,7 @@ or xml_attribute() is returned.
xml_node first_element_by_attribute(const char* attr_name, const char* attr_value) const; xml_node first_element_by_attribute_w(const char* attr_name, const char* attr_value) const; -Find the first node (depth-first search), which corresponds to the given criteria (i.e. either has a matching name, or a matching value, or has an attribute with given name/value, or has an attribute @@ -522,20 +540,20 @@ and has a matching name). Note that _w versions treat all parameters as w
xml_node first_node(xml_node_type type) const; - |
_Winnie C++ Colorizer |
Return a first node (depth-first search) with a given type, or xml_node().
std::string path(char delimiter = '/') const; - |
_Winnie C++ Colorizer |
Get a path of the node (i.e. the string of names of the nodes on the path from the DOM tree root to the node, separated with delimiter (/ by default).
xml_node first_element_by_path(const char* path, char delimiter = '/') const; - |
_Winnie C++ Colorizer |
Get the first element that has the following path. The path can be absolute (beginning with delimiter) or
relative, '..' means 'up-level' (so if we are at the path mesh/fragment/geometry/stream, ../..
@@ -543,7 +561,7 @@ will lead us to mesh/fragment, and /mesh will lead us to mesh
+
bool traverse(xml_tree_walker& walker) const;
-
_Winnie C++ Colorizer
Traverse the subtree (beginning with current node) with the walker, return the result. See Miscellaneous section for details.
@@ -560,19 +578,19 @@ will lead us to mesh/fragment, and /mesh will lead us to mesh bool operator>(const xml_attribute& r) const; bool operator<=(const xml_attribute& r) const; bool operator>=(const xml_attribute& r) const; -Comparison operators.
operator unspecified_bool_type() const; - |
_Winnie C++ Colorizer |
Safe bool conversion - like in xml_node, use this to check for validity.
bool empty() const; - |
_Winnie C++ Colorizer |
Like with xml_node, if (attr.empty())
is equivalent to if (!attr)
.
xml_attribute next_attribute() const; xml_attribute previous_attribute() const; - |
_Winnie C++ Colorizer |
Get the next/previous attribute of the node, that owns the current attribute. Return xml_attribute() if no such attribute is found.
@@ -588,7 +606,7 @@ if no such attribute is found.const char* name() const; const char* value() const; - |
_Winnie C++ Colorizer |
Get the name and value of the attribute. These methods never return NULL - they return "" instead.
@@ -596,14 +614,14 @@ if no such attribute is found. int as_int() const; double as_double() const; float as_float() const; -Convert the value of an attribute to the desired type. If the conversion is not successfull, return default value (0 for int, 0.0 for double, 0.0f for float). These functions rely on CRT functions ato*.
bool as_bool() const; - |
_Winnie C++ Colorizer |
Convert the value of an attribute to bool. This method returns true if the first character of the value is '1', 't', 'T', 'y' or 'Y'. Otherwise it returns false.
@@ -629,7 +647,7 @@ do something like: xml_attribute last_attrib = *(--node.attributes_end()); ... } -virtual bool begin(const xml_node&); virtual bool end(const xml_node&); - |
_Winnie C++ Colorizer |
These functions are called when the processing of the node starts/ends. First begin() is called, then all children of the node are processed recursively, then end() is called. If @@ -652,14 +670,14 @@ returns false.
virtual void push(); virtual void pop(); - |
_Winnie C++ Colorizer |
These functions are called before and after the processing of node's children. If node has no children, none of these is called. The default behavior is to increment/decrement current node depth.
virtual int depth() const; - |
_Winnie C++ Colorizer |
Get the current depth. You can use this function to do your own indentation, for example.
@@ -667,7 +685,7 @@ none of these is called. The default behavior is to increment/decrement currentbool value = node.child("stream").attribute("compress").as_bool(); - |
_Winnie C++ Colorizer |
We can also write a class that will traverse the DOM tree and store the information from nodes based on their names, depths, attributes, etc. This way is well known by the users of SAX parsers. To do that, @@ -830,7 +848,7 @@ we have to write an implementation of xml_tree_walker interface
if (!parser.document().traverse(mp)) // generate an error } -I'm always open for questions; feel free to write them to zeux@mathcentre.com. +
I'm always open for questions; feel free to write them to arseny.kapoulkine@gmail.com.
I'm always open for bug reports; feel free to write them to zeux@mathcentre.com. +
I'm always open for bug reports; feel free to write them to arseny.kapoulkine@gmail.com. Please provide as much information as possible - version of pugixml, compiling and OS environment (compiler and it's version, STL version, OS version, etc.), the description of the situation in which the bug arises, the code and data files that show the bug, etc. - the more, the better. Though, please, do not send executable files.
+Note, that you can also submit bug reports/suggestions at +project page. +
The pugixml parser is released into the public domain (though this may change).
+The pugixml parser is distributed under the MIT license:
+ ++Copyright (c) 2006 Arseny Kapoulkine + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +
Revised 15 July, 2006
-© Copyright Zeux 2006. All Rights Reserved.
+Revised 6 November, 2006
+© Copyright Arseny Kapoulkine 2006. All Rights Reserved.