I want to serialize a class to xml and store that in a field in a database. I can serialize with this:
StringWriter sw = new StringWriter();
XmlSerializer xmlser = new XmlSerializer(typeof(MyClass));
xmlser.Serialize(sw, myClassVariable);
string s = sw.ToString();
sw.Close();
Thats works, but it has the namespaces in it.
<.... xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Will these slow down the deserialization because it will go out to those and verify the XML? I got rid of the namespaces by creating a blank XmlSerializerNamespaces and using that to serialize, but then the xml still had namespaces around integer variables:
<anyType xmlns:q1="http://www.w3.org/2001/XMLSchema"
d3p1:type="q1:int"
xmlns:d3p1="http://www.w3.org/2001/XMLSchema-instance">
3
</anyType>
My question is: Is it necessary to have the namesapces for deserialization and if not, how to get rid of them? How do I tell it fields are ints so it doesnt put in "anytype"
Thanks, Brian
No, these namespaces will not slow down the deserialisation. Those URIs are not Web endpoints that the serialiser visits: they are just identifiers -- labels which happen to use the Web URI scheme in order to guarantee uniqueness. You can safely leave them in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With