Remove the default namespace during XML serialization.

Source: Internet
Author: User

When C # is serialized in XML, the document will always contain
Xmlns: XSD = "http://www.w3.org/2001/XMLSchema"

And

Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
If you want to remove it or add your own namespace, consider the following method:

 

 

// Create our own namespaces for the output <br/> xmlserializernamespaces NS = new xmlserializernamespaces (); </P> <p> // Add an empty namespace and empty value <br/> ns. add ("", ""); </P> <p> // create the serializer <br/> xmlserializer SLZ = new xmlserializer (sometype ); </P> <p> // serialize the object with our own namespaces (notice the overload) <br/> SLZ. serialize (myxmltextwriter, someobject, NS); <br/>

Reference: http://www.csharper.net/blog/serializing_without_the_namespace__xmlns__xmlns_xsd__xmlns_xsi_.aspx

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.