Check if element has at least one child element in CSharp

Description

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

Example


    /*  w  w w .  j a va2  s .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 XElement("Child", 1)
        );
        Console.WriteLine(xmlTree1.HasElements);
        XElement xmlTree2 = new XElement("Root", "contents");
        Console.WriteLine(xmlTree2.HasElements);
    }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style