Display the second namespace on screen

image_pdfimage_print
   
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using System.IO;


public class MainClass{

   public static void Main(string[] args){   
      XDocument NewDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
            new XElement("Root", "MyDoc"));  
      XElement ThisElement = new XElement("{http://www.kutayzorlu.com/java2s/com/}First",new XAttribute(XNamespace.Xmlns + "NewNS",
                  "http://www.microsoft.com"),"Hello");
      Console.WriteLine(ThisElement.ToString());

      XName ThisName = ThisElement.Name;

      Console.WriteLine(ThisName.LocalName +
            "
Namespace: " + ThisName.Namespace +
            "
Namespace Name: " + ThisName.NamespaceName);

      ThisName = ThisElement.Attribute(XNamespace.Xmlns + "NewNS").Name;

      Console.WriteLine("Second Local Name: " + ThisName.LocalName +
           "
Second Namespace: " + ThisName.Namespace +
           "
Second Namespace Name: " + ThisName.NamespaceName +
           "
Attribute Value: " + 
               ThisElement.Attribute(XNamespace.Xmlns + "NewNS").Value);
   }
}

   
     


This entry was posted in XML LINQ. Bookmark the permalink.