OK, for some reason this XML stuff eludes me. Im trying to do the following as an exercise in learning it.
I have an xml file with this content:
All I want to do is find out how to access the elements that hold the data. Im tried the DOM and Xpath and now xmlTextReader. I have got further with the latter but it all seems messy.
Here is some code:
The hashtable is there as Im trying to figure out a way to store the data so I can move back and forth through it.
All help gratefully recieved.
Thnx
I have an xml file with this content:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v4.2 -->
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
<CD>
<TITLE>Greatest Hits</TITLE>
<ARTIST>Dolly Parton</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>RCA</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1982</YEAR>
</CD>
</CATALOG>
All I want to do is find out how to access the elements that hold the data. Im tried the DOM and Xpath and now xmlTextReader. I have got further with the latter but it all seems messy.
Here is some code:
Code:
Dim xReader As Xml.XmlTextReader = New Xml.XmlTextReader("C:\Documents and Settings\paul\My Documents\Visual Studio Projects\SampleSchema\cd_catalog.xml")
Dim htCDCollection As Hashtable = New Hashtable
Dim strNodeName As String
Dim intCounter As Integer
Do While xReader.Read
If xReader.NodeType = XmlNodeType.Element Then
htCDCollection.Add(xReader.Name & intCounter, Nothing)
strNodeName = xReader.Name & intCounter
Me.rtbCDCollection.Text = Me.rtbCDCollection.Text & xReader.Name & vbCrLf & vbTab
End If
If xReader.NodeType = XmlNodeType.Text Then
htCDCollection.Item(strNodeName) = xReader.Value
Me.rtbCDCollection.Text = Me.rtbCDCollection.Text & xReader.Value & vbCrLf
End If
intCounter += 1
Loop
xReader.Close()
xReader = Nothing
The hashtable is there as Im trying to figure out a way to store the data so I can move back and forth through it.
All help gratefully recieved.
Thnx