private void RemoveDuplicateNamespace(XmlElement elem, XmlNamespaceManager mgr, bool fCheckElemAttrs)
{
mgr.PushScope();
XmlAttributeCollection attributes = elem.Attributes;
int count = attributes.Count;
if (fCheckElemAttrs && (count > 0))
{
for (int i = count - 1; i >= 0; i--)
{
XmlAttribute attribute = attributes[i];
if (attribute.Prefix == this.doc.strXmlns)
{
string str = mgr.LookupNamespace(attribute.LocalName);
if (str == null)
{
mgr.AddNamespace(attribute.LocalName, attribute.Value);
}
else if (attribute.Value == str)
{
elem.Attributes.RemoveNodeAt(i);
}
}
else if ((attribute.Prefix.Length == 0) && (attribute.LocalName == this.doc.strXmlns))
{
string defaultNamespace = mgr.DefaultNamespace;
if (defaultNamespace != null)
{
if (attribute.Value == defaultNamespace)
{
elem.Attributes.RemoveNodeAt(i);
}
}
else
{
mgr.AddNamespace(attribute.LocalName, attribute.Value);
}
}
}
}
for (XmlNode node = elem.FirstChild; node != null; node = node.NextSibling)
{
XmlElement element = node as XmlElement;
if (element != null)
{
this.RemoveDuplicateNamespace(element, mgr, true);
}
}
mgr.PopScope();
}