我正在使用 Silverlight 项目中的 XmlReader 编写文件阅读器。但是,我遇到了一些错误(特别是在 XmlReader.ReadStartElement 方法周围),这让我相信我误解了如何在某个地方使用它。
基本上,这是我正在使用的 Xml 格式的示例:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<root>
<EmptyElement />
<NonEmptyElement Name="NonEmptyElement">
<SubElement Name="SubElement" />
</NonEmptyElement>
</root>
下面是一些代码示例,其使用方式与我使用它的方式相同:
public void ReadData(XmlReader reader)
{
// Move to root element
reader.ReadStartElement("root");
// Move to the empty element
reader.ReadStartElement("EmptyElement");
// Read any children
while(reader.ReadToNextSibling("SubEmptyElement"))
{
// ...
}
// Read the end of the empty element
reader.ReadEndElement();
// Move to the non empty element
reader.ReadStartElement("NonEmptyElement"); // NOTE: This is where I get the error.
// ...
}
所以,本质上,我只是试图阅读每个元素和任何包含的子元素。我在突出显示的点得到的错误如下:
错误描述
[Xml_InvalidNodeType] 参数:无,10,8 调试资源字符串不可用。通常,关键和论据提供了足够的信息来诊断问题。请参阅http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.51204.0&File=System.Xml.dll&Key=Xml_InvalidNodeType
错误堆栈跟踪
在 System.Xml.XmlReader.ReadStartElement(字符串名称)在 ----------------
对此的任何建议或指导将不胜感激。
编辑 由于该阅读器需要相当通用,因此可以假设 Xml 可能包含作为 EmptyElement 的子元素的元素。因此,读取任何 SubEmptyElements 的尝试应该是有效的。