Check if element contains no content in CSharp

Description

The following code shows how to check if element contains no content.

Example


    /*from  w  w  w. j  a  v  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 el1 = new XElement("Root");
        Console.WriteLine(el1);
        Console.WriteLine(el1.IsEmpty);
        Console.WriteLine();
        XElement el2 = new XElement("Root", "content");
        Console.WriteLine(el2);
        Console.WriteLine(el2.IsEmpty);
        Console.WriteLine();
        XElement el3 = new XElement("Root", "");
        Console.WriteLine(el3);
        Console.WriteLine(el3.IsEmpty);
        Console.WriteLine();
        el3.ReplaceAll(null);
        Console.WriteLine(el3);
        Console.WriteLine(el3.IsEmpty);

    }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style