Gets the XNamespace object that corresponds to no namespace.
using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass{
public static void Main(){
XNamespace aw = "http://www.domain.com";
XElement root = new XElement("Root",
new XElement(aw + "ChildInNamespace", "content"),
new XElement("ChildInNoNamespace", "content")
);
if (root.Name.Namespace == XNamespace.None)
Console.WriteLine("Root element is in no namespace");
else
Console.WriteLine("Root element is in a namespace");
if (root.Element(aw + "ChildInNamespace").Name.Namespace == XNamespace.None)
Console.WriteLine("ChildInNamespace element is in no namespace");
else
Console.WriteLine("ChildInNamespace element is in a namespace");
if (root.Element("ChildInNoNamespace").Name.Namespace == XNamespace.None)
Console.WriteLine("ChildInNoNamespace element is in no namespace");
else
Console.WriteLine("ChildInNoNamespace element is in a namespace");
}
}
Related examples in the same category