【发布时间】:2013-09-04 00:49:22
【问题描述】:
我正在尝试打开这样的 xmldocument:
var doc = new XDocument("c:\\temp\\contacts.xml");
var reader = doc.CreateReader();
var namespaceManager = new XmlNamespaceManager(reader.NameTable);
namespaceManager.AddNamespace("g", g.NamespaceName);
var node = doc.XPathSelectElement("/Contacts/Contact/g:Name[text()='Patrick Hines']", namespaceManager);
node.Value = "new name Richard";
doc.Save("c:\\temp\\newcontacts.xml");
我在第一行返回错误:
Non whitespace characters cannot be added to content.
xml 文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Contacts xmlns:g="http://something.com">
<Contact>
<g:Name>Patrick Hines</g:Name>
<Phone>206-555-0144</Phone>
<Address>
<street>this street</street>
</Address>
</Contact>
</Contacts>
【问题讨论】:
标签: xml c#-4.0 linq-to-xml