Reputation: 6666
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
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