Here is the code that wrote the file:
'ExportArray is an arraylist
'and Details is a structure
'I'm taking the structures that have been saved into the arraylist and
then exporting them using the textwriter. See comments below code:
'_______________________Write Code
Dim mywriter As System.Xml.XmlTextWriter
mywriter = New System.Xml.XmlTextWriter("c:\NH.xml", Nothing)
With mywriter
.Indentation = 4
.IndentChar = " "
.Formatting = .Indentation
.WriteStartDocument()
.WriteComment("NH Listing")
.WriteStartElement("Restaurants")
For i As Integer = 0 To ExportArray.Count - 1
.WriteStartElement("Restaurant")
.WriteElementString("Category", CType(ExportArray(i),
Details).strCat)
.WriteElementString("Name", CType(ExportArray(i),
Details).strName)
.WriteElementString("Address", CType(ExportArray(i),
Details).strAddress)
.WriteElementString("StreetAddress",
CType(ExportArray(i), Details).strStreetAddress)
.WriteElementString("City", CType(ExportArray(i),
Details).strCityName)
.WriteElementString("State", CType(ExportArray(i),
Details).strStateName)
.WriteElementString("Zip", CType(ExportArray(i),
Details).strZip)
.WriteElementString("Phone", CType(ExportArray(i),
Details).strPhone)
.WriteElementString("Lon", CType(ExportArray(i),
Details).Lon)
.WriteElementString("Lat", CType(ExportArray(i),
Details).Lat)
.WriteEndElement()
Next
.WriteEndElement()
.WriteEndDocument()
End With
'End Write Code
'Sample output:
<?xml version="1.0" ?>
- <!-- NH Listing
-->
- <Restaurants>
- <Restaurant>
<Category>American Restaurants</Category>
<Name>APPLEBEES</Name>
<Address>1273 HOOKSETT RD, HOOKSETT, NH 03106</Address>
<StreetAddress>1273 HOOKSETT RD</StreetAddress>
<City>HOOKSETT</City>
<State>NH</State>
<Zip>03106</Zip>
<Phone>(603) 627-3000</Phone>
<Lon>-71.4363</Lon>
<Lat>43.0484</Lat>
</Restaurant>
- <Restaurant>
<Category>American Restaurants</Category>
<Name>APPLEBEES</Name>
<Address>14 MANCHESTER RD, DERRY, NH 03038</Address>
<StreetAddress>14 MANCHESTER RD</StreetAddress>
<City>DERRY</City>
<State>NH</State>
<Zip>03038</Zip>
<Phone>(603) 432-5600</Phone>
<Lon>-71.3298</Lon>
<Lat>42.8958</Lat>
</Restaurant>
'End sample output....'truncated sample
'----------------------More comments
I have found that I can import the enteries using the code below but I
want to refrence by type. So in the example below I refrence the
item(0) but I would rather refrence it as Category...Name...Address....
'---------------------My code right now
Begin read code:
Dim s As New Details
Dim al As New ArrayList
Try
Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlNode
'Create the XML Document
m_xmld = New XmlDocument
'Load the Xml file
m_xmld.Load("C:\NH.xml")
'Get the list of name nodes
m_nodelist = m_xmld.SelectNodes("/Restaurants/Restaurant")
'Loop through the nodes
For Each m_node In m_nodelist
s.strCat = m_node.ChildNodes.Item(0).InnerText
s.strName = m_node.ChildNodes.Item(1).InnerText
Console.Write(s.strCat)
Next
Catch errorVariable As Exception
'Error trapping
Console.Write(errorVariable.ToString())
End Try
'Any direction would be appreciated. Thanks