Click here to Skip to main content
15,918,742 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
var data = doc.Element("testes").Elements("teste");


getting error for this line at element

Error 1 'System.Xml.XmlDocument' does not contain a definition for 'Element' and no extension method 'Element' accepting a first argument of type 'System.Xml.XmlDocument' could be found (are you missing a using directive or an assembly reference?)

code:

XmlDocument doc = new XmlDocument();
            doc.Load(@"C:\Sampledata.xml");
            var data = doc.Element("testes").Elements("teste");

            Dictionary<string, string> hash = new Dictionary<string, string>();

            var result = from d in data
                         select new Dictionary<string, string>()
             { 
                { "sernum", (string)d.Attribute("sernum") },
                 { "rectime", (string)d.Attribute("rectime") },
                 { "area", (string)d.Attribute("area") },
                 { "machine", (string)d.Attribute("machine") },
                 {"cell",(string)d.Attribute("cell")}
             };

            foreach (var item in result)
            {
                foreach (var y in item)
                {
                    hash.Add(y.Key, y.Value);
                }
            }    
Posted
Updated 6-Aug-13 19:56pm
v2
Comments
ArunRajendra 7-Aug-13 1:48am    
Post you code.

The methods Element() and Elements() are defined in XContainer[^] and not XmlDocument[^] so if you want to use them you'll need to load your XML document as an XDocument[^].
 
Share this answer
 
Comments
valluru's 7-Aug-13 2:02am    
thank you its working
Sergey Alexandrovich Kryukov 7-Aug-13 2:14am    
Good catch :-), a 5.
—SA
make sure you have included the following namespaces-
Sysstem.XML.LINQ<br />
Sysstem.LINQ
 
Share this answer
 
Comments
valluru's 7-Aug-13 1:55am    
yes....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900