XMLUnit - 忽略“id”比较属性
我目前正在使用 XMLUnit,我想知道是否有方法将其配置为仅忽略我想要比较的标签的 id
属性。
预先感谢您的帮助。
I am currently working with XMLUnit and I am wondering if there is way to configure it to ignore only the id
attribute of the tags I want to compare.
Thanks in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案非常简单。您可以配置
DifferenceEngine
来处理ATTR_VALUE
差异。编写实现DifferenceListener的自定义差异监听器类:这里需要检查属性名称是否为“id”。标准 Java DOM 功能可能会有所帮助。但我更喜欢通过正则表达式来做到这一点:
PS 另请参阅: http://xmlunit .sourceforge.net/api/org/custommonkey/xmlunit/Difference.html
The solution is quite simple. You can configure your
DifferenceEngine
to handleATTR_VALUE
differences. Write custom difference listener class which implements DifferenceListener:The required thing here is to check whether the attribute name is "id". Standard Java DOM functionality could help. But I prefer to do this by the means of regular expressions:
P.S. See also: http://xmlunit.sourceforge.net/api/org/custommonkey/xmlunit/Difference.html
我将尝试实现我自己的 DifferenceListener 来处理这个问题需要(请参阅这篇文章)。很快就会发布结果。看来可行,明天发布实施。
I am gonna try to implement my own DifferenceListener to handle this need (see this post). Gonna post the result soon. It seems to work, gonna post the implementation tomorrow.