@@ -152,19 +152,31 @@ public static ElementSelector
152152 /// Elements with the same local name (and namespace URI - if any)
153153 /// and attribute values for all attributes can be compared.
154154 /// </summary>
155+ /// <remarks>
156+ /// <para>
157+ /// This ElementSelector doesn't know anything about a
158+ /// potentially configured attribute filter so may also
159+ /// compare attributes that are excluded from comparison by
160+ /// the filter. Use the ByNameAndAllAttributes(Predicate)
161+ /// passing in your attribute filter if this causes problems.
162+ /// </para>
163+ /// </remarks>
155164 public static bool ByNameAndAllAttributes ( XmlElement controlElement ,
156165 XmlElement testElement ) {
157- if ( ! ByName ( controlElement , testElement ) ) {
158- return false ;
159- }
160- IDictionary < XmlQualifiedName , string > cAttrs =
161- Nodes . GetAttributes ( controlElement ) ;
162- IDictionary < XmlQualifiedName , string > tAttrs =
163- Nodes . GetAttributes ( testElement ) ;
164- if ( cAttrs . Count != tAttrs . Count ) {
165- return false ;
166- }
167- return MapsEqualForKeys ( cAttrs , tAttrs , cAttrs . Keys ) ;
166+ return ByNameAndAllAttributes ( ignored => true , controlElement , testElement ) ;
167+ }
168+
169+ /// <summary>
170+ /// Elements with the same local name (and namespace URI - if any)
171+ /// and attribute values for all attributes can be compared.
172+ /// </summary>
173+ /// <remarks>
174+ /// <para>
175+ /// since XMLUnit 2.9.3
176+ /// </para>
177+ /// </remarks>
178+ public static ElementSelector ByNameAndAllAttributes ( Predicate < XmlAttribute > attributeFiler ) {
179+ return ( control , test ) => ByNameAndAllAttributes ( attributeFiler , control , test ) ;
168180 }
169181
170182 /// <summary>
@@ -420,5 +432,21 @@ private static bool
420432 } ) ;
421433 }
422434
435+ private static bool ByNameAndAllAttributes ( Predicate < XmlAttribute > attributeFiler ,
436+ XmlElement controlElement ,
437+ XmlElement testElement ) {
438+ if ( ! ByName ( controlElement , testElement ) ) {
439+ return false ;
440+ }
441+ IDictionary < XmlQualifiedName , string > cAttrs =
442+ Nodes . GetAttributes ( controlElement , attributeFiler ) ;
443+ IDictionary < XmlQualifiedName , string > tAttrs =
444+ Nodes . GetAttributes ( testElement , attributeFiler ) ;
445+ if ( cAttrs . Count != tAttrs . Count ) {
446+ return false ;
447+ }
448+ return MapsEqualForKeys ( cAttrs , tAttrs , cAttrs . Keys ) ;
449+ }
450+
423451 }
424452}
0 commit comments