Get XML Nodes in a Specific XML Namespace - CSharp XML

CSharp examples for XML:XML Namespace

Description

Get XML Nodes in a Specific XML Namespace

Demo Code


using System;//from   w  w w.  jav a 2 s.  co m
using System.Xml;

public class SelectNodesByNamespace
{
    [STAThread]
    private static void Main()
    {
        XmlDocument doc = new XmlDocument();
        doc.Load("Order.xml");

        XmlNodeList matches = doc.GetElementsByTagName("*", "http://mycompany/OrderML");

        Console.WriteLine("Element \tAttributes");
        Console.WriteLine("******* \t**********");
        foreach (XmlNode node in matches)
        {
            Console.Write(node.Name + "\t");
            foreach (XmlAttribute attribute in node.Attributes)
            {
                Console.Write(attribute.Value + "  ");
            }
            Console.WriteLine();
        }

    }
}

Result


Related Tutorials