I’m reading a XML file in a very simple way:
XmlTextReader reader = new XmlTextReader(dataPath);
while(reader.Read()){
switch (reader.Name){
case "language":
Debug.Log(reader.ReadString());
break;
case "file":
Debug.Log(reader.ReadString());
break;
case "arg":
Debug.Log(reader.ReadString());
break;
}
}
Where my xml is like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<config>
<language>EN-US</language>
<file>\File\Doc\sample.txt</file>
</config>
<data>
<arg>LKR</language>
</dara>
My first problem is this:
XmlException: Multiple document element was detected. file:///C:/prj/as/sample.xml Line 7, position 2.
Mono.Xml2.XmlTextReader.ReadStartTag ()
Mono.Xml2.XmlTextReader.ReadContent ()
Mono.Xml2.XmlTextReader.Read ()
System.Xml.XmlTextReader.Read ()
LectorXML.Start () (at as/sampleXML.cs:17)
And second, my output is language and file, but NO arg. Maybe because is a different node? How can i fix this?
You can only have a single node element at the root of your document. You have a
<config>and a<data>. Wrap them in a single document element: