我创建了这个 xmlfile:
<?xml version="1.0" encoding="utf-8"?>
<Contacts xmlns:g="http://something.com">
<Contact>
<g:Phone>206-555-0144</g:Phone>
<g:Name>Patrick Hines</g:Name>
<g:Address>
<street>this street</street>
</g:Address>
</Contact>
</Contacts>
我正在尝试选择电话节点,然后尝试获取下一个节点。电话节点是独一无二的,所以这就是我首先寻找它的原因。如何更改名称的值?
var doc = XDocument.Load("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:Phone[text()='206-555-0144']", namespaceManager);
var nd =node.NextNode // does not work
node.Value = "sjfjks";