Hi All,
I have a xml file like this:
I have a xml file like this:
test1.xml
test2.xml
test3.xml
test4.xml
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
Advance thanks,
Darma
VulpesPosted Sep 30, 2014, 9:37 AM
The output is:
darma tejaPosted Sep 30, 2014, 10:41 AM
Abhishek KumarPosted Sep 30, 2014, 8:26 AM
Abhishek
darma tejaPosted Sep 30, 2014, 8:22 AM
My code is like this:
Thanks,
Darma
darma tejaPosted Sep 30, 2014, 7:29 AM
It means that two root elements present in the xml file.
Thanks,
Darma
Abhishek KumarPosted Sep 30, 2014, 6:09 AM
D:\My Development\TestWeb\TestWeb\Test.xml
This is my local machine test location for test file , you need to provide the your path where your xml file is residing.
Abhishek
darma tejaPosted Sep 30, 2014, 5:58 AM
I am getting exception exactly at: doc.Load(@"D:\My Development\TestWeb\TestWeb\Test.xml");
The exception is There are multiple root elements present. Line 8, position the second.
and I would like to get the output
Thanks,
Darma
Abhishek KumarPosted Sep 30, 2014, 5:44 AM
if your xml file would be as below
xml version="1.0" encoding="utf-8" standalone="yes"?>
<informations>
<information>
<information1 name="region">Asiainformation1>
<information1 name="mainlang">ENGinformation1>
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>
informations>
i have added a root information.
Please try this code below..
XmlDocument doc = new XmlDocument();
doc.Load(@"D:\My Development\TestWeb\TestWeb\Test.xml");
// Root element
System.Xml.XmlElement root = doc.DocumentElement;
System.Xml.XmlElement information = (System.Xml.XmlElement)root.ChildNodes[0].ChildNodes[0];
string information1 = information.ChildNodes[0].InnerText;
if (information1 == "ENG")
{
//Put your logic here
}
Hope this will help.
Abhsihek
Abhishek KumarPosted Sep 30, 2014, 5:22 AM
Abhishek
darma tejaPosted Sep 30, 2014, 5:11 AM
Thanks for the message. Actually It is multiple root level element xml file. I cannot change this xml file, because i get it from customer.
I think we can artificially add a root to this xml file, is it works?
Thanks,
Darma
Abhishek KumarPosted Sep 30, 2014, 4:58 AM
Your Xml file seems to have issue as it has multiple root level element.
Could you please verify and provide the proper xml.?
Abhishek