Get the first annotation object of the specified type from this XElement in CSharp

Description

The following code shows how to get the first annotation object of the specified type from this XElement.

Example


  //  w  ww . j  a v  a2  s.  c  o m
  
  
   
using System;
using System.Xml.Linq;

public class MyAnnotation {
    private string tag;
    public string Tag {get{return tag;} set{tag=value;}}
    public MyAnnotation(string tag) {
        this.tag = tag;
    }
}

public class Program {
    public static void Main(string[] args) {   
        MyAnnotation ma = new MyAnnotation("T1");
        XElement root = new XElement("Root", "content");
        root.AddAnnotation(ma);

        MyAnnotation ma2 = root.Annotation<MyAnnotation>();
        Console.WriteLine(ma2.Tag);
    }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style