C#およびXMLデータの使用法は初めてです。
次のxmlデータがあります。このXMLファイルには、スタイル情報が関連付けられていないようです。ドキュメントツリーを以下に示します。
<response>
<auctions>
<auction>
<id>90436</id>
<user>blabla</user>
<title>title name</title>
<value>10000.00</value>
<period>36</period>
<www/>
</auction>
<auction>
<id>90436</id>
<user>blabla</user>
<title>title name</title>
<value>10000.00</value>
<period>36</period>
<www/>
</auction>
</auctions>
</response>
私はそのC#コードを使用します。(Form1で使用されるクラスです)
public IXmlNamespaceResolver ns { get; set; }
public string[] user,id,title,value,period;
public void XmlRead(string url)
{
// Create a new XmlDocument
XPathDocument doc = new XPathDocument(url);
// Create navigator
XPathNavigator navigator = doc.CreateNavigator();
// Get forecast with XPath
XPathNodeIterator nodes = navigator.Select("/response/auctions", ns);
int i = 0;
foreach (XPathNavigator oCurrentPerson in nodes)
{
userName[i] = oCurrentPerson.SelectSingleNode("user").Value;
userId[i] = int.Parse(oCurrentPerson.SelectSingleNode("id").Value);
title[i] = oCurrentPerson.SelectSingleNode("title").Value;
value[i] = oCurrentPerson.SelectSingleNode("value").Value;
period[i] = oCurrentPerson.SelectSingleNode("period").Value;
i++; }
}
エラーが発生しました:オブジェクト参照がオブジェクトのインスタンスに設定されていません。
userName [i] = oCurrentPerson.SelectSingleNode( "user")。Value;
userName、userIdなどの単一の文字列変数を[]なしで使用すると、すべてが正しく機能しました。
前もって感謝します