Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / Visual Basic
Article

Xml to VB.net Class Generator

Rate me:
Please Sign up or sign in to vote.
1.72/5 (7 votes)
3 Jul 20061 min read 65.6K   3.5K   26   8
Converts XML Document to VB.Net Class

Introduction

Sample screenshot

XML2Class Generator converts the XML Document to VB.Net Class. The reason behind developing this application was I have some components those returns xml string. I want to expose them out as strongly typed classes. I tried to implement Dataset by creating schema from xml and generating Dataset, but for the two reasons I left that idea.

Reason 1. Some of the tags in the xml documents have attributes and the dataset was created with child tables for each tag that has the attributes. I don’t like that approach.

Reason 2. I felt Dataset is too heavy to do this kind of work and it has lot of functionality that is not useful in this scenario.


Then I tought i would write a class manually which reads the xml document and copy the values to the class properties. But I felt it is laborious job, since the xml document has so many tags. I left this idea too.


Hence I decided to write XML to Class generator.

 

Features:

1. Generates class from xml. (This version only supports XML file with one root node )

2. Handles the xml attributes by converting them as separate properties. The xml attribute will be rendered as a property with this format “NodeName_Attributename”.

Example : <Name First=”Srinivas”/>

Attribute First will be created as property Name_First.

3.Can Be serialized from the xml.

I have included a sample project which has the logic to create an instance of the above generated class by deserializing from the xml.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionDid not work on more complicated XML.... Pin
Craig P Williams Sr20-Jul-17 7:28
professionalCraig P Williams Sr20-Jul-17 7:28 
Try this:
It was not even close.


-<filecabinet allowallcontentservers="true" oguid="4f82903f-b3f7-405d-909d-8af7b539b7aa" oid="1" fid="23" organization="Here at work" version="5.1.0.1">-<general foreignchksum="false" autodisplay="false"><fcid dbdatetime="13111538.702" guid="3a42bf7b-7257-42dc-83fd-76695ef82713"><fcname>CMC Customers<fcshortname>CUSTOMER<fcsymbol color="Green" symbol="standart"><tracking>false<securitylevel>Normal<sapaccess>false<cassupport>false<sapmapping totalnumber="0"><notesaccess>false<masterfcguid>00000000-0000-0000-0000-000000000000<allowemailalerts>true<allowwexplorerclientaccess>false<allowtrustedappuseraccess>false-<database databasetype="MySQL" databaseconnectionguid="c4d4e1a5-dbcc-4ad9-9316-d3f57f07619c"><dbgeneral uppercaseindexentries="true" timeoutsearch="5" isreadonly="false" allowmodifyindexentries="true">CUSTOMER
DWSYS
CUSTOMER_DSKS
CUSTOMER_LOCK
CUSTOMER_VER
CUSTOMER_SECT
CUSTOMER_PAGE
-<documents><capacitylimit documentslimit="-1" fileoverhead="48" overhead="1024" clustersize="2" includefulltext="false" includedb="No" limitdiskcapacity="true">4529848320-<docgeneral updateheadersofchangeddocuments="true" newdiskstype="RW" autoswitchtonextdisk="true" autocreatedisk="true"><coldreadoptions maxsizecoldfile="2" allowstorecolddocs="false">-<disk updateheadersofchangeddocuments="true" refreshonactivate="true" dw4disk="true" number="1" creationdate="0001-01-01T00:00:00" diskversion="DW4"><capacitylimit documentslimit="-1" fileoverhead="0" overhead="0" clustersize="0" includefulltext="false" includedb="No" limitdiskcapacity="false">0<type>RO<currentdiskspace>0<storagelocationguid>0194dd5c-427b-4cf4-8dc9-7c0deacb0c8c<coldreadoptions maxsizecoldfile="2" allowstorecolddocs="false">-<disk updateheadersofchangeddocuments="true" refreshonactivate="true" dw4disk="true" number="2" creationdate="0001-01-01T00:00:00" diskversion="DW4"><capacitylimit documentslimit="-1" fileoverhead="0" overhead="0" clustersize="0" includefulltext="false" includedb="No" limitdiskcapacity="false">0<type>RO<currentdiskspace>0<storagelocationguid>0194dd5c-427b-4cf4-8dc9-7c0deacb0c8c<coldreadoptions maxsizecoldfile="2" allowstorecolddocs="false">-<disk updateheadersofchangeddocuments="true" refreshonactivate="true" dw4disk="false" number="3" creationdate="0001-01-01T00:00:00" diskversion="DW5"><capacitylimit documentslimit="-1" fileoverhead="48" overhead="1024" clustersize="2" includefulltext="false" includedb="No" limitdiskcapacity="true">4529848320<type>RW<currentdiskspace>0<storagelocationguid>0194dd5c-427b-4cf4-8dc9-7c0deacb0c8c<coldreadoptions maxsizecoldfile="2" allowstorecolddocs="false">-<disk updateheadersofchangeddocuments="true" refreshonactivate="true" dw4disk="false" number="4" creationdate="2017-04-05T14:41:27" diskversion="DW5"><capacitylimit documentslimit="-1" fileoverhead="48" overhead="1024" clustersize="2" includefulltext="false" includedb="No" limitdiskcapacity="true">4529848320<type>RW<currentdiskspace>0<storagelocationguid>0194dd5c-427b-4cf4-8dc9-7c0deacb0c8c<coldreadoptions maxsizecoldfile="2" allowstorecolddocs="false"><storagelocationguid>5a201afc-151a-4575-86a5-9d318bbf1b76-<fields>-<userfield guid="d63f4364-12c5-4956-9cf3-742b86a2aa4b" selectlistonly="false" id="32" notempty="true" usedasdocumentname="true" dropleadingblanks="false" dropleadingzero="false" displayname="Name" dbname="NAME" dwlength="40" dwtype="TextVar"><dbtype uniquetype="None" length="40" indexed="false">NVarChar<fixedentry>No-<assignedsearchselectlists><assignedexternalselectlist guid="00000000-0000-0000-0000-000000000000" isdwinternalselectlist="true">-<assignedmodifyselectlists><assignedexternalselectlist guid="00000000-0000-0000-0000-000000000000" isdwinternalselectlist="true">-<userfield guid="567fd5d2-2bf4-4667-8952-45b6378c5341" selectlistonly="false" id="64" notempty="false" usedasdocumentname="false" dropleadingblanks="false" dropleadingzero="false" displayname="XDate" dbname="XDATE" dwlength="-1" dwtype="Date"><dbtype uniquetype="None" length="-1" indexed="false">DateTime<fixedentry>No-<assignedsearchselectlists><assignedexternalselectlist guid="00000000-0000-0000-0000-000000000000" isdwinternalselectlist="true">-<assignedmodifyselectlists><assignedexternalselectlist guid="00000000-0000-0000-0000-000000000000" isdwinternalselectlist="true">-<userfield guid="d81c518e-a6b9-4aed-a554-059b97648c11" selectlistonly="false" id="33" notempty="false" usedasdocumentname="false" dropleadingblanks="false" dropleadingzero="false" displayname="DATERANGE" dbname="DATERANGE" dwlength="40" dwtype="TextVar"><dbtype uniquetype="None" length="40" indexed="false">NVarChar<fixedentry>No-<assignedsearchselectlists><assignedexternalselectlist guid="00000000-0000-0000-0000-000000000000" isdwinternalselectlist="true">-<assignedmodifyselectlists><assignedexternalselectlist guid="00000000-0000-0000-0000-000000000000" isdwinternalselectlist="true">-<userfield guid="c4ef2378-db6b-4119-b34e-09016bb290a1" selectlistonly="false" id="34" notempty="false" usedasdocumentname="false" dropleadingblanks="false" dropleadingzero="false" displayname="SUBECT" dbname="SUBECT" dwlength="40" dwtype="TextVar"><dbtype uniquetype="None" length="40" indexed="false">NVarChar<fixedentry>No-<assignedsearchselectlists><assignedexternalselectlist guid="00000000-0000-0000-0000-000000000000" isdwinternalselectlist="true">-<assignedmodifyselectlists><assignedexternalselectlist guid="00000000-0000-0000-0000-000000000000" isdwinternalselectlist="true">-<userfield guid="44b2cbe5-4729-45e4-b6a4-26170379ad05" selectlistonly="false" id="65" notempty="false" usedasdocumentname="false" dropleadingblanks="false" dropleadingzero="false" displayname="SCAN_DATE" dbname="SCAN_DATE" dwlength="-1" dwtype="Date"><dbtype uniquetype="None" length="-1" indexed="false">DateTime<fixedentry>No-<assignedsearchselectlists><assignedexternalselectlist guid="00000000-0000-0000-0000-000000000000" isdwinternalselectlist="true">-<assignedmodifyselectlists><assignedexternalselectlist guid="00000000-0000-0000-0000-000000000000" isdwinternalselectlist="true">-<userfield guid="a0960850-3212-491e-87dc-df2b09354516" selectlistonly="false" id="35" notempty="false" usedasdocumentname="false" dropleadingblanks="false" dropleadingzero="false" displayname="DOC_TYPE" dbname="DOC_TYPE" dwlength="40" dwtype="TextVar"><dbtype uniquetype="None" length="40" indexed="false">NVarChar<fixedentry>No-<assignedsearchselectlists><assignedexternalselectlist guid="00000000-0000-0000-0000-000000000000" isdwinternalselectlist="true">-<assignedmodifyselectlists><assignedexternalselectlist guid="00000000-0000-0000-0000-000000000000" isdwinternalselectlist="true"><systemfield guid="cd17b494-7bc2-4f17-8a8f-214f1af56c25" id="-5" displayname="Version ID" dbname="DWVERID" dwlength="-1" dwtype="Int"> <systemfield guid="3e3d0d85-7714-4539-b5f5-ab83475f48bf" id="-6" displayname="Version" dbname="DWSYSVERSION" dwlength="-1" dwtype="Int"> <systemfield guid="60f855a0-dec4-4b52-8ef4-2a17af5d98bd" id="-7" displayname="Extended Flags" dbname="DWFLAGSEX" dwlength="-1" dwtype="Long"> <systemfield guid="7713a2ef-a5d8-49ae-842e-ebd7500912a0" id="-1" displayname="Storage Access" dbname="DWSTORAGEACCESS" dwlength="-1" dwtype="TextVar"> <systemfield guid="17b40d60-b042-46da-adc0-3cf88e2bac8a" id="-2" displayname="Extension" dbname="DWEXTENSION" dwlength="20" dwtype="TextVar"> <systemfield guid="61f33c5c-3f4d-461d-9e07-cefae8d2226a" id="-3" displayname="Header Size" dbname="DWHEADERSIZE" dwlength="-1" dwtype="Long"> <systemfield guid="61a388c8-82c4-41bd-965f-434f945fbfce" id="-4" displayname="Document Size" dbname="DWDOCSIZE" dwlength="-1" dwtype="Long"> <systemfield guid="f21eaf98-995e-4aee-b6e0-eb4bf8cec3d4" id="251" displayname="Offset" dbname="DWOFFSET" dwlength="-1" dwtype="Int"> <systemfield guid="4d053ba5-294d-4adb-93e8-14f8f8ef60f1" id="250" displayname="Flags" dbname="DWFLAGS" dwlength="-1" dwtype="Int"> <systemfield guid="be06d61a-8e11-44d8-9f39-83112a7cb403" id="-8" displayname="Intellix hints" dbname="DWINTELLIXHINTS" dwlength="-1" dwtype="TextVar"> <systemfield guid="bb804971-4a94-412b-9a84-e3c686021dda" id="248" displayname="Doc ID" dbname="DWDOCID" dwlength="-1" dwtype="Int"> <systemfield guid="d1cfe412-11de-4428-ad22-3a090ad4f396" id="242" displayname="File Count" dbname="DWPAGECOUNT" dwlength="-1" dwtype="Int"> <systemfield guid="56816ce6-5256-4d83-80f2-90638cd452e7" id="249" displayname="Disk Number" dbname="DWDISKNO" dwlength="-1" dwtype="Int"> <systemfield guid="494b5111-2ffc-40e0-a07b-552cbe510cac" id="243" displayname="Store Date" dbname="DWSTOREDATETIME" dwlength="-1" dwtype="DateTime"> <systemfield guid="d23ae6e8-581b-4fe1-8ced-ce76bfef2fdb" id="31" displayname="Store User" dbname="DWSTOREUSER" dwlength="20" dwtype="TextVar"> <systemfield guid="b24e2bad-157d-48db-a227-a7a0333d11e6" id="65552" displayname="Modification Date" dbname="DWMODDATETIME" dwlength="-1" dwtype="DateTime"> <systemfield guid="bed06610-629e-4d2f-9b32-76985b2c2d18" id="65568" displayname="Modification User" dbname="DWMODUSER" dwlength="20" dwtype="TextVar"> <systemfield guid="021cfaf4-faee-4c39-a3e0-c4da6178b0a6" id="65553" displayname="Last Access Date" dbname="DWLASTACCESSDATETIME" dwlength="-1" dwtype="DateTime"> <systemfield guid="0a1634f9-0c5d-4c89-ba6b-1d9ec7e1608e" id="65569" displayname="Last Access User" dbname="DWLASTACCESSUSER" dwlength="20" dwtype="TextVar"> -<misc maxindexsearchhits="10000"><printinfo transparent="true" ystart="10" xstart="10" printstamp="false" memofield="false" headwords="true" fields="true" filllines="true" fontname="Arial" active="false" fontsize="10"><selectlist timeout="15000"><thumbnailsettings showannotations="true"><fulltextoptions ftversion="Cheetah" solrapplicationname="" solrconnectionguid="00000000-0000-0000-0000-000000000000" autorotate="false" transactionaldatabasetables="false" maxhitcount="10000" maxhitcounttype="Absolute" minwordlenght="4" fulltextprocessguid="00000000-0000-0000-0000-000000000000" fulltextstoragelocationguid="00000000-0000-0000-0000-000000000000" maxindexpagesize="1" ocrtemplate="00000000-0000-0000-0000-000000000000" iscasesensitive="false" fulltextsupport="false" maximumtextshotspersection="100" realtimetextshotgeneration="false"> <validation><versionmanagementoptions documenthistory="false" enable="false">
General[My vote of 2] xsd Pin
Member 904093029-May-12 2:32
Member 904093029-May-12 2:32 
GeneralMy vote of 5 Pin
somethingfree12318-Jan-11 5:28
somethingfree12318-Jan-11 5:28 
GeneralMy vote of 1 Pin
Dave Kreskowiak7-Mar-10 15:44
mveDave Kreskowiak7-Mar-10 15:44 
GeneralCouple things... [modified] Pin
BoneSoft3-Jul-06 9:40
BoneSoft3-Jul-06 9:40 
GeneralRe: Couple things... Pin
zhaojicheng18-Feb-09 2:00
zhaojicheng18-Feb-09 2:00 
GeneralRe: Couple things... Pin
BoneSoft18-Feb-09 2:20
BoneSoft18-Feb-09 2:20 
GeneralRe: Couple things... Pin
zhaojicheng18-Feb-09 4:21
zhaojicheng18-Feb-09 4:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.