Below is the code I am using. What I don't undersatnd is how I can get a
the value for each element into a variable so I can do some work with them.
Imports Microsoft.VisualBasic
Imports System
Imports System.Xml
namespace HowTo.Samples.XML
public class XmlReadFromURLSample
dim CustIDc as string= ""
Dim prodidq as string= "639749"
'URL to read from
dim localURL as String =
"http://intouch.computer2000.com/xml/xmlonl.asp?custid=325009"& "&" &
"prodid="& ProdIDq
public shared sub Main()
Dim myXmlReadFromURLSample as XmlReadFromURLSample = new
XmlReadFromURLSample()
myXmlReadFromURLSample.Run()
end sub
public sub Run()
Dim myXmlURLReader as XmlTextReader
try
' Reading xml from a URL
Console.WriteLine ("Initializing XmlTextReader ...")
Console.WriteLine ("Reading from URL: {0}", localURL)
' Load the XmlTextReader from the URL
myXmlURLReader = new XmltextReader (localURL)
Console.WriteLine ("Processing ...")
Console.WriteLine ()
FormatXml(myXmlURLReader)
catch e as Exception
Console.WriteLine ("Exception: {0}", e.ToString())
Console.WriteLine ("Make sure that, {0} exists", localURL)
finally
Console.WriteLine()
Console.WriteLine("Processing of URL complete.")
' Finished with XmlTextReader
If Not myXmlURLReader Is Nothing
myXmlURLReader.Close()
End If
end try
end sub
private shared Sub FormatXml (reader as XmlTextReader)
Dim declarationCount, piCount, docCount, commentCount, elementCount
as Integer
Dim attributeCount, textCount, whitespaceCount as Integer
Dim Element as string
Dim text as String
While reader.Read()
Select (reader.NodeType)
case XmlNodeType.XmlDeclaration:
' Format (reader, "XmlDeclaration")
declarationCount += 1
case XmlNodeType.ProcessingInstruction:
' Format (reader, "ProcessingInstruction")
piCount += 1
case XmlNodeType.DocumentType:
' Format (reader, "DocumentType")
docCount += 1
case XmlNodeType.Comment:
' Format (reader, "Comment")
commentCount += 1
case XmlNodeType.Element:
Format (reader, "Element")
elementCount += 1
if (reader.HasAttributes)
attributeCount += reader.AttributeCount
end if
case XmlNodeType.Text:
Format (reader, "Text")
textCount += 1
case XmlNodeType.Whitespace:
whitespaceCount += 1
End Select
End While
' Display the Statistics for the file
'Console.WriteLine ()
'Console.WriteLine("Statistics for URL")
'Console.WriteLine ()
'Console.WriteLine("XmlDeclaration: " & declarationCount)
'Console.WriteLine("ProcessingInstruction: " & piCount)
'Console.WriteLine("DocumentType: " & docCount)
'Console.WriteLine("Comment: " & commentCount)
'Console.WriteLine("Element: " & elementCount)
'Console.WriteLine("Attribute: " & attributeCount)
'Console.WriteLine("Text: " & textCount)
'Console.WriteLine("Whitespace: " & whitespaceCount)
End Sub
private shared Sub Format(byref reader as XmlTextReader , nodeType as
String)
' Format the output
'Console.Write(reader.Depth & " ")
'Console.Write(reader.AttributeCount & " ")
Dim i as Integer
for i = 0 to reader.Depth - 1
'Console.Write(Strings.chr(9))
Next
'if reader.name = "DESC" then
Console.Write("1:" & reader.Name & VBCRLF & "2:" & reader.Value)
'end if
'Display the attributes values for the current node
'if (reader.HasAttributes)
'Console.Write(" Attributes:")
'Dim j as Integer
'for j = 0 to reader.AttributeCount - 1
'Console.Write(" [{0}] " & reader(j), j)
'next
'End if
Console.WriteLine()
End Sub
end Class 'XMLNodeReaderSample
end Namespace 'HowTo.Samples.XML
----------------------------ASPX file----------
<%@ Page Language="VB" Debug="true" Src="XmlReadFromUrl.vb"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="HowTo.Samples.XML" %>
<html>
<head>
<link rel="stylesheet" href="intro.css">
</head>
<body style="background-color:f6e4c6">
<form action="XmlReadFromUrl.aspx" method="post" runat="server">
<font>Input file: </font>
<a href="server/xml/books.xml">books.xml</a>
<center>
<asp:button type=submit text="Run"
OnClick="SubmitBtn_Click" runat="server"/></br>
</form>
</center>
<p>
<table align="center">
<tr><th><span>Output from loading file...</span></th></tr>
<tr><th><span></span></th></tr>
<tr><td><h4><xmp id="output" runat="server"/></h4></td></tr>
</table>
</body>
</html>
<script language="VB" runat="server">
Private Sub SubmitBtn_Click(sender As Object, e As EventArgs)
Dim writer as StringWriter
writer = new StringWriter()
Console.SetOut(writer)
Dim myXmlReadFromUrlSample as XmlReadFromUrlSample
myXmlReadFromUrlSample = new XmlReadFromUrlSample()
myXmlReadFromUrlSample.Run()
output.InnerHtml = writer.ToString()
End Sub
</script>