Reading xml data

  • Thread starter Thread starter pmclinn
  • Start date Start date
P

pmclinn

How should one import data that is stored in the following fashion?

<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) 000-0000</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) 000-0000</Phone>
<Lon>-71.3298</Lon>
<Lat>42.8958</Lat>
</Restaurant>
</Restaurants>
 
Hi,

http://msdn.microsoft.com/library/d...e/html/vbtskcodeexamplereadingxmlfromfile.asp

Ken
-------------------------
How should one import data that is stored in the following fashion?

<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) 000-0000</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) 000-0000</Phone>
<Lon>-71.3298</Lon>
<Lat>42.8958</Lat>
</Restaurant>
</Restaurants>
 
pmclinn,

This is a dataset so
\\\
dim ds as new dataset
ds.readXML("path to the file")
datagrid1.datasource = ds.tables(0)
///
Will show it in a datagrid.

I hope this helps?

Cor
 
pmclinn said:
How should one import data that is stored in the following fashion?

<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) 000-0000</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) 000-0000</Phone>
<Lon>-71.3298</Lon>
<Lat>42.8958</Lat>
</Restaurant>
</Restaurants>

Depends on import to what really...
Import implies to database to my mind.
Just in case that's what you mean.

If you're talking sql server then sqlxmlbulkload will import big xml files
and you could use a vbscript DTS to do so.

Otherwise, you already have a couple answers like xmlreader.
 
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
 
Peter,

What is the reason that you use that expensive code while I showed that it
can be done in two lines?
(Which I even tested for you by the way with your file)

Cor
 
Peter,

You can as well use the viewstate and send it with the page.

However how do you want to read it from the grid.
I could not succeed in that?

Cor
 
pmclinn said:
If I read the data from the grid won't that cost more in the long run?


I'm still confused as to what you're trying to accomplish.

You want to get the data out the file into some program.
To do what?
To just display it?
I guess not.
 
The data is stored in XML format simply because of re-usablity factors.
Everynight I run a program that finds all the current restaurant
listings and there GPS coordinates. This data is then pushed up to a
remote SQL Server, where I will have to preform distance and positional
operations on the data. So transfering the data to the grid is
currently out of the questions.

So I was hoping to be able to select 'typed elements' by name for code
readiblity reasons.
 
pmclinn said:
The data is stored in XML format simply because of re-usablity factors.
Everynight I run a program that finds all the current restaurant
listings and there GPS coordinates. This data is then pushed up to a
remote SQL Server, where I will have to preform distance and positional
operations on the data. So transfering the data to the grid is
currently out of the questions.

So I was hoping to be able to select 'typed elements' by name for code
readiblity reasons.

You still haven't told us why the techniques suggested are no good to you.
So at this point I can only ask the same question again....


From this I get you want the data from one server to be used on another
server.
It's a batch over-night process.
Correct?

So my next question.

What's wrong with my initial suggestion:
Load it into a table using sqlxmlbulkload.
Use a DTS package scheduled to run nightly.
Stick it in a table.
Once you have it in your remote database you can do whatever you want with
the data there.
 
My provider [Godaddy.com] does not give me access to the DTS
packages unfortunately. I'm using a hosted plan and not a dedicated
server for obvious cost reasons. Let me put it this way, Godaddy only
allows end users to push content up via web forms and/or through a
pethetic csv. loader utility that crashes half way through most
uploads.

Yes. This is a nightly batch run.

The process only imports new addresses and account information so I
finally ended up creating a password protected directory that allows me
to push the records via an asp form into the database. LOL.
Definately not an optimum situation.

I'm just trying to get the site up and running this month to show to
prospective clients. If the test goes well then I'll have funding to
lease a dedicated server.

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top