Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

RE: XML in VB.Net

 

I'm 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.

  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

<%@ 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 i'm 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.

  • *Experts*
Posted

The top line of your ASPX page should state that the code you're

using is VB, not VBScript. This may fix the problem.

 

<%@ Page Language="vb" %>

 

If that does not fix anything, I'm afraid I don't know what

could be wrong. Everything looks declared to me. :-\

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...