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. C#
  4. Parse Custom XML type into DataSet

Parse Custom XML type into DataSet

Scheduled Pinned Locked Moved C#
questionxml
3 Posts 2 Posters 0 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
    james cxx
    wrote on last edited by
    #1

    Suppose I have a custom type made of a list of floats, and I want to represent it compactly in XML like this: [2.718, 3.142, 1.613, 1.000] Suppose also that I have a dataset, with a datatable where one of the columns uses MyType, which is a essentailly a float[]. My question is this: How do I ensure the tag is written into this format and read properly back into the float[] when I use ds.WriteXml and ds.ReadXml mehtods? Is there an interface or something I implement in my custom type to write on the contents for the tag and also to parse it back in? -- James --

    H 1 Reply Last reply
    0
    • J james cxx

      Suppose I have a custom type made of a list of floats, and I want to represent it compactly in XML like this: [2.718, 3.142, 1.613, 1.000] Suppose also that I have a dataset, with a datatable where one of the columns uses MyType, which is a essentailly a float[]. My question is this: How do I ensure the tag is written into this format and read properly back into the float[] when I use ds.WriteXml and ds.ReadXml mehtods? Is there an interface or something I implement in my custom type to write on the contents for the tag and also to parse it back in? -- James --

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Not without having to serialize the entire DataSet itself (using the undocumented IXmlSerializable interface) - not exactly something you want to do (it gets pretty complex if you want to remain compatible with the functionality of the DataSet). You could try, however, to create a typed DataSet (using xsd.exe or the DataSet designer in VS.NET - right-click on your project or project folder, select Add->Add New Item and add a "DataSet"), then modify the hidden source code (use Project->Show All Files) to transform a string into a float[]. Keep in mind, however, that most databases (Oracle is the only major database I can think of that can hold an array, IIRC) can't hold arrays. So, in Access, MS SQL Server/MSDE, MySQL, etc., this would only be a string. So should it be in your DataSet (well, in most cases). Your caller should be responsibe for serializing and deserializing that string to/from a float[], from a logical perspective.

      Microsoft MVP, Visual C# My Articles

      J 1 Reply Last reply
      0
      • H Heath Stewart

        Not without having to serialize the entire DataSet itself (using the undocumented IXmlSerializable interface) - not exactly something you want to do (it gets pretty complex if you want to remain compatible with the functionality of the DataSet). You could try, however, to create a typed DataSet (using xsd.exe or the DataSet designer in VS.NET - right-click on your project or project folder, select Add->Add New Item and add a "DataSet"), then modify the hidden source code (use Project->Show All Files) to transform a string into a float[]. Keep in mind, however, that most databases (Oracle is the only major database I can think of that can hold an array, IIRC) can't hold arrays. So, in Access, MS SQL Server/MSDE, MySQL, etc., this would only be a string. So should it be in your DataSet (well, in most cases). Your caller should be responsibe for serializing and deserializing that string to/from a float[], from a logical perspective.

        Microsoft MVP, Visual C# My Articles

        J Offline
        J Offline
        james cxx
        wrote on last edited by
        #3

        Heath Stewart wrote: Keep in mind, however, that most databases (Oracle is the only major database I can think of that can hold an array, IIRC) can't hold arrays. So, in Access, MS SQL Server/MSDE, MySQL, etc., this would only be a string. So should it be in your DataSet (well, in most cases). Your caller should be responsibe for serializing and deserializing that string to/from a float[], from a logical perspective. Your right. This is probably a better way to go. Thanks for your insight on this. -- James --

        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