是否可以使用XPath设置属性值?
可以像这样用XPath设置属性值吗是否可以使用XPath设置属性值?,xpath,attributes,Xpath,Attributes,可以像这样用XPath设置属性值吗 XPathNavigator xNav = doc.CreateNavigator(); xNav.MoveToAttribute("requestID", String.Empty); xNav.SetAttributeValue?? // need correct method to set a (new) value for current node-attribute.. 很可能(在您没有展示的代码中),XPathNavi
XPathNavigator xNav = doc.CreateNavigator();
xNav.MoveToAttribute("requestID", String.Empty);
xNav.SetAttributeValue?? // need correct method to set a (new) value for current node-attribute..
很可能(在您没有展示的代码中),XPathNavigator是根据XPathDocument构建的。根据定义,XPathDocument是只读的(这就是为什么它更高效的原因)
来自:
“由XPathDocument对象创建的XPathNavigator对象是
由XmlDocument对象创建的XPathNavigator对象为只读
可以编辑。”
如果要使用DOM更新节点,则必须使用另一个对象,例如XmlDocument
当然,人们早在7-8年前就意识到DOM并不是处理XML的最佳方式
我绝对建议使用XSLT进行XML处理,XSLT是一种专门为树转换设计的语言出于某种原因,它似乎不可能:属性的CanEdit字段为false。。。我尝试从xmldocument中完全删除该属性,并尝试调用xNav.CreateAttribute(string.Empty,“requestID”,string.Empty,“testivalue”);但这种方法也不受支持。。。当然,这必须是一种使用XPath添加/编辑AttAttribute的方法??使用XPath无法修改任何内容,但它应该允许您找到要修改的属性节点,因此您可以使用一些外部API进行修改;但这并不取决于XPath,而是取决于外部API。