RE: XML in VB.Net

rmurillo

New member
Joined
Feb 26, 2003
Messages
3
Im new to VB.Net and am having some trouble with converting programs from ASP

<%@ Language=VBScript %>
<%@ Import Namespace="System.Net"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Xml"%>
<Script runat="server">
Function GetWebPageAsStringShort2(strURI)
With WebRequest.Create(New URI(strURI)).GetResponse()
With New StreamReader(.GetResponseStream())
GetWebPageAsStringShort2 = .ReadToEnd()
End With
End With
End Function

Dim sXML as String = GetWebPageAsStringShort2("http://slashdot.org/slashdot.xml")
Dim doc As XmlDocument = New XmlDocument()




</Script>

That is as far as I have gotten. The trouble seems to be that I cannot seem to figure out how to remotely get XML data so i can transform it server-side with an XSL document. Any help would be appreciated.
 
You will need the XslTransform class to transform XML files with XSLT.
It is found in the System.Xml.Xsl namespace. The Transform()
method is overloaded several ways. Read all about it (with
examples) in the documentation:

[mshelp]ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemxmlxslxsltransformclasstopic.htm[/mshelp]

If you go to "XslTransform Members," and then click on the
Transform method, all the overloaded versions will be listed.
 
<%@ Language=VBScript %>
<%@ Import Namespace="System.Net"%>
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.Collection"%>
<%@ Import Namespace="System.Text"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Xml"%>
<%@ Import Namespace="System.Xml.Xsl"%>
<%@ Import Namespace="System.Xml.XPath"%>


<Script runat="server">
Function GetWebPageAsStringShort2(strURI)
With WebRequest.Create(New URI(strURI)).GetResponse()
With New StreamReader(.GetResponseStream())
GetWebPageAsStringShort2 = .ReadToEnd()
End With
End With
End Function

Dim sXML as String = GetWebPageAsStringShort2("http://slashdot.org/slashdot.xml")
Dim sXSLT As New XslTransform()
sXSLT.Load(CType(Server.MapPath("slashdot.xsl"), String))
# Error is on the above line.
Dim mydata As New XPathDocument(sXML)
Dim writer As New XmlTextWriter(Console.Out)
sXSLT.Transform(mydata, Nothing, writer)




</Script>

That is what I got thus far (btw, thank you for the article. I have some book coming from wrox press on this stuff, but I need to know this rather quickly for a job so im trying to get a head start.) but it gives me an error:

Compiler Error Message: BC30188: Declaration expected.

at the above referenced line of code.
 
The top line of your ASPX page should state that the code youre
using is VB, not VBScript. This may fix the problem.

Code:
<%@ Page Language="vb" %>

If that does not fix anything, Im afraid I dont know what
could be wrong. Everything looks declared to me. :-\
 
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30188: Declaration expected.

Source Error:



Line 21: Dim sXML as String = GetWebPageAsStringShort2("http://slashdot.org/slashdot.xml")
Line 22: Dim sXSLT As New XslTransform()
Line 23: sXSLT.Load(CType(Server.MapPath("slashdot.xsl"), String))
Line 24: Dim mydata As New XPathDocument(sXML)
Line 25: Dim writer As New XmlTextWriter(Console.Out)


Source File: D:\development\test\ASPPage1.aspx Line: 23

Code:

<%@ Language="VB" Debug="True" %>
<%@ Import Namespace="System.Net"%>
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.Collection"%>
<%@ Import Namespace="System.Text"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Xml"%>
<%@ Import Namespace="System.Xml.Xsl"%>
<%@ Import Namespace="System.Xml.XPath"%>


<Script runat="server">
Function GetWebPageAsStringShort2(strURI)
With WebRequest.Create(New URI(strURI)).GetResponse()
With New StreamReader(.GetResponseStream())
GetWebPageAsStringShort2 = .ReadToEnd()
End With
End With
End Function

Dim sXML as String = GetWebPageAsStringShort2("http://slashdot.org/slashdot.xml")
Dim sXSLT As New XslTransform()
sXSLT.Load(CType(Server.MapPath("slashdot.xsl"), String))
Dim mydata As New XPathDocument(sXML)
Dim writer As New XmlTextWriter(Console.Out)
sXSLT.Transform(mydata, Nothing, writer)




</Script>
 

Similar threads

Z
Replies
0
Views
171
Zarticho
Z
B
Replies
0
Views
108
Born2Achieve
B
N
Replies
0
Views
109
.Net C Sharp Junior
N
Back
Top