XElement rootElement = XElement.Load("filename.xml"); XNamespace xmlnsNamespace = rootElement.GetNamespaceOfPrefix("xmlns");
XElement rootElement = XElement.Load("filename.xml"); XNamespace customNamespace = rootElement.GetNamespaceOfPrefix("myPrefix");In this example, we retrieve the namespace associated with the "myPrefix" prefix, which is a custom prefix that was defined in the XML document. Package library: The GetNamespaceOfPrefix method is part of the System.Xml.Linq namespace, which is included in the System.Xml.Linq.dll library. This library is part of the .NET Framework and is available in all versions of .NET.