XML, Помогите устранить error
Среда Visual Basic STUDIO’2010 Professional
Private Sub XmlIntoAlllTextBoxToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XmlIntoAlllTextBoxToolStripMenuItem.Click
Dim doc4 As New XmlDocument()
doc4.Load("test4.xml")
Dim firstCD As XmlElement = DirectCast(doc4.DocumentElement.FirstChild, XmlElement)
Dim artist As XmlElement = DirectCast(firstCD.GetElementsByTagName("artist")(0), XmlElement)
Dim title As XmlElement = DirectCast(firstCD.GetElementsByTagName("title")(0), XmlElement)
Console.WriteLine("Artist={0}, Title={1}", artist.InnerText, title.InnerText)
' вышестоящая строка приводит к error:
[color=red][b]' Ссылка на объект не указывает на экземпляр объекта. – [/b][/color]
End Sub
test4.xml имеет вид:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="orders.xsl"?>
<order id="ord123456">
<customer id="cust0921">
<first-name>Dare</first-name>
<last-name>Obasanjo</last-name>
<address>
<street>One Microsoft Way</street>
<city>Redmond</city>
<state>WA</state>
<zip>98052</zip>
</address>
</customer>
<items>
<compact-disc>
<price>16.95</price>
<artist>Nelly</artist>
<title>Nellyville</title>
</compact-disc>
<compact-disc>
<price>17.55</price>
<artist>Baby D</artist>
<title>Lil Chopper Toy</title>
</compact-disc>
</items>
</order>
Спасибо.