User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 426,525 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,857 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 325 | Replies: 5
Reply
Join Date: Jul 2008
Posts: 15
Reputation: njitram is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
njitram njitram is offline Offline
Newbie Poster

LINQ & XML (references & using System..)

  #1  
Jul 17th, 2008
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?
Last edited by njitram : Jul 17th, 2008 at 7:59 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2008
Posts: 89
Reputation: camilojvarona is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 9
camilojvarona camilojvarona is offline Offline
Junior Poster in Training

Re: LINQ & XML (references & using System..)

  #2  
Jul 17th, 2008
Hi,

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

Regards,
Camilo
Last edited by camilojvarona : Jul 17th, 2008 at 9:43 am.
Reply With Quote  
Join Date: Jul 2008
Posts: 15
Reputation: njitram is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
njitram njitram is offline Offline
Newbie Poster

Re: LINQ & XML (references & using System..)

  #3  
Jul 17th, 2008
Does anny one know annthing about this then?
or got a smaple that i can use that works?
Reply With Quote  
Join Date: Jul 2008
Posts: 89
Reputation: camilojvarona is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 9
camilojvarona camilojvarona is offline Offline
Junior Poster in Training

Re: LINQ & XML (references & using System..)

  #4  
Jul 17th, 2008
Hi,

In this links there are some videos. Are in VB.NET but you should be able of understand them.

http://www.asp.net/learn/linq-videos/

Regards,
Camilo
Reply With Quote  
Join Date: Jul 2008
Posts: 15
Reputation: njitram is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
njitram njitram is offline Offline
Newbie Poster

Re: LINQ & XML (references & using System..)

  #5  
Jul 17th, 2008
Ai.. its VB..
Reply With Quote  
Join Date: Jul 2008
Posts: 89
Reputation: camilojvarona is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 9
camilojvarona camilojvarona is offline Offline
Junior Poster in Training

Re: LINQ & XML (references & using System..)

  #6  
Jul 17th, 2008
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...e-xml-parsing/

Hope this help.
Camilo
Last edited by camilojvarona : Jul 17th, 2008 at 12:19 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C# Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the C# Forum

All times are GMT -4. The time now is 6:28 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC