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. How to load XML objects into .Net classes [modified]

How to load XML objects into .Net classes [modified]

Scheduled Pinned Locked Moved XML / XSL
csharpdatabasexmloracle
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.
  • N Offline
    N Offline
    nzmike
    wrote on last edited by
    #1

    Hi all, Hoping someone can point me in the right direction here. I'm writing a VB.Net 2.0 WinForms admin app to allow users to do maintenance on an Oracle database behind another very large app. To keep the size of the admin app down and to avoid a maintenance nightmare when the tables (about 70 of them) change I am trying to write it so it's totally automated. I already have code to read the schema of each table to get the columns and then I have a form that adds an appropriate custom control for each type of table column. This works very well but I need it to be advanced enough to hide some columns, make sure others are entered, validate some others, etc, etc. So my idea is to have an XML file (see below) containing the tables and columns which can be maintained and when the app starts it would read the file and load the data into .Net classes which correspond to the XML (see class definitions below). I can then use these table and column classes to apply custom behaviour to the custom edit form I already have. So, looking at the XML and class definitions (both kept VERY simple for illustration purposes) can anyone tell me how best to go about this? How could I best read the XML file in and convert it to the classes I've defined? TIA for any help... I know how to write using lots of fairly manual code but am hoping there is a smarter & quicker way to to do this. Mike.

    Public Class SAMTables Public Tables() as SAMTAble End Class Public Class SAMTable Public TableName as String Public CustomForm as String Public Columns() as SAMColumn End Class Public

    S 1 Reply Last reply
    0
    • N nzmike

      Hi all, Hoping someone can point me in the right direction here. I'm writing a VB.Net 2.0 WinForms admin app to allow users to do maintenance on an Oracle database behind another very large app. To keep the size of the admin app down and to avoid a maintenance nightmare when the tables (about 70 of them) change I am trying to write it so it's totally automated. I already have code to read the schema of each table to get the columns and then I have a form that adds an appropriate custom control for each type of table column. This works very well but I need it to be advanced enough to hide some columns, make sure others are entered, validate some others, etc, etc. So my idea is to have an XML file (see below) containing the tables and columns which can be maintained and when the app starts it would read the file and load the data into .Net classes which correspond to the XML (see class definitions below). I can then use these table and column classes to apply custom behaviour to the custom edit form I already have. So, looking at the XML and class definitions (both kept VERY simple for illustration purposes) can anyone tell me how best to go about this? How could I best read the XML file in and convert it to the classes I've defined? TIA for any help... I know how to write using lots of fairly manual code but am hoping there is a smarter & quicker way to to do this. Mike.

      Public Class SAMTables Public Tables() as SAMTAble End Class Public Class SAMTable Public TableName as String Public CustomForm as String Public Columns() as SAMColumn End Class Public

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      Sounds like the XmlSerializer is what you're looking for.


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      N 1 Reply Last reply
      0
      • S Stefan Troschuetz

        Sounds like the XmlSerializer is what you're looking for.


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        N Offline
        N Offline
        nzmike
        wrote on last edited by
        #3

        Thanks - what I did in the end was read the file into an XMLDataDocument object instead of a class structure as it means I can use XPath/XQuery and also have the power of the DatatSet object as well. Once I created the schema file (by loading the XML file into VS2005 and choosing Create Schema from the XML menu) the code was simply as follows: Public Sub LoadXMLConfig() 'Read the XML configuration file dataDoc = New XmlDataDocument() dataDoc.DataSet.ReadXml(My.Settings.XMLConfigFile) End Sub Just thought I'd post this in case anyone else is wanting to do this sort of thing and comes across this thread. Mike

        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