/// <summary>Removes attributes, comments, and processing instructions. </summary>
private static void clean(System.Xml.XmlElement elem)
{
System.Xml.XmlNodeList children = elem.ChildNodes;
for (int i = 0; i < children.Count; i++)
{
System.Xml.XmlNode child = children.Item(i);
if (System.Convert.ToInt16(child.NodeType) == (short)System.Xml.XmlNodeType.ProcessingInstruction || System.Convert.ToInt16(child.NodeType) == (short)System.Xml.XmlNodeType.Comment)
{
elem.RemoveChild(child);
}
else if (System.Convert.ToInt16(child.NodeType) == (short)System.Xml.XmlNodeType.Element)
{
clean((System.Xml.XmlElement)child);
}
}
System.Xml.XmlNamedNodeMap attributes = (System.Xml.XmlAttributeCollection)elem.Attributes;
//get names
System.String[] names = new System.String[attributes.Count];
for (int i = 0; i < names.Length; i++)
{
names[i] = attributes.Item(i).Name;
}
//remove by name
for (int i = 0; i < names.Length; i++)
{
attributes.RemoveNamedItem(names[i]);
}
}