DOM4J Element.attributes().containsAll() 返回意外值

发布于 2024-10-11 07:04:13 字数 835 浏览 0 评论 0原文

我正在使用 DOM4J 来分析两个 XML 元素。这些元素如下:

<element1 attr="val">text</element1> //org.dom4j.Element = e1

并且

<element1 attr="val">OtherText</element1>  //org.dom4j.Element = e2

这两个元素都存储在 org.dom4j.Element 实例中,e1e2

我期望这两个元素具有相同的属性,因此我期望:

e1.attributes().containsAll(e2.attributes())

返回 true,但实际上返回 false

当我检查这两个属性时,我发现以下字符串表示形式:

org.dom4j.tree.DefaultAttribute@552c8fa8 [Attribute: name attr value "val"]

并且

org.dom4j.tree.DefaultAttribute@26d58939 [Attribute: name attr value "val"]

我是否遗漏了一些明显的东西?除了编写我自己的 containsAll 函数来检查此行为之外,您还能想到我应该尝试的其他方法吗?

I am using DOM4J to do analysis of two XML elements. The elements are the following:

<element1 attr="val">text</element1> //org.dom4j.Element = e1

and

<element1 attr="val">OtherText</element1>  //org.dom4j.Element = e2

Both of these elements are stored in org.dom4j.Element instances, e1 and e2.

I expect that both of these elements have the same attributes, so I expect that:

e1.attributes().containsAll(e2.attributes())

returns true, but it actually returns false.

When I inspect both of these attributes, I find the following string representations:

org.dom4j.tree.DefaultAttribute@552c8fa8 [Attribute: name attr value "val"]

and

org.dom4j.tree.DefaultAttribute@26d58939 [Attribute: name attr value "val"]

Am I missing something obvious? Beyond writing my own containsAll function to inspect this behavior, can you think of anything else I should try?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情释 2024-10-18 07:04:13

我相信您必须编写自己的 containsAll()。您将看到默认的 List.containsAll(),它使用 equals() 比较项目。由于 DefaultAttribute 不会覆盖 equals() 以使您的比较结果为 true,那么您就不走运了。

I believe you'll have to write your own containsAll(). You're seeing the default List.containsAll(), which compares items using equals(). Since DefaultAttribute doesn't override equals() to make your comparison evaluate to true, you're out of luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文