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 ;}