【发布时间】:2009-10-05 20:24:55
【问题描述】:
我有一个构造很差的 xml 文档——而不是子节点,项目有多个属性。
例如:
<makes>
<option make="FORD" year_start="1950" year_end="2009" />
<option make="CHEVROLET" year_start="1965" year_end="2009" />
...
</makes>
我正在尝试使用 XPath 为与某个属性匹配的所有节点选择其他属性的值。我正在填充 3 个 asp 下拉菜单,其中包含基于先前选择的 2 个 xml 文档的值。我正在使用 .net/c#
例如: 对于所有具有值为 x 的 make 属性的选项节点,找到 year_start 的值。
我尝试过这样的事情:
yearListData.XPath = string.Format("/makes/option[@year_start] and [@make={0}]", make);
其中 make = 先前的选择。显然,它没有用。
有没有办法使用 XPath 来做到这一点?
【问题讨论】: