void AddAttribute(XmlAttribute attr, XmlNode parent) { if (parent == null) { fragment.Add(attr); } else { XmlElement elem = parent as XmlElement; if (elem == null) { throw new InvalidOperationException(); } elem.Attributes.Append(attr); } }