Exemple #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string    xmlFile = Server.MapPath("DvdList2.xml");
        XDocument doc     = XDocument.Load(xmlFile);

        //IEnumerable<XElement> matches = from DVD in doc.Descendants("DVD")
        //              where (int)DVD.Attribute("ID") < 3
        //              select DVD.Element("Title");

        var matches = from DVD in doc.Descendants("DVD")
                      orderby(decimal) DVD.Element("Price") descending
                      select new
        {
            Movie = (string)DVD.Element("Title"),
            Price = (decimal)DVD.Element("Price")
        };

        gridTitles.DataSource = matches;
        gridTitles.DataBind();


        //var matches = from title in doc.Root.Elements("DVD").Elements("Title")
        //              select (string)title;

        gridTitles.DataSource = matches;
        gridTitles.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        string    xmlFile = Server.MapPath("DvdList2.xml");
        XDocument doc     = XDocument.Load(xmlFile);

        XDocument newDoc = new XDocument(
            new XDeclaration("1.0", "utf-8", "yes"),
            new XElement("Movies",
                         from DVD in doc.Descendants("DVD")
                         where (int)DVD.Attribute("ID") < 3
                         select new XElement[] {
            new XElement("Movie",
                         new XAttribute("Name", (string)DVD.Element("Title")),
                         DVD.Descendants("Star")
                         )
        }
                         )
            );

        lblXml.Text = Server.HtmlEncode(newDoc.ToString());
    }