Check XmlElement.HasAttributes before calling XmlElement.Attributes

I have tested it against Everrette. If an xmlelement you are working with doesn't contain any attributes, calling XmlElement.Attributes will trigger the system to create an empty ArrayList. The best way to avoid it is to check whether the element contain any attribute before trying to traversing its attributes.

foreach(XmlAttriubte attr in element.Attributes) {

   // do some work with attr

}

is better off replaced by

if ( element.HasAttributes )

{

XmlAttributeCollection

attrList = node.Attributes;

         for (int i = 0; i<attrList.Count; i++)

{

// do some work

}

   }

This way, for a huge xml document, we won't be creating thousands of empty unnecessary ArrayList objects. Hope this helps!