Updating an XML file from VC6.0
-
Hi, I've just got started with XML and VC6.0 (thanks to Tom Archer : http://codeguru.earthweb.com/xml/XMLDOMFromVC.html - great explanation/tutorial !!!) and I'm wondering how I can write data back to an XML file. I use the DOM as described in the article to read data from a file to internal datastructures - but I need to update different values in my XML file after updating the datastructures. How is this done most easily ? Currently, I see two ways of doing it : writing the XML file as ascii based on the data or using the DOM to generate a file. The first I can do ;o) - but how is the latter done ? And is that the "right" way to do it ? Thanks in advance. Best regards Jan Hansen
-
Hi, I've just got started with XML and VC6.0 (thanks to Tom Archer : http://codeguru.earthweb.com/xml/XMLDOMFromVC.html - great explanation/tutorial !!!) and I'm wondering how I can write data back to an XML file. I use the DOM as described in the article to read data from a file to internal datastructures - but I need to update different values in my XML file after updating the datastructures. How is this done most easily ? Currently, I see two ways of doing it : writing the XML file as ascii based on the data or using the DOM to generate a file. The first I can do ;o) - but how is the latter done ? And is that the "right" way to do it ? Thanks in advance. Best regards Jan Hansen
u have seem to have solved the question about retrieving data. XML DOM supports for Data insertion . Additionally it is advantageous as you will follow a syntax to add data . In case the DOM object could not add data it will notify . I think that using the DOM to insert Data is the way to go about this . Also try exploring SAX .
-
Hi, I've just got started with XML and VC6.0 (thanks to Tom Archer : http://codeguru.earthweb.com/xml/XMLDOMFromVC.html - great explanation/tutorial !!!) and I'm wondering how I can write data back to an XML file. I use the DOM as described in the article to read data from a file to internal datastructures - but I need to update different values in my XML file after updating the datastructures. How is this done most easily ? Currently, I see two ways of doing it : writing the XML file as ascii based on the data or using the DOM to generate a file. The first I can do ;o) - but how is the latter done ? And is that the "right" way to do it ? Thanks in advance. Best regards Jan Hansen
Use the DOM. To set the value of an element use the same method you used to get the text, but instead set it. Finally call the save method of the DOMDocument to save your DOM as an XML file. Drinking In The Sun Forgot Password?
-
Hi, I've just got started with XML and VC6.0 (thanks to Tom Archer : http://codeguru.earthweb.com/xml/XMLDOMFromVC.html - great explanation/tutorial !!!) and I'm wondering how I can write data back to an XML file. I use the DOM as described in the article to read data from a file to internal datastructures - but I need to update different values in my XML file after updating the datastructures. How is this done most easily ? Currently, I see two ways of doing it : writing the XML file as ascii based on the data or using the DOM to generate a file. The first I can do ;o) - but how is the latter done ? And is that the "right" way to do it ? Thanks in advance. Best regards Jan Hansen
You can use DOM to both modify data ( change values of existing nodes) and to modify the structure of your XML (Add or remove nodes). DOMDocument has functions like CreatNode, CreateElement etc. Once you create a Node you can insert it or append it to an existing to node in your XML. Think of it as dealing with a tree structure. Changing the value is easier. You just set the new value. For example node.firstChild.Attributes.getNamedItem("blah").Text = "Yoooo Hoooo" This will find an attribute named blah in your node and set its text to "Yoooo Hoooo" You can try doing this yourself by editing the text but that would be reinventing the wheel. Hope this helped. You may want to look into MSDN for more precise syntax and examples.
-
You can use DOM to both modify data ( change values of existing nodes) and to modify the structure of your XML (Add or remove nodes). DOMDocument has functions like CreatNode, CreateElement etc. Once you create a Node you can insert it or append it to an existing to node in your XML. Think of it as dealing with a tree structure. Changing the value is easier. You just set the new value. For example node.firstChild.Attributes.getNamedItem("blah").Text = "Yoooo Hoooo" This will find an attribute named blah in your node and set its text to "Yoooo Hoooo" You can try doing this yourself by editing the text but that would be reinventing the wheel. Hope this helped. You may want to look into MSDN for more precise syntax and examples.
Thanks a lot ! I have looked (a little) at the "root-object", and there doesn't seem to be a "flush-to-disk" operation. During the lifetime of my application, I would like to ensure that changes to the data in the file are written - just to prevent a crash of the framework I'm working inside from deleting changes. Any idea how this is done ? Or do I have to sort of close the document? /Jan
-
Thanks a lot ! I have looked (a little) at the "root-object", and there doesn't seem to be a "flush-to-disk" operation. During the lifetime of my application, I would like to ensure that changes to the data in the file are written - just to prevent a crash of the framework I'm working inside from deleting changes. Any idea how this is done ? Or do I have to sort of close the document? /Jan
You need to look up help/documention for DOMDocument. It has a funtion called save that will save your XML. DOMDocument is where you load your XML. Then you use the nodes to manipulate the content. Then you save the DOMDocument.
-
Hi, I've just got started with XML and VC6.0 (thanks to Tom Archer : http://codeguru.earthweb.com/xml/XMLDOMFromVC.html - great explanation/tutorial !!!) and I'm wondering how I can write data back to an XML file. I use the DOM as described in the article to read data from a file to internal datastructures - but I need to update different values in my XML file after updating the datastructures. How is this done most easily ? Currently, I see two ways of doing it : writing the XML file as ascii based on the data or using the DOM to generate a file. The first I can do ;o) - but how is the latter done ? And is that the "right" way to do it ? Thanks in advance. Best regards Jan Hansen
Hi all, and thanks a lot for the help so far. I now read data, delete some data from my XML tree ,and insert some data. Then I save the data to the file I loaded it from. Everything works fine - except for the formatting. I tend to format my XML data C-like, with tabular indents etc. This is kept in the part of the XML tree not modified from C++ - but the data added from C++ is written in one long line like this blahblah - any way I can ask the XML engine to format things "my way" or a "standard way". By the way, the data not modified from C++ is getting (damn, whats the word...) truncated/fitted/"replace-one-or-more-newlines-with-only-one-newline". But tabs are kept. Any hints, oh allmighty gurus of knowledge ;o) Thanks in advance /Jan
-
Hi all, and thanks a lot for the help so far. I now read data, delete some data from my XML tree ,and insert some data. Then I save the data to the file I loaded it from. Everything works fine - except for the formatting. I tend to format my XML data C-like, with tabular indents etc. This is kept in the part of the XML tree not modified from C++ - but the data added from C++ is written in one long line like this blahblah - any way I can ask the XML engine to format things "my way" or a "standard way". By the way, the data not modified from C++ is getting (damn, whats the word...) truncated/fitted/"replace-one-or-more-newlines-with-only-one-newline". But tabs are kept. Any hints, oh allmighty gurus of knowledge ;o) Thanks in advance /Jan
Read here for possible information on formatting needs: Format XML/XSL for Documentation