Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

Possible to deserialize xml with unknown-ahead-of-time number of a given element type?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sherifffruitfly - 31 Aug 2006 18:44 GMT
Hi,

I've got a dtd for my xml file according to which, for example, 0 or
more <component> elements are permitted. I'd like to take any xml file
conforming to this dtd, and deserialize it into a programmatic object.

My experience with the deserialization method is limited to classes
with *fixed* numbers of member data variables - and that number is
known ahead of time in the class definition.

Is it possible to use the built-in .net deserialization routines for a
varying (from xml doc to xml doc) number of elements? Or do I have to
"manually" deserialize, by reading the nodes, and plopping their
contents programmatically into the vars I want?

I'm googling, but having trouble finding a clear answer/program flow to
this.

Thanks for any suggestions,

cdj
Chris Dunaway - 31 Aug 2006 19:17 GMT
> Hi,
>
[quoted text clipped - 13 lines]
> I'm googling, but having trouble finding a clear answer/program flow to
> this.

Yes it is possible, the object you end up with would probably have
collection or ArrayList as a property or an array.  In your class
definition, you can specify, through attributes, how things should be
deserialized.

Good luck.

Chris
David Browne - 31 Aug 2006 20:08 GMT
sherifffruitfly wrote:
>> Hi,
>>
[quoted text clipped - 18 lines]
> definition, you can specify, through attributes, how things should be
> deserialized.

DTD is old and everything in .NET is based on XML Schema.  If you can
convert your DTD to an XSD, then you can use XSD.EXE to generate a .NET
class definition to de-serialize instances.

GotDotNet User Sample: Dtd2Xsd 1.1
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=54358B80-
1324-49E9-821B-A08911356AD7


David
sherifffruitfly - 31 Aug 2006 20:33 GMT
> DTD is old and everything in .NET is based on XML Schema.  If you can
> convert your DTD to an XSD, then you can use XSD.EXE to generate a .NET
> class definition to de-serialize instances.
>
> GotDotNet User Sample: Dtd2Xsd 1.1
> http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=54358B80-
1324-49E9-821B-A08911356AD7

I knew dtd was old, but didn't realize it was substantially easier to
do what I wanted with a schema - i'll look into the dtd2xsd
conversion/xsd.exe process you mention - thanks!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.