stdecden
25-12-2007, 17:03
Salve a tutti!
Ho un problemino con la classe XmlTextReader. Dato il seguente file xml:
<?xml version="1.0" encoding="utf-8"?>
<level id="001_BY_D" rversion="0.2.5">
<info>
<name>001</name>
<description></description>
<author>D</author>
<date>2007-12-24</date>
<sky>BlueBlue</sky>
<border texture="Asphalt1"/>
</info>
<limits left="-33.723425" right="33.723425" top="25.387795" bottom="-25.387795"/>
<entity id="path2176" typeid="PlayerStart">
<position y="7.36220615" x="-18.373425"/>
<size r="0.4"/>
</entity>
...
ed il seguente codice:
this.Show();
System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader("001.lvl");
TreeNode cnode = xmlTreeView.Nodes.Add("001.lvl");
while (reader.Read())
{
if (reader.NodeType == System.Xml.XmlNodeType.Element)
{
//MessageBox.Show(reader.Name);
cnode = cnode.Nodes.Add(reader.Name);
}else if(reader.NodeType == System.Xml.XmlNodeType.EndElement)
{
Application.DoEvents();
//MessageBox.Show("<\\>");
cnode = cnode.Parent;
}else if(reader.NodeType == System.Xml.XmlNodeType.Attribute)
{
//MessageBox.Show("Attr: " + reader.Name);
cnode.Nodes.Add(reader.Name);
}
xmlTreeView.Nodes[0].ExpandAll();
}
ottengo come risultato (vedi allegato)
Grazie in Anticipo!
Ho un problemino con la classe XmlTextReader. Dato il seguente file xml:
<?xml version="1.0" encoding="utf-8"?>
<level id="001_BY_D" rversion="0.2.5">
<info>
<name>001</name>
<description></description>
<author>D</author>
<date>2007-12-24</date>
<sky>BlueBlue</sky>
<border texture="Asphalt1"/>
</info>
<limits left="-33.723425" right="33.723425" top="25.387795" bottom="-25.387795"/>
<entity id="path2176" typeid="PlayerStart">
<position y="7.36220615" x="-18.373425"/>
<size r="0.4"/>
</entity>
...
ed il seguente codice:
this.Show();
System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader("001.lvl");
TreeNode cnode = xmlTreeView.Nodes.Add("001.lvl");
while (reader.Read())
{
if (reader.NodeType == System.Xml.XmlNodeType.Element)
{
//MessageBox.Show(reader.Name);
cnode = cnode.Nodes.Add(reader.Name);
}else if(reader.NodeType == System.Xml.XmlNodeType.EndElement)
{
Application.DoEvents();
//MessageBox.Show("<\\>");
cnode = cnode.Parent;
}else if(reader.NodeType == System.Xml.XmlNodeType.Attribute)
{
//MessageBox.Show("Attr: " + reader.Name);
cnode.Nodes.Add(reader.Name);
}
xmlTreeView.Nodes[0].ExpandAll();
}
ottengo come risultato (vedi allegato)
Grazie in Anticipo!