- Home /
Question by
ChuckSaldana · Jan 24, 2011 at 10:29 PM ·
xmlwhile-loop
XmlTextReader problem
Hi,
I have the following XML file:
<?xml version="1.0"?><!--This document contains the profiles that have been created.--><Profiles>
<Profile>
<name>One</name>
<date>Two</date>
</Profile>
<Profile>
<name>One</name>
<date>Two</date>
</Profile>
<Profile>
<name>One</name>
<date>Two</date>
</Profile>
</Profiles>
The problem is that when I use XmlTextReader, it only reads the first profile and ignore the second and third.
public ArrayList ReadProfiles() {
ArrayList result = new ArrayList();
Hashtable currentProfile = null;
string currentName = "";
string currentValue = "";
XmlTextReader textReader = new XmlTextReader(profilesPath);
// Read until end of file
while (textReader.Read()) {
switch(textReader.NodeType) {
case XmlNodeType.Text: {
currentValue = textReader.Value;
Debug.Log("found text = " + currentValue);
}
break;
case XmlNodeType.Element: {
currentName = textReader.Name;
switch(currentName) {
case "Profiles":
Debug.Log("found profiles");
break;
case "Profile":
Debug.Log("found profile");
break;
case "name":
Debug.Log("found name");
break;
case "date":
Debug.Log ("found date");
break;
default:
Debug.Log("default in");
break;
}
}
break;
case XmlNodeType.Comment:
Debug.Log("found comment");
break;
case XmlNodeType.EndElement:
Debug.Log("found end element" + textReader.Name.ToString());
break;
default:
Debug.Log("default out");
break;
}
}
textReader.Close();
return result;
}
so I get:
Comment
Best Answer
Answer by ChuckSaldana · Jan 24, 2011 at 11:06 PM
I found that Debug.Log() prints very slowly each result. I couldn't use Console.WriteLine() but instead I concatenated every result in the same string and at the end the parsing was complete.
Your answer
![](https://koobas.hobune.stream/wayback/20220613100920im_/https://answers.unity.com/themes/thub/images/avi.jpg)