"Oleg Subachev" <ol**@urvb.ru> wrote in message news:OU**************@tk2msftngp13.phx.gbl...
How to get list of namespces that are declared in an element ?
Given that you have first positioned yourself onto an XmlElement
of an XmlDocument, one of the fastest ways is to grab an XPath-
Navigator and enumerate the Namespace nodes that are present.
XPathNavigator nav = myElement.CreateNavigator( );
if ( nav.MoveToFirstNamespace( ) ) do
{
// Distinguish the default declaration (no prefix) from others.
if ( nav.Name == String.Empty )
Console.WriteLine( "xmlns='{0}'", nav.Value);
else
Console.WriteLine( "xmlns:{0}='{1}'", nav.Name, nav.Value);
}
while ( nav.MoveToNextNamespace( ) );
Another technique (albeit slower) is to take the OuterXml of the
XmlElement and parse it for xmlns declarations. (This approach
will not give you any advantage as far as identifying a particular
element's xmlns declarations from the source document, because
the serialized XML for any element shall also include all in-scope
namespace declarations.)
If you want to find the xmlns declarations on this specific element
(from the source document serialization), you must first get the
namespace declarations of this element and then follow-up by
getting the namespace declarations in-scope for the parent of
this element, finally removing the parent's in-scope namespace
declarations from this element's declarations (the resulting
declarations are those that are specific to this element).
Derek Harmon