falcong / pugixml

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

Adding elements to the node class #110

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Use this request type if there is something you need to do with pugixml and
you don't know how.

What do you need to do with pugixml? Please provide a description of the
problem along with sample usage scenario.

Is it possible to add more parameters to the xml_node class? if yes, where do I 
make the modifications? I wanted to add 2 ints 'left' and 'right'. I tried 
modifying class PUGIXML_CLASS xml_node in pugixml.hpp and adding these to 
constructor in .cpp file. But something is not right. Values are not getting 
initialized via the constructor.

Original issue reported on code.google.com by devesh...@gmail.com on 22 Jun 2011 at 11:47

GoogleCodeExporter commented 9 years ago
xml_node is a handle class; you can have many xml_node instances for the same 
tree node. If you want to associate additional data with a tree node, it has to 
go to xml_node_struct.

What are 'left' and 'right' supposed to mean? For compatibility reasons you're 
discouraged to modify pugixml sources; it's likely that there is an alternative 
way to solve your problem.

Original comment by arseny.k...@gmail.com on 23 Jun 2011 at 12:06

GoogleCodeExporter commented 9 years ago
I am trying to implement Nested 
Set(http://en.wikipedia.org/wiki/Nested_set_model), for my XML data to be 
stored in MySQL. For that I would need a left and right value associated with 
every xml_node. Please suggest if you can think of any alternative to achieve 
this.

Original comment by devesh...@gmail.com on 23 Jun 2011 at 12:34

GoogleCodeExporter commented 9 years ago
Well, you can always store left/right indices externally, via something like

struct sql_binding_data { int left; int right; int depth; };
std::map<pugi::xml_node, sql_binding_data> sqlbd;

Since the tree in the DB is pretty much static anyway (changing the tree 
structure will require updating 50% of DB on average, AFAICS), you don't even 
need to keep this map up-to-date on node insertions/deletions because you don't 
want to be doing the DB update for them except in huge batches anyway. And that 
way the data that's rarely updated (left/right indices) & can become stale is 
separated from the actual document structure.

Original comment by arseny.k...@gmail.com on 23 Jun 2011 at 6:07

GoogleCodeExporter commented 9 years ago
Thanks for the help moderator.
I was using the xml_tree_walker, trying to parse and extract the data from 
multiple XMLs. Is there a way I could implement a different walker function for 
every different xml file in my system?
Say XML file1 uses walker1 function and file2 uses walker2 function? 

Original comment by devesh...@gmail.com on 24 Jun 2011 at 9:07

GoogleCodeExporter commented 9 years ago
You'll have to implement separate classes; of course, you can call 
walker1/walker2 functions from tree_walker1::for_each & tree_walker2::for_each.

Alternatively, you can manually traverse the tree with a recursive function.

Original comment by arseny.k...@gmail.com on 26 Jun 2011 at 1:41

GoogleCodeExporter commented 9 years ago
Closing the issue; if there's anything else, feel free to update it and I'll 
reopen it.

Original comment by arseny.k...@gmail.com on 9 Jul 2011 at 1:05