I have a function which needs to deserialize an XML string, but it doesn't at this point know the object type.
So I get a string like:-
"<?xml version="1.0" encoding="utf-16"?>
<OneClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SomeThing>Serializer.OneClass <--This class type</SomeThing>
</OneClass>"
Or maybe:-
"<?xml version="1.0" encoding="utf-16"?>
<TwoClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SomeThing>Serializer.TwoClass <--This class type</SomeThing>
</TwoClass>"
And I want to end up with a "OneClass" or a "TwoClass".
I can do this by creating an xmlDocument, loading the XML, getting the documentelement.name, mapping that to a type via configuration information, and this then gives me the type which I can create an xmlSerializer from. Then I can deserialize it.
But surely there must a better way.
Stuffed if I can find it though. Any suggestions?
Cheers.
So I get a string like:-
"<?xml version="1.0" encoding="utf-16"?>
<OneClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SomeThing>Serializer.OneClass <--This class type</SomeThing>
</OneClass>"
Or maybe:-
"<?xml version="1.0" encoding="utf-16"?>
<TwoClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SomeThing>Serializer.TwoClass <--This class type</SomeThing>
</TwoClass>"
And I want to end up with a "OneClass" or a "TwoClass".
I can do this by creating an xmlDocument, loading the XML, getting the documentelement.name, mapping that to a type via configuration information, and this then gives me the type which I can create an xmlSerializer from. Then I can deserialize it.
But surely there must a better way.
Stuffed if I can find it though. Any suggestions?
Cheers.
Comment