C # Set the xml content to not wrap; add an empty node whose attribute is xsi: nil = & quot; true & quot;

Source: Internet
Author: User

1. Set the content format of the generated xml to not wrap. By default, the following code is used to create and generate xml: XmlDocument doc = new XmlDocument (); // The code for creating nodes is omitted .... // Save the doc. save (filename); the generated node has a line feed: <UserName> </UserName> this will cause the xsd to fail if any verification is passed. To avoid line feed, doc. save (filename); can be changed to: using (XmlTextWriter xtw = new XmlTextWriter (filename, null) {// None indicates that no special format is applied, and the other Reverse enumeration value Indented indicates indent xtw. formatting = Formatting. none; doc. save (xtw);} 2. add the public static XmlElement CreateNodeWithNullAttr (XmlDocument doc, string nodeName) {XmlElement element = doc. createElement (nodeName); XmlAttribute attr = doc. createAttribute ("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance"); attr. value = "true"; www.2cto.com element. setAttributeNode (attr); // element. attributes. append (attr); return element ;}

Related Article

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.