johan
johan

Reputation: 6666

How to determine what Class to deserialize XML into

I'm creating a parser that receives XML and deserializes it into object. I have used two different schemas to generate the classes that the XML is deserialized into. However I need to determine what class to use when deserializing it.

The XML looks something like this:

Type A

 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
 <typeA>
 <info>
 </info>
 </typeA>

Type B

 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
  <typeB>
 <info>
  </info>
 </typeB>

How can this be done in a effecient way?

Upvotes: 0

Views: 122

Answers (1)

Leon
Leon

Reputation: 3401

In .NET, serializers use namespaces to figure out what type to de-serialize the XML in to.

If you are implementing a custom serialization, I would follow the same convention.

You can retrieve namespaces from XML files, and then decide what type to deserialize it to.

Upvotes: 3

Related Questions