Я получаю сообщение об ошибке NullReferenceException для "_attr.Append (xmlNode.Attributes [" name "]);".
namespace SMAS
{
class Profiles
{
private XmlTextReader _profReader;
private XmlDocument _profDoc;
private const string Url = "http://localhost/teamprofiles.xml";
private const string XPath = "/teams/team-profile";
public XmlNodeList Teams{ get; private set; }
private XmlAttributeCollection _attr;
public ArrayList Team { get; private set; }
public void GetTeams()
{
_profReader = new XmlTextReader(Url);
_profDoc = new XmlDocument();
_profDoc.Load(_profReader);
Teams = _profDoc.SelectNodes(XPath);
foreach (XmlNode xmlNode in Teams)
{
_attr.Append(xmlNode.Attributes["name"]);
}
}
}
}
файл teamprofiles.xml выглядит как
<teams>
<team-profile name="Australia">
<stats type="Test">
<span>1877-2010</span>
<matches>721</matches>
<won>339</won>
<lost>186</lost>
<tied>2</tied>
<draw>194</draw>
<percentage>47.01</percentage>
</stats>
<stats type="Twenty20">
<span>2005-2010</span>
<matches>32</matches>
<won>18</won>
<lost>12</lost>
<tied>1</tied>
<draw>1</draw>
<percentage>59.67</percentage>
</stats>
</team-profile>
<team-profile name="Bangladesh">
<stats type="Test">
<span>2000-2010</span>
<matches>66</matches>
<won>3</won>
<lost>57</lost>
<tied>0</tied>
<draw>6</draw>
<percentage>4.54</percentage>
</stats>
</team-profile>
</teams>
Я пытаюсь извлечь имена всех команд из ArrayList. Затем я извлеку все статистические данные всех команд и покажу их в моем приложении. Не могли бы вы помочь мне с этим исключением из нулевой ссылки?