Hiho C# people!

I have a problem while compiling this:

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            XDocument test = XDocument.Load(dataPath + "c:\\test.xml");
            var result = new XElement("dbs", from test.Descendants("dbs") select new XElement("db", a.Element("id").Value));
            Console.WriteLine(result);
        }
    }
}

Error 1 ) expected C:\..\Program.cs 14 51 ConsoleApplication5
Error 2 ; expected C:\..\Program.cs 14 75 ConsoleApplication5
Error 3 ; expected C:\..\Program.cs 14 82 ConsoleApplication5
Error 4 ; expected C:\..\Program.cs 14 123 ConsoleApplication5
Error 5 Invalid expression term ')' C:\..\Program.cs 14 123 ConsoleApplication5

I think i forgot a reference and using System.somthing

Can someone helpe me out?

Hi,

You have syntax errors. It has nothing to do with importing any namespace.

Regards,
Camilo

Does anny one know annthing about this then?
or got a smaple that i can use that works?

Ai.. its VB.. :(

Hi,

Wha you missed was 'a in', here is the correct way.

XDocument test = XDocument.Load(dataPath + "c:\\test.xml");
            var result =  new XElement("a", from a in test.Descendants("dbs") select new XElement("db", a.Element("id").Value));

If you really are interested in understand that code the you should read some article about how to crate XML with LINQ. Here are some videos http://msdn.microsoft.com/en-us/vcsharp/aa336745.aspx

Also you can go to this link.

http://blog.paranoidferret.com/index.php/2008/03/04/introduction-to-linq-simple-xml-parsing/

Hope this help.
Camilo

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.