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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. XML / XSL
  4. How to add a datasource as a sub node in XML file

How to add a datasource as a sub node in XML file

Scheduled Pinned Locked Moved XML / XSL
databasexmltutorial
5 Posts 3 Posters 1 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.
  • R Offline
    R Offline
    Rekha Patel
    wrote on last edited by
    #1

    Hi I have a few textbox entries that i have written to an xml file and now I have to add a datasource as its child node. Any ideas on how to achieve this. I did try WriteXml method for datasource but this does not write to the file as a child node. This is what I am trying to do The query's name and age are textbox entries and the Criteria is a part of the dataset. So i am trying to insert as child node to Any ideas will be greatly appreicated Thanks in advance :)

    D 1 Reply Last reply
    0
    • R Rekha Patel

      Hi I have a few textbox entries that i have written to an xml file and now I have to add a datasource as its child node. Any ideas on how to achieve this. I did try WriteXml method for datasource but this does not write to the file as a child node. This is what I am trying to do The query's name and age are textbox entries and the Criteria is a part of the dataset. So i am trying to insert as child node to Any ideas will be greatly appreicated Thanks in advance :)

      D Offline
      D Offline
      DavidNohejl
      wrote on last edited by
      #2

      hi, I think you can write your Criteria node to, say XmlDocumentFragment (using XmlWriter), and then append it as node to your original XML - assumming it's in XmlDocument or similar (basicaly everything with AppendChild method ). Or you can probably work with XmlWriter directly. Does it help? best regards, David 'DNH' Nohejl Never forget: "Stay kul and happy" (I.A.)

      R 1 Reply Last reply
      0
      • D DavidNohejl

        hi, I think you can write your Criteria node to, say XmlDocumentFragment (using XmlWriter), and then append it as node to your original XML - assumming it's in XmlDocument or similar (basicaly everything with AppendChild method ). Or you can probably work with XmlWriter directly. Does it help? best regards, David 'DNH' Nohejl Never forget: "Stay kul and happy" (I.A.)

        R Offline
        R Offline
        Rekha Patel
        wrote on last edited by
        #3

        David I looked into XmlWriter class. The problem is writing the complete dataset individually by adding elements and its attributes. Criteria has a about 10 columns that I did not specify in the mail. If I were to use XmlWriter then I would have to append every single column as an element. But the datasource's writeXml method takes care of everything. Would you happen to know how I can create a document fragment and somehow use ds.WriteXml("Filename") method Thanks!!! Rekha

        D 1 Reply Last reply
        0
        • R Rekha Patel

          David I looked into XmlWriter class. The problem is writing the complete dataset individually by adding elements and its attributes. Criteria has a about 10 columns that I did not specify in the mail. If I were to use XmlWriter then I would have to append every single column as an element. But the datasource's writeXml method takes care of everything. Would you happen to know how I can create a document fragment and somehow use ds.WriteXml("Filename") method Thanks!!! Rekha

          D Offline
          D Offline
          DavidNohejl
          wrote on last edited by
          #4

          hi, Of course you can let dataset do lot of work for for you! you can use [WriteXml(XmlWriter)](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatasetclasswritexmltopic4.asp) [[^](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatasetclasswritexmltopic4.asp "New Window")] overloaded method to write columns and all into XmlWriter at once. Bt yes, you would have to write your Query element by yourself... example:

          XmlTextWriter w = new XmlTextWriter(filename);
          w.WriteElementStart("query");
          ds.WriteXml(w);
          w.WriteElementEnd();
          w.Close();
          

          It's not exact code - just idea how to do that... I don't know exact method names and arguments from heart... :-O I think this way it should work... As for XmlDocument, sorry. I forgot you can load XML into it with XmlReader, bt AFAIK you can't write into it with XmlWriter. My fault. hmm or you can save dataset into file, than load it to XmlDocument and than you can create XmlDocumentFragment from it. Next step is to append Criteria node to Query element - It suppose to have Query also loaded in (another) XmlDocument - probably less efficient solution than the first one ( with XmlTextWriter).:~ David Never forget: "Stay kul and happy" (I.A.)

          A 1 Reply Last reply
          0
          • D DavidNohejl

            hi, Of course you can let dataset do lot of work for for you! you can use [WriteXml(XmlWriter)](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatasetclasswritexmltopic4.asp) [[^](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatasetclasswritexmltopic4.asp "New Window")] overloaded method to write columns and all into XmlWriter at once. Bt yes, you would have to write your Query element by yourself... example:

            XmlTextWriter w = new XmlTextWriter(filename);
            w.WriteElementStart("query");
            ds.WriteXml(w);
            w.WriteElementEnd();
            w.Close();
            

            It's not exact code - just idea how to do that... I don't know exact method names and arguments from heart... :-O I think this way it should work... As for XmlDocument, sorry. I forgot you can load XML into it with XmlReader, bt AFAIK you can't write into it with XmlWriter. My fault. hmm or you can save dataset into file, than load it to XmlDocument and than you can create XmlDocumentFragment from it. Next step is to append Criteria node to Query element - It suppose to have Query also loaded in (another) XmlDocument - probably less efficient solution than the first one ( with XmlTextWriter).:~ David Never forget: "Stay kul and happy" (I.A.)

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

            :)

            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