falcong / pugixml

Automatically exported from code.google.com/p/pugixml
0 stars 0 forks source link

XPath query starting from attribute context #221

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
**What feature do you require in pugixml?

see summary

**What do you need this feature for?

Custom xforms implementation.  As an example, one of the complex types in 
xforms, bind, requires a reference to a node/nodeset.  The other properties of 
the bind affect form behavior.  This is an example of valid xforms that would 
give me trouble:

<xf:bind nodeset="/data/@age" constraint=". > 18" type="xs:int" />

(this says form validation would fail unless the value of /data/@age is greater 
than 18)

http://www.w3.org/MarkUp/Forms/

**If you already have a patch, please attach it to the issue.

I was able to achieve what I needed by copying the exact implementations of 
these methods into the 'xpath_node' class (since I was beginning my query from 
the result of a previous query, e.g. nodeset).

PUGI__FN xpath_node xml_node::select_single_node(const char_t* query, 
xpath_variable_set* variables) const

PUGI__FN xpath_node xml_node::select_single_node(const xpath_query& query) const

PUGI__FN xpath_node_set xml_node::select_nodes(const char_t* query, 
xpath_variable_set* variables) const

PUGI__FN xpath_node_set xml_node::select_nodes(const xpath_query& query) const

It looked to me like a better(?) way of doing it might be to have xml_attribute 
keep a reference to its parent node so that it can be easily constructed as a 
xpath_node.

Original issue reported on code.google.com by phoenixs...@gmail.com on 17 Dec 2013 at 3:10

GoogleCodeExporter commented 9 years ago
Since using attribute nodes as a context is relatively rare, to do this you 
need to use xpath_query API (which is what select_* do behind the scenes 
anyway).

I.e.:
pugi::xpath_node node(attr, attrnode);
pugi::xpath_query(". > 18").evaluate_boolean(node);

The reason why xml_attribute does not keep a parent reference is because the 
need for it is relatively rare, but the memory overhead is significant; see #127

Original comment by arseny.k...@gmail.com on 17 Dec 2013 at 4:53

GoogleCodeExporter commented 9 years ago
#127 refers to http://code.google.com/p/pugixml/issues/detail?id=127

Original comment by arseny.k...@gmail.com on 17 Dec 2013 at 4:53

GoogleCodeExporter commented 9 years ago
Closing as "Done" since the request is for a feature that already exists.

Original comment by arseny.k...@gmail.com on 20 Dec 2013 at 5:33