xml_attribute xml_node::attribute(const char_t* name, xml_attribute& hint) const;
+From e383ce5d823a21bd82511ab9c10aa916fcc8cebd Mon Sep 17 00:00:00 2001
From: Arseny Kapoulkine
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 and permits multiple top-level element nodes. 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 and permits multiple top-level element nodes (currently multiple top-level element nodes are also permitted when the flag is off, but that behavior should not be relied on). This flag is off by default.
for (pugi::xml_node tool = tools.child("Tool"); tool; tool = tool.next_sibling("Tool"))
+attribute
function needs to look for the target attribute by name. If a node has many attributes, finding each by name can be time consuming. If you have an idea of how attributes are ordered in the node, you can use a faster function:
xml_attribute xml_node::attribute(const char_t* name, xml_attribute& hint) const;
+The extra hint
argument is used to guess where the attribute might be, and is updated to the location of the next attribute so that if you search for multiple attributes in the right order, the performance is maximized. Note that hint
has to be either null or has to belong to the node, otherwise the behavior is undefined.
You can use this function as follows:
+xml_attribute hint;
+xml_attribute id = node.attribute("id", hint);
+xml_attribute name = node.attribute("name", hint);
+xml_attribute version = node.attribute("version", hint);
+This code is correct regardless of the order of the attributes, but it’s faster if "id"
, "name"
and "version"
occur in that order.
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: