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

S

sherifffruitfly

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
 
C

Chris Dunaway

sherifffruitfly said:
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.

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
 
D

David Browne

<DIV>&quot;Chris Dunaway&quot; &lt;[email protected]&gt; wrote in message
news:[email protected]... said:
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.



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/...mpleGuid=54358B80-1324-49E9-821B-A08911356AD7

David
 
S

sherifffruitfly

David said:
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/...mpleGuid=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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top