-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeFilter with nodematcher #259
Comments
Sorry, the formatting of your example makes it almost impossible to see what you are looking for. In particular there is only one XML. .withAttributeFilter(attr -> attr.getName().equals("AttributeName")) says: Only look at attributes named Unfortunately you don't say what result you get that you are not expecting - and also not what you tried "withDifferenceEvaluator", so it is hard to help here. |
Hi Stefan, Thanks for the reply.I got the point, but i want to clear one doubt ` Diff diffs = DiffBuilder.compare(control).withTest(test).ignoreComments().ignoreWhitespace()
Here what is the use of |
Please see https://github.com/xmlunit/user-guide/wiki/SelectingNodes for a more comprehensive answer. Your setup says: Whenever XMLUnit looks at a list of elements and tries to decide which of the elements in the list that belongs to the control document to compare to which of the elements in the list of the test elements, then
Say your control doc is <root>
<VersionAttributes>
<VersionAttribute>1</VersionAttribute>
<VersionAttributes>
<a test="1"/>
<a test="2" foo="bar"/>
<a test="2"/>
<VersionAttributes>
<VersionAttribute>2</VersionAttribute>
<VersionAttributes>
</root> and your test document <root>
<VersionAttributes>
<VersionAttribute>2</VersionAttribute>
<VersionAttributes>
<a test="2"/>
<a test="2" foo="bar"/>
<a test="1"/>
<VersionAttributes>
<VersionAttribute>1</VersionAttribute>
<VersionAttributes>
</root> then
|
Hi Stefan..thanks for the reply. Lets say there is there are other attributes called "test2","test3" but it is not mentioned in the ElementSelectors.byNameAndAttributes("test"). so if i write this code so, here the xmls should be matched using attribute "test" and all other attributes apart from test will be ignored as i have used |
If you use If you set an attribute filter, the attributes filtered out will be completely invisible to the comparison, so you should never see any differences related to these attributes. I believe this is what you said, so yes, you are correct :-) While reading your question I realized |
Thanks Stefan for the explanation. |
Hi Stefan,
I want to find out the difference between 2 xml file, ignoring few attribute of a node.
my XML-
</AssignedContent> <AssignedContent ContentClass="FKN" IsRequired="false"> <ContentAttributes> <ContentAttribute AttributeName="PARAMETER-ABHAENGIGKEITe" CommentRequired="N" Description="Parameterabhängigkeit der Funktion" Group="FKN" LockedForGUI="R" MultipleValues="false" OnlyNormValues="false" Required="false" ShowNulls="true"> <ContentGrants/> </ContentAttribute> </ContentAttributes> </AssignedContent>
code which i tried-
` Diff diffs = DiffBuilder.compare(Source).withTest(Source2).ignoreComments().ignoreWhitespace()
.ignoreElementContentWhitespace().checkForSimilar()
.withNodeMatcher(new DefaultNodeMatcher(
ElementSelectors.conditionalBuilder().whenElementIsNamed("ContentAttributes")
.thenUse(ElementSelectors.byXPath("./ContentAttribute/text()",
ElementSelectors.byNameAndAttributes("Description")))
.elseUse(ElementSelectors.byNameAndAllAttributes).build()))
.withAttributeFilter(attr -> (attr.getName().equals("AttributeName"))
I tried with both withAttributeFilter and withDifferenceEvaluator but its not working. I wanted to ignore the AttributeName attribute of ContentAttribute .
Thanks
The text was updated successfully, but these errors were encountered: