Parse hard coded string to XElement in CSharp

Description

The following code shows how to parse hard coded string to XElement.

Example


     //from   www .jav a2 s  .c o  m
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Reflection;
using System.Xml.Linq;

class Program {
    static void Main(string[] args) {
        string doc = @"<people>
                          <!-- Employee section -->
                          <person>
                            <id>1</id>
                            <firstname>C</firstname>
                            <lastname>L</lastname>
                            <idrole>1</idrole>
                          </person>
                           </people>";
        XElement xml = XElement.Parse(doc);
        Console.WriteLine(xml);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style