Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » XML , DOM - Modify the tree
XML , DOM - Modify the tree [message #12133] Fri, 12 October 2007 11:15 Go to next message
pippo is currently offline  pippo
Messages: 17
Registered: October 2007
Location: Italy
Promising Member
hallo, I'm a newbe.
I need read a XML file and modify it.

I've seen the addressBookXML2. this example read a file and ,to rewrite it, re-CREATES ALL structure: starts from a new XmlNode object and fill it with Add().
This because function Node(int) returns a const XmlNode object.

But my XML files is very complex and I need modify only 1 value.

Why the dom-generated-tree is read only????
There's a function to modify it?

...Or copy some integer-block (nodes) to another tree, so I can create a new object and fill with copy... Very Happy




10aa3a8774daeb994a88cc07572e2b6c
Re: XML , DOM - Modify the tree [message #12135 is a reply to message #12133] Fri, 12 October 2007 11:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
pippo wrote on Fri, 12 October 2007 05:15

hallo, I'm a newbe.
I need read a XML file and modify it.

I've seen the addressBookXML2. this example read a file and ,to rewrite it, re-CREATES ALL structure: starts from a new XmlNode object and fill it with Add().
This because function Node(int) returns a const XmlNode object.

But my XML files is very complex and I need modify only 1 value.

Why the dom-generated-tree is read only????
There's a function to modify it?

...Or copy some integer-block (nodes) to another tree, so I can create a new object and fill with copy... Very Happy





You can use following methods to modify XmlNode:

	XmlNode&       Add()                                      { return node.Add(); }
	void           AddText(const String& txt)                 { Add().CreateText(txt); }
	int            FindTag(const char *tag) const;
	XmlNode&       Add(const char *tag);
	XmlNode&       GetAdd(const char *tag);
	XmlNode&       operator()(const char *tag)                { return GetAdd(tag); }
	void           Remove(const char *tag);


Basically, it is only about using () instead of []...

Mirek
Re: XML , DOM - Modify the tree [message #12141 is a reply to message #12135] Fri, 12 October 2007 16:10 Go to previous messageGo to next message
pippo is currently offline  pippo
Messages: 17
Registered: October 2007
Location: Italy
Promising Member
luzr wrote on Fri, 12 October 2007 11:44



You can use following methods to modify XmlNode:




YES! I've discovered these just 15 minutes ago... Smile
At() methods is very nice, also.

---
Now I need to swap 2 nodes with all their sub-nodes. And/or insert a node between other nodes in a precise position (no append at end).

BEFORE:
<EatInSequence>
   <module>
      <thing value= "spaghetti"/>
   </module>
   <module>
      <thing value= "pizza"/>
   </module>
   <module>
      <thing value= "cheese cake"/>
   </module>
</EatInSequence>

AFTER:
<EatInSequence>
   <module>
      <thing value= "spaghetti"/>
   </module>
   <module>
      <thing value= "Beer"/>
   </module>
   <module>
      <thing value= "pizza"/>
   </module>
   <module>
      <thing value= "cheese cake"/>
   </module>
</EatInSequence>


I CAN'T CHANGE ONLY THE VALUE OF ATTRIB "value" (my first idea Laughing), because this's only an exaple! In real my nodes are full of sub-nodes, then I must move sub and sub and sub nodes, too.

My onlyone solution found Embarassed is:
1) read the old xml file
2) in dom-tree insert a my tag with progressive number
3) insert new tags (in append...) and mark it with position number needed.
<EatInSequence>
   <module>
      <thing value= "spaghetti"/>
      <myTag progr = "0">
   </module>
   <module>
      <thing value= "pizza"/>
      <myTag progr = "2">
   </module>
   <module>
      <thing value= "cheese cake"/>
      <myTag progr = "3">
   </module>
   <module>
      <thing value= "beer"/>
      <myTag progr = "1">
   </module>
</EatInSequence>

4) create a new tree, copying the nodes in correct sequence and deleting my tags with progressive number.
5) save.
Embarassed

Have you got a better solution?


Sorry for my english.....




10aa3a8774daeb994a88cc07572e2b6c
Re: XML , DOM - Modify the tree [message #12143 is a reply to message #12141] Fri, 12 October 2007 16:53 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, you can Insert nodes, that is not a problem.

Also, Node itself has pick semantics, so Swap should work with them.

Mirek
Previous Topic: How to read file into Memory
Next Topic: How to convert String to char ?
Goto Forum:
  


Current Time: Sat May 04 08:02:15 CEST 2024

Total time taken to generate the page: 0.03697 seconds