darma teja

darma teja

  • NA
  • 496
  • 337k

Get value from xml file

Sep 30 2014 4:24 AM
Hi All,
I have a xml file like this:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<information>
<information1 name="region">Asia</information1>
<information1 name="mainlang">ENG</information1>
</information>
<Data>
<dataname lang="Hindi" group="Asia">
test1.xml
</dataname>
<dataname lang="Chinese" group="Asia">
test2.xml
</dataname>
<dataname lang="English" group="US">
test3.xml
</dataname>
<dataname lang="Polish" group="EU">
test4.xml
</dataname>
</Data>


I am trying to get information/information1['mainlang']  == ENG from xml file.

and also 

I would like to get All "lang, group, dataname" from xml file.

I am getting following error "invalid data at the root level. line 1, position the first" for the following code:

             XDocument doc = XDocument.Load(path);
            XElement test = doc.Root;
            var nodeList = doc.SelectNodes("//dataname");


Advance thanks,
Darma

Answers (11)