Leer en inglés Editar

Compartir a través de


XmlElement.HasAttributes Property

Definition

Gets a boolean value indicating whether the current node has any attributes.

C#
public virtual bool HasAttributes { get; }

Property Value

true if the current node has attributes; otherwise, false.

Examples

The following example removes all attributes from the root element.

C#
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    XmlElement root = doc.DocumentElement;

    // Remove all attributes from the root element.
    if (root.HasAttributes)
      root.RemoveAllAttributes();

    Console.WriteLine("Display the modified XML...");
    Console.WriteLine(doc.InnerXml);
  }
}

Remarks

This property is a Microsoft extension to the Document Object Model (DOM).

Applies to