Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Updating an XML file from VC6.0

Updating an XML file from VC6.0

Scheduled Pinned Locked Moved XML / XSL
htmlcomxmltutorialquestion
8 Posts 5 Posters 30 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jan R Hansen
    wrote on last edited by
    #1

    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

    A J R J 4 Replies Last reply
    0
    • J Jan R 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

      A Offline
      A Offline
      act_x
      wrote on last edited by
      #2

      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 .

      1 Reply Last reply
      0
      • J Jan R 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

        J Offline
        J Offline
        James Pullicino
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • J Jan R 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

          R Offline
          R Offline
          Ranjan Banerji
          wrote on last edited by
          #4

          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.

          J 1 Reply Last reply
          0
          • R Ranjan Banerji

            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.

            J Offline
            J Offline
            Jan R Hansen
            wrote on last edited by
            #5

            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

            R 1 Reply Last reply
            0
            • J Jan R Hansen

              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

              R Offline
              R Offline
              Ranjan Banerji
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • J Jan R 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

                J Offline
                J Offline
                Jan R Hansen
                wrote on last edited by
                #7

                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

                A 1 Reply Last reply
                0
                • J Jan R 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

                  A Offline
                  A Offline
                  Anonymous
                  wrote on last edited by
                  #8

                  Read here for possible information on formatting needs: Format XML/XSL for Documentation

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups