开发者

DOM4J Element.attributes().containsAll() returns unexpected value

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜