Query Attributes with namespace in CSharp

Description

The following code shows how to query Attributes with namespace.

Example


using System;/*www . j  a v  a 2 s . c o  m*/
using System.Linq;
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 xmlTree = new XElement(aw + "Root",
            new XAttribute(XNamespace.Xmlns + "aw", "http://www.domain.com"),
            new XAttribute(aw + "Att1", "content1"),
            new XAttribute(aw + "Att2", "content2")
        );
        IEnumerable<XAttribute> attList = xmlTree.Attributes(aw + "Att1");
        foreach (XAttribute att in attList)
            Console.WriteLine(att);
    }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style