XMLを解析し、XMLreaderを使用してXMLからすべての情報を取得しようとしています。それは何らかの理由でタイトルからエラーを投げている。ここでは、XMLは次のとおりです。ReadElementContentAsStringメソッドは、ノード型のテキストではサポートされていません。
<?xml version="1.0" encoding="utf-8" ?>
<queries>
<selectparent table="Associates">"SELECT * FROM @table"</selectparent>
<selectchild table="VehicleContract">"SELECT * FROM @table"</selectchild>
<addchild table="VehicleContract" read="contractId, regNr, assoc_id, percentage, vehicleType, trailerNr">"INSERT into @table (contractId, regNr, assoc_id, percentage, vehicleType, trailerNr) VALUES (@id, @reg, @assort, @perc, @type, @trailer)"</addchild>
<updatechild table="VehicleContract" read="contractId, regNr, assoc_id, percentage, vehicleType, trailerNr">"UPDATE @table SET [email protected], [email protected], [email protected], [email protected], [email protected] WHERE [email protected]"</updatechild>
<removechild table="VehicleContract" read="id">"DELETE from @table WHERE [email protected]"</removechild>
</queries>
そして、私の方法:
public string selectParent, selectChildren, addChildren, updateChildren, removeChildren;
public string[] addParams, updateParams, removeParams;
XmlTextReader reader = new XmlTextReader(base.Path);
reader.WhitespaceHandling = WhitespaceHandling.None;
reader.Read();
reader.Read();
reader.Read();
selectParent = reader.ReadElementContentAsString();
reader.Read();
selectChildren = reader.ReadElementContentAsString();
addParams = reader.GetAttribute("read").Split(',');
addChildren = reader.ReadElementContentAsString();
updateParams = reader.GetAttribute("read").Split(',');
updateChildren = reader.ReadElementContentAsString();
removeParams = reader.GetAttribute("read").Split(',');
removeChildren = reader.ReadElementContentAsString();
私は、この行のエラーを取得: selectParent = reader.ReadElementContentAsString
問題は何?私はreader.Read()
を追加し続けました。なぜなら、同じエラーが発生していたのですが、異なるノードタイプになってしまったからです。
私の知る限り、テーブル属性はクエリの@tableを置き換えるべきですが、何かが正しくありません。何か案は?
を使用します。 XMLを文字列として埋め込み、 'new MemoryStream(Encoding.UTF8.GetBytes(xml))'を使用してXMLを読み込むと、あなたのコードは私のために働きます。また、コードをデバッグして 'reader.NodeType'と' reader.Name'を見ると、ファイル内のどこにいるのかが分かります。 –
私は完全なパスを使用し、デバッガでは、それは私にXMLにかかります。その行に着くと、 "SELECT * FROM @ table"と表示され、エラーがスローされます:/ – Mocktheduck