我想读取 XML 文件并保存 InnerText-Strings,但它会因 SystemNullReference 错误而崩溃。我认为我阅读它的方式是错误的,但我不确定。
XML 文件:
<?xml version="1.0" encoding="Windows-1252" standalone="no"?>
<schema>
<Hintergrund>#FFFFFFFF</Hintergrund>
<Zahlen>#FFFFFFFF</Zahlen>
<Text>#FFFFFFFF</Text>
<Zeichenketten>#FFFFFFFF</Zeichenketten>
<Tags>#FF000000</Tags>
<Direktiven>#FF000000</Direktiven>
<Ausdruecke>#FF000000</Ausdruecke>
<Initialisierer>#FF000000</Initialisierer>
<Modifizierer>#FF000000</Modifizierer>
<Booleanische>#FF000000</Booleanische>
<Operator>#FF000000</Operator>
<Kommentare>#FF000000</Kommentare>
</schema>
阅读:
foreach (XmlNode node in doc.SelectNodes("/schema/*"))
{
switch (node.Name)
{
case "Hintergrund":
colorBG = (Color)ColorConverter.ConvertFromString(node["Hintergrund"].InnerText);
break;
case "Zahlen":
colorNumbers = (Color)ColorConverter.ConvertFromString(node["Zahlen"].InnerText);
break;
case "Text":
colorText = (Color)ColorConverter.ConvertFromString(node["Text"].InnerText);
break;
case "Zeichenketten":
colorStrings = (Color)ColorConverter.ConvertFromString(node["Zeichenketten"].InnerText);
break;
case "Tags":
colorTags = (Color)ColorConverter.ConvertFromString(node["Tags"].InnerText);
break;
case "Direktiven":
colorDirectives = (Color)ColorConverter.ConvertFromString(node["Direktiven"].InnerText);
break;
case "Ausdruecke":
colorStatements = (Color)ColorConverter.ConvertFromString(node["Ausdruecke"].InnerText);
break;
case "Initialisierer":
colorInitial = (Color)ColorConverter.ConvertFromString(node["Initialisierer"].InnerText);
break;
case "Modifizierer":
colorModifiers = (Color)ColorConverter.ConvertFromString(node["Modifizierer"].InnerText);
break;
case "Booleanische":
colorBools = (Color)ColorConverter.ConvertFromString(node["Booleanische"].InnerText);
break;
case "Operator":
colorOperators = (Color)ColorConverter.ConvertFromString(node["Operator"].InnerText);
break;
case "Kommentare":
colorComments = (Color)ColorConverter.ConvertFromString(node["Kommentare"].InnerText);
break;
}
}
请告诉我为什么它不起作用。