【发布时间】:2023-03-03 10:09:01
【问题描述】:
我发现了一些关于这个主题的例子。一些例子给出了用SelectNodes()或SelectSingleNode()修改属性的方法,还有一些例子给出了用someElement.SetAttribute("attribute-name", "new value");修改属性的方法
但是如果我只使用XpathNodeItterator it,我仍然对如何建立关系感到困惑?
假设我定义如下,
System.Xml.XPath.XPathDocument doc = new XPathDocument(xmlFile);
System.Xml.XPath.XPathNavigator nav = doc.CreateNavigator();
System.Xml.XPath.XPathNodeIterator it;
it = nav.Select("/Equipment/Items/SubItmes");
while (it.MoveNext())
{
name = it.Current.GetAttribute("name ", it.Current.NamespaceURI);
int vidFromXML = int.Parse(it.Current.GetAttribute("vid", it.Current.NamespaceURI));
if (vidFromXML = vid)
{
// How can I find the relation between it and element and node? I want to modify name attribute value.
}
}
有it.setAttribute(name, "newValue")这样的方法吗?
【问题讨论】:
标签: c# xml c#-2.0 setattribute selectnodes