【发布时间】:2012-10-18 21:17:09
【问题描述】:
我有一个很大的 xml 文件,我正在解析一个 xpath 以在其中插入值。这是我在其中插入一些值的 xml 文件的一部分:
<SERVICES>
<RELATIONSHIPS>
<RELATIONSHIP xlink:from="fromValue01" xlink:to="toValue01" />
<RELATIONSHIP xlink:from="fromValue02" xlink:to="toValue02" />
<RELATIONSHIP xlink:from="fromValue03" xlink:to="toValue03" />
<RELATIONSHIP xlink:from="fromValue04" xlink:to="toValue04" />
<RELATIONSHIP xlink:from="fromValue05" xlink:to="toValue05" />
<RELATIONSHIP xlink:from="fromValue06" xlink:to="toValue06" />
<RELATIONSHIP xlink:from="fromValue07" xlink:to="toValue07" />
</RELATIONSHIPS>
<SERVICES>
现在,当我想添加更多具有相同属性但具有不同值的 RELATIONSHIP 节点时(例如 <RELATIONSHIP xlink:from="fromValue08" xlink:to="toValue08" />),我总是会收到 Duplicate Attribute 错误。这将是我正在解析的 xpath 的示例:
/SERVICES/RELATIONSHIPS/RELATIONSHIP[@xlink:from="fromValue08" and @xlink:to="toValue08"]
解析器的代码太大,无法粘贴到这里,我确信它可以正常工作,因为它可以很好地插入所有节点,只是这里的这部分给我带来了一些麻烦。 我还用 Altova 检查了 xpath,它工作正常。
我的问题是:是否可以在 XML 中添加具有相同属性但具有不同值的节点?如果是,为什么 Visual Studio 总是抛出这个错误?
【问题讨论】: