【发布时间】:2010-11-07 12:45:39
【问题描述】:
大家好 我曾尝试编写一个简单的 xml 阅读器,但发现它无意中跳过了 xml 文件中的所有其他元素。
我猜我告诉它两次移动到下一个元素,但我不确定发生了什么或解决方案是什么。
任何帮助将不胜感激:)
这里是代码示例和xml文件示例
public LevelLoader(string theLevelFile ,ContentManager theContent)
{
XmlTextReader reader = new XmlTextReader(theLevelFile);
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "tilerow":
{
currentRow = currentRow + 1;
Console.WriteLine("row found");
currentCol = 0;
break;
}
case "tilecol":
{
Console.WriteLine("col found");
currentTexture = reader.ReadElementContentAsFloat();
currentCol = currentCol + 1;
break;
}
}
}
}
}
示例 xml
<tilerow>
<tilecol>1</tilecol><tilecol>2</tilecol><tilecol>3</tilecol><tilecol>4</tilecol><tilecol>5</tilecol><tilecol>6</tilecol><tilecol>7</tilecol><tilecol>8</tilecol><tilecol>9</tilecol><tilecol>10</tilecol>
</tilerow>
【问题讨论】:
-
为什么不用linq to xml?
-
您的示例无法编译。既然你有bug,我们需要看代码。
-
对我来说编译得很好,他正在使用我删除的一些全局成员
-
它缺少虚空,但这已经够小了,晨雾还没有完全消散。