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 の読み取りの試行は有効である必要があります。