Check if element has at least one attribute in CSharp

Description

The following code shows how to check if element has at least one attribute.

Example


  //w  w  w .  j  av a  2s  .  c o m
  
  
   
using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;


public class MainClass{
   public static void Main(){
        XElement xmlTree1 = new XElement("Root",
            new XAttribute("Att1", 1)
        );
        Console.WriteLine(xmlTree1.HasAttributes);
        XElement xmlTree2 = new XElement("Root");
        Console.WriteLine(xmlTree2.HasAttributes);
   }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style