【发布时间】:2011-03-06 06:24:57
【问题描述】:
我有这个代码:
Public Class Transform
Dim inputFile As IO.StringReader ' Object variable
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ofdOpenFile.FileOk
' Configure the Open dialog box and display it.
With ofdOpenFile
.Filter = " Text files (*. txt)|*. txt| All files (*.*)|*.*"
.InitialDirectory = " C:\ Data"
.Title = " Select a File to Open"
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
inputFile = IO.File.OpenText(.FileName)
End If
End With
End Sub
Private Sub Transform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Option Strict On
Imports System.Xml.Xsl
''' <summary>
''' Updated 10.14.2010 - changed class name to Form1
''' This program converts a VB 2008 XML Documentation
''' into an HTML file for displaying in a browser using
''' an XSLT transformation file stored on a remote server
''' </summary>
''' <author>John Couture - jcouture@sdccd.edu</author>
''' <assignment>Week 5</assignment>
''' <version>2.02 - 02/03/2010</version>
''' <seealso>http://media.techtarget.com/digitalguide/images/Misc/professionalVB_ch12.pdf </seealso>
''' <seealso>Using XML in Visual Basic 2005,
''' Excerpted from Wrox Publishing: Professional VB 2005,
''' (c)2005, Bill Evjen et al, ISBN 0-764507536-8
''' </seealso>
'''
Public Class Form1
' Identify where the XSLT file is located
Dim strTransformPath As String = Application.StartupPath & "\transform.xslt"
' Provide a default file name for this program
Dim strOutputPath As String = _
Application.StartupPath & "/output.htm"
''' <summary>
''' When the program first starts, show the user where the output
''' file will be located.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
End Sub
Private Sub Transform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtHTML.Text = strOutputPath
End Sub
''' <summary>
''' Using a file dialog box, get the input file.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub btnXML_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnXML.Click
With ofdOpenFile
.InitialDirectory = "C:\"
.Filter() = "Comment File | *.xml"
.ShowDialog()
txtXML.Text = .FileName
End With
End Sub
''' <summary>
''' Transform the XML code into HTML code
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' Once you know the location of the XML file, the computer
''' will automatically download the XSLT (transformation) file
''' and convert the XML code into HTML code for printing.
''' </remarks>
Private Sub btnTransform_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnTransform.Click
Dim myXSLTransform As XslCompiledTransform = New XslCompiledTransform
Try
'myXSLTransform.Load(txtXSLT.Text)
myXSLTransform.Load(strTransformPath)
myXSLTransform.Transform(txtXML.Text, txtHTML.Text)
btnTransform.Text = "Transformation is Done!"
btnTransform.BackColor = System.Drawing.Color.Green
btnTransform.ForeColor = System.Drawing.Color.White
btnTransform.Font = New Font(btnTransform.Name, 12, FontStyle.Bold)
Catch ex As Exception
If Not IO.File.Exists(strTransformPath) Then
MessageBox.Show("Cannot find XSL file")
End If
If Not IO.File.Exists(txtXML.Text) Then
MessageBox.Show("Cannot find XML file")
End If
MessageBox.Show("Message: " & ex.Message)
End Try
End Sub
End Class
我收到这些错误:
'Private Sub Transform_Load(sender As Object, e As System.EventArgs)' 有多个具有相同签名的定义。第 15 行
'strOutputPath' 未声明。由于其保护级别,它可能无法访问。 51号线
类型“XslCompiledTransform”未定义。 83号线
Public Class Transform
Dim inputFile As IO.StringReader ' Object variable
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ofdOpenFile.FileOk
' Configure the Open dialog box and display it.
With ofdOpenFile
.Filter = " Text files (*. txt)|*. txt| All files (*.*)|*.*"
.InitialDirectory = " C:\ Data"
.Title = " Select a File to Open"
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
inputFile = IO.File.OpenText(.FileName)
End If
End With
End Sub
Private Sub Transform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Option Strict On
Imports System.Xml.Xsl
''' <summary>
''' Updated 10.14.2010 - changed class name to Form1
''' This program converts a VB 2008 XML Documentation
''' into an HTML file for displaying in a browser using
''' an XSLT transformation file stored on a remote server
''' </summary>
''' <author>John Couture - jcouture@sdccd.edu</author>
''' <assignment>Week 5</assignment>
''' <version>2.02 - 02/03/2010</version>
''' <seealso>http://media.techtarget.com/digitalguide/images/Misc/professionalVB_ch12.pdf </seealso>
''' <seealso>Using XML in Visual Basic 2005,
''' Excerpted from Wrox Publishing: Professional VB 2005,
''' (c)2005, Bill Evjen et al, ISBN 0-764507536-8
''' </seealso>
'''
Public Class Form1
' Identify where the XSLT file is located
Dim strTransformPath As String = Application.StartupPath & "\transform.xslt"
' Provide a default file name for this program
Dim strOutputPath As String = _
Application.StartupPath & "/output.htm"
''' <summary>
''' When the program first starts, show the user where the output
''' file will be located.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
End Sub
Private Sub Transform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtHTML.Text = strOutputPath
End Sub
''' <summary>
''' Using a file dialog box, get the input file.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub btnXML_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnXML.Click
With ofdOpenFile
.InitialDirectory = "C:\"
.Filter() = "Comment File | *.xml"
.ShowDialog()
txtXML.Text = .FileName
End With
End Sub
''' <summary>
''' Transform the XML code into HTML code
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' Once you know the location of the XML file, the computer
''' will automatically download the XSLT (transformation) file
''' and convert the XML code into HTML code for printing.
''' </remarks>
Private Sub btnTransform_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnTransform.Click
Dim myXSLTransform As XslCompiledTransform = New XslCompiledTransform
Try
'myXSLTransform.Load(txtXSLT.Text)
myXSLTransform.Load(strTransformPath)
myXSLTransform.Transform(txtXML.Text, txtHTML.Text)
btnTransform.Text = "Transformation is Done!"
btnTransform.BackColor = System.Drawing.Color.Green
btnTransform.ForeColor = System.Drawing.Color.White
btnTransform.Font = New Font(btnTransform.Name, 12, FontStyle.Bold)
Catch ex As Exception
If Not IO.File.Exists(strTransformPath) Then
MessageBox.Show("Cannot find XSL file")
End If
If Not IO.File.Exists(txtXML.Text) Then
MessageBox.Show("Cannot find XML file")
End If
MessageBox.Show("Message: " & ex.Message)
End Try
End Sub
End Class
我收到这些错误:
'Private Sub Transform_Load(sender As Object, e As System.EventArgs)' 有多个具有相同签名的定义。第 15 行
'strOutputPath' 未声明。由于其保护级别,它可能无法访问。 51号线
类型“XslCompiledTransform”未定义。 83号线
【问题讨论】:
标签: .net vb.net visual-studio-2010