Mega Code Archive

 
Categories / C# / XML LINQ
 

Gets the node type for this XObject

using System.Xml; using System; using System.Xml.Linq; class Program {     static void Main(string[] args)     {         XDocument xmlTree = new XDocument(             new XComment("a comment"),             new XProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"hello.xsl\""),             new XElement("Root",                 new XAttribute("Att", "attContent"),                 new XElement("Child1", new XCData("CDATA content")),                 new XElement("Child2", new XText("Text content"))             )         );         foreach (XNode node in xmlTree.DescendantNodes())         {             Console.WriteLine(node.NodeType);             if (node.NodeType == XmlNodeType.Element)             {                 foreach (XAttribute att in ((XElement)node).Attributes())                     Console.WriteLine(att.NodeType);             }         }     } }