Csharp/CSharp Tutorial/XML/Xml Namespace
Get Namespace URI, Prefix and LocalName
<source lang="csharp">using System; using System.Collections.Generic; using System.ruponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Xml;
public class MainClass { public static void Main() { XmlDocument doc = new XmlDocument(); doc.Load(Application.StartupPath + @"\employees.xml"); Console.WriteLine(doc.DocumentElement.NamespaceURI); Console.WriteLine(doc.DocumentElement.Prefix); Console.WriteLine(doc.DocumentElement.LocalName); } }</source>
Select Nodes By Namespace
<source lang="csharp">using System; using System.Xml; public class MainClass {
[STAThread] private static void Main() { XmlDocument doc = new XmlDocument(); doc.Load("Sample.xml"); XmlNodeList matches = doc.GetElementsByTagName("*", "http://mycompany/OrderML"); foreach (XmlNode node in matches) { Console.WriteLine(node.Name ); foreach (XmlAttribute attribute in node.Attributes) { Console.WriteLine(attribute.Value); } } }
}</source>