I'm curious how it would be possible to write a DifferenceListener that
ignores all attributes in a given namespace. The problem I'm running
into is that differences in attributes are reported at the
org.w3c.dom.Element level (i.e., the both the test and control nodes are
Elements, even though the difference is in the attribute).
Here's the relevant section of code I currently have:
public int differenceFound( Difference difference )
{
int returnValue =3D RETURN_ACCEPT_DIFFERENCE;
Node controlNode =3D difference.getControlNodeDetail().getNode();
Node testNode =3D difference.getTestNodeDetail().getNode();
if ( "backendData".equals( controlNode.getNamespaceURI() )) {
System.out.println( "Found backendData URI for node " +
controlNode );
returnValue =3D RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
}
if ( difference.getDescription().equals( "number of element
attributes" ) ) {
returnValue =3D RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
}
return returnValue;
}
Here's the test that I'm using that needs to pass:
public void testIgnoreBackendDataNamespaces() throws Exception
{
String control =3D "<foo xmlns:ignore=3D\"backendData\"
ignore:a=3D\"whatever\" />";
String test =3D "<foo xmlns:ignore=3D\"backendData\" />";
Diff diff =3D new Diff( control, test );
diff.overrideDifferenceListener( new MyDifferenceListener() );
assertXMLEqual( diff, true );
}
Might it be preferable to have XML Unit pass in the Attr nodes in the
Difference object rather than the Element nodes when in actuality it is
the Attr that is different? Or is there another way I can do this?
Thanks for your help.
- Eli
|