【发布时间】:2014-03-25 17:05:29
【问题描述】:
我在尝试构建 XDocument 时遇到错误。错误发生在代码下的 System.XML.Linq.Xdocument 内
internal override void ValidateString(string s) {
if (!IsWhitespace(s)) throw new ArgumentException(Res.GetString(Res.Argument_AddNonWhitespace));
}
此代码正在生成空引用异常。下面是我的 XDocument 代码,我不知道我正在做的事情是在哪里造成的。
XDocument folderviewContents = new XDocument(
new XDeclaration("1.0", "utf8", "yes"),
new XElement("LVNPImport",
new XAttribute("xmlns" + "xsd", XNamespace.Get("http://www.w3.org/2001/XMLSchema")),
new XAttribute("xmlns" + "xsi", XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance"))),
new XElement("InterfaceIdentifier", "835"),
//Start of FolderPaths
new XElement("FolderPaths",
new XElement("Folder",
new XAttribute("fromDate", "TEST"),
//attributes for Folder w/ lots of attributes
new XAttribute("toDate", "TEST"),
new XAttribute("contactName", "APerson"),
new XAttribute("email", "AnEmail"),
//value for that long Folder w/ lots of attributes
"Remittance Advice"),
//Facility
new XElement("Folder", "TEST"),
//PayorID
new XElement("Folder", "TEST"),
//RemitDate Year
new XElement("Folder","TEST"),
//RemitDate Month/Year
new XElement("Folder","TEST")),
new XElement("DocumentType", "RA"),
new XElement("DocumentDescription","TEST"),
new XElement("TotalFiles", "1"));
//Create a writer to write XML to the console.
XmlTextWriter writer = null;
writer = new XmlTextWriter(Console.Out);
//Use indentation for readability.
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
folderviewContents.WriteTo(writer);
writer.WriteEndDocument();
writer.Close();
Console.ReadLine();
编辑 更新代码
【问题讨论】:
标签: c# .net xml linq linq-to-xml