根据属性值选择XML节点节点、属性、根据、XML

2023-09-04 01:06:53 作者:世界末日丶莪只带离开

<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 ;)