Removing XML Namespaces from XML Serialized Output
I am generatin开发者_如何转开发g this XML using the serializer in VB.net as shown below
Dim string_writer As New StringWriter()
Dim serializer As New XmlSerializer(GetType(MyClass))
serializer.Serialize(string_writer, addr)
txttest.Text = string_writer.ToString()
though it is returning XML, I see xmlns="http://tempuri.org/ in all the elements, is there anyway I hide this one.
Sure - just pass the default namespace you want to use to the constructor of your XmlSerializer:
Dim string_writer As New StringWriter()
Dim serializer As New XmlSerializer(GetType(MyClass), "")
serializer.Serialize(string_writer, addr)
txttest.Text = string_writer.ToString()
That should do the trick.
精彩评论