根据属性值选择XML节点 [英] Select XML node by attribute value
本文介绍了根据属性值选择XML节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<location>
<hotspot name="name1" X="444" Y="518" />
<hotspot name="name2" X="542" Y="452" />
<hotspot name="name3" X="356" Y="15" />
</location>
我有一个点变量,我需要选择其坐标的节点,然后更改属性值。我想要做类似的事:
I have a point variable and I need to select the node with its coordinates, then change an attribute value. I want to do something similar to:
let node = xmld.SelectSingleNode("/location/hotspot[@X='542' @Y='452']")
node.Attributes.[0].Value <- "new_name2"
而是一个变量取属性值(variable_name.X / variable_name.Y)。
but taking attributes value by a variable (variable_name.X / variable_name.Y).
推荐答案
这是很容易的。假如我要修改的第一个属性在我的节点:
It was really easy. Supposing I want to modify the first attribute in my node:
let node = xmld.SelectSingleNode("/location/hotspot[@X='" + string(current.X) + "'] [@Y='" + string(current.Y) + "']")
node.Attributes.[0].Value <- v
在这里当前是我的变量;)
where "current" is my variable ;)
这篇关于根据属性值选择XML节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文