Extracting XML Information from other Website

J

Jonathan Wood

I'd like to write a shareware Website that supports PAD files.

This involves being able to download an XML file from another site and
extracting the data it contains.

I'm still new to ASP.NET. Any tips or examples on doing this?

Thanks!
 
A

Alexey Smirnov

I'd like to write a shareware Website that supports PAD files.

This involves being able to download an XML file from another site and
extracting the data it contains.

I'm still new to ASP.NET. Any tips or examples on doing this?

here's one

Dim lcUrl As String = "http://.../rss/"
Dim loHttp As HttpWebRequest = CType(WebRequest.Create(lcUrl),
HttpWebRequest)
Dim enc As Encoding = Encoding.GetEncoding(1252)
Dim loWebResponse As HttpWebResponse
Dim loResponseStream As System.IO.StreamReader

loWebResponse = CType(loHttp.GetResponse(), HttpWebResponse)
loResponseStream = New
System.IO.StreamReader(loWebResponse.GetResponseStream(), enc)

Dim reader As XmlTextReader
reader = New XmlTextReader(loResponseStream)

Dim doc As XmlDocument = New XmlDocument()
doc.Load(reader)
reader.Close()

Dim xmlItemChild As XmlNode
Dim xmlChild As XmlNode

Dim nsMgr As XmlNamespaceManager = New
XmlNamespaceManager(doc.NameTable)
nsMgr.AddNamespace("rss", doc.DocumentElement.NamespaceURI)

Dim nodeList As XmlNodeList
nodeList = doc.SelectNodes("//rss:item", nsMgr)

For Each xmlItemChild In nodeList

Response.Write (xmlItemChild("link").InnerText)
Response.Write (xmlItemChild("title").InnerText)

Next

loWebResponse.Close()
loResponseStream.Close()
 
M

Mark Rae [MVP]

This involves being able to download an XML file from another site and
extracting the data it contains.

ASP.NET and XML really are "made for each other", so you should have no
problems with this...

Firstly, getting hold of the XML document can be done like this:
http://msdn2.microsoft.com/en-us/library/875kz807(vs.80).aspx

Then, you have a whole slew of possibilities depending how the XML document
is structured and what you want to do with the data it contains.

Your best bet is probably to do a search in the MSDN Library for things
like:

XmlElement
XmlNode

What sort of structure will the XML document have?
 
J

Jonathan Wood

Thanks Alexey. I've printed your post and will go over it carefully later.
 
J

John Timney \(MVP\)

Jonathan,

To add to what Alexy has given you, structured XML can be bound to very
easily - even remote XML files over http and using standard binding can save
you a lot of work as you quite literally deal with it as a set of data once
you have it. The code can be as simple as:

ds = new DataSet();
ds.ReadXml(URLpath, XmlReadMode.Auto);

I have an example on my site that might interest you as it extends this a
bit.

http://www.johntimney.com/blog/Setting+DataSetReadXML+Timeout+Values.aspx

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
 

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

Top