开发者

Removing XML Namespaces from XML Serialized Output

开发者 https://www.devze.com 2022-12-20 05:46 出处:网络
I am generatin开发者_如何转开发g this XML using the serializer in VB.net as shown below Dim string_writer As New StringWriter()

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号