将 XAttribute 添加到 XElement 时出现重复错误 [英] Duplicate error when adding XAttribute to XElement

查看:26
本文介绍了将 XAttribute 添加到 XElement 时出现重复错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的 xml 文件,我正在解析一个 xpath 以在其中插入值.这是我在其中插入一些值的 xml 文件的一部分:

I've got a big xml file and I'm parsing an xpath to insert values in it. This is a part of the xml file where I'm inserting some values:

<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 的示例:

Now, when I want to add more of these RELATIONSHIP nodes with same attributes but with different values (e.g. <RELATIONSHIP xlink:from="fromValue08" xlink:to="toValue08" />) I always get a Duplicate Attribute error. This would be example of the xpath I'm parsing:

/SERVICES/RELATIONSHIPS/RELATIONSHIP[@xlink:from="fromValue08" and @xlink:to="toValue08"]

解析器的代码太大,无法粘贴在这里,我确信它运行良好,因为它可以很好地插入所有节点,只有这里的这部分给我带来了一些麻烦.我还用 Altova 检查了 xpath 并且它有效.

The parser is too big of a code to just paste here, and I'm sure it's working fine since it's inserting all nodes just fine, only this part here is giving me some trouble. I also checked the xpath with Altova and it works.

我的问题是:在 XML 中是否允许添加具有相同属性但具有不同值的节点?如果是,为什么 Visual Studio 总是抛出这个错误?

My question is: Is adding a node with same attributes but with different values allowed in XML? And if yes, why is Visual Studio always throwing this error?

推荐答案

肯定与您的 XPath 请求有关,可能缺少 RELATIONSHIPS

It's sure in relation with your XPath request maybe an index in missing for RELATIONSHIPS

这篇关于将 XAttribute 添加到 XElement 时出现重复错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆