private void AddNamespaces(Rhino.Xmlimpl.XmlNode.Namespaces rv, XmlElement element) { if (element == null) { throw new Exception("element must not be null"); } string myDefaultNamespace = ToUri(element.LookupNamespaceURI(null)); string parentDefaultNamespace = string.Empty; if (element.ParentNode != null) { parentDefaultNamespace = ToUri(element.ParentNode.LookupNamespaceURI(null)); } if (!myDefaultNamespace.Equals(parentDefaultNamespace) || !(element.ParentNode is XmlElement)) { rv.Declare(Rhino.Xmlimpl.XmlNode.Namespace.Create(string.Empty, myDefaultNamespace)); } XmlNamedNodeMap attributes = element.Attributes; for (int i = 0; i < attributes.Count; i++) { XmlAttribute attr = (XmlAttribute)attributes.Item(i); if (attr.Prefix != null && attr.Prefix.Equals("xmlns")) { rv.Declare(Rhino.Xmlimpl.XmlNode.Namespace.Create(attr.LocalName, attr.Value)); } } }