Ralf Klatt
asked on
VB.NET -> XML/XSL Transformation Outcome should be structured RSS 2.0 format ...!
Hi,
I have this code which is working fine:
Imports System
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.ICon tainer
Friend WithEvents TextBox1 As System.Windows.Forms.TextB ox
Friend WithEvents Button1 As System.Windows.Forms.Butto n
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextB ox
Me.Button1 = New System.Windows.Forms.Butto n
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 8)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(712, 504)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(320, 528)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(104, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(752, 557)
Me.Controls.Add(Me.Button1 )
Me.Controls.Add(Me.TextBox 1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Public Shared Function Transform(ByVal input As IXPathNavigable, ByVal stylesheetURL As String) As IXPathNavigable
Dim xsltProcessor As New XslTransform
xsltProcessor.Load(stylesh eetURL)
Dim output As IXPathNavigable = Nothing
If TypeOf input Is XmlDocument Then
Dim outputXML As New XmlDocument
outputXML.Load(xsltProcess or.Transfo rm(input, CType(Nothing, XsltArgumentList), CType(Nothing, XmlResolver)))
output = outputXML
Else
If TypeOf input Is XPathDocument Then
output = New XPathDocument(xsltProcesso r.Transfor m(input, CType(Nothing, XsltArgumentList), CType(Nothing, XmlResolver)))
End If
End If
Return output
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xslURL As String = Application.StartupPath + "\test.xsl"
Dim xmlURL As String = Application.StartupPath + "\test.xml"
Dim xmlDocument As New XmlDocument
xmlDocument.Load(xmlURL)
Dim resultDocument As XmlDocument = CType(Transform(xmlDocumen t, xslURL), XmlDocument)
TextBox1.Text = resultDocument.OuterXml
End Sub
End Class
The only problem I have is that the outcome should be in RSS 2.0 format -> infact the outcome is RSS 2.0 ... it's just not well structured (it's one line instead of being a line for each tag!) ... and when I try to validate it using http://www.feedvalidator.org/ I'm receiving a lot of errors!
The only workarround that I can think of is to parse the content using my own functions ... but I guess that there should be a way to use .NET integrated functionality ... shouldn't it?
Best regards,
Raisor
I have this code which is working fine:
Imports System
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.ICon
Friend WithEvents TextBox1 As System.Windows.Forms.TextB
Friend WithEvents Button1 As System.Windows.Forms.Butto
<System.Diagnostics.Debugg
Me.TextBox1 = New System.Windows.Forms.TextB
Me.Button1 = New System.Windows.Forms.Butto
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 8)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(712, 504)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(320, 528)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(104, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(752, 557)
Me.Controls.Add(Me.Button1
Me.Controls.Add(Me.TextBox
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Public Shared Function Transform(ByVal input As IXPathNavigable, ByVal stylesheetURL As String) As IXPathNavigable
Dim xsltProcessor As New XslTransform
xsltProcessor.Load(stylesh
Dim output As IXPathNavigable = Nothing
If TypeOf input Is XmlDocument Then
Dim outputXML As New XmlDocument
outputXML.Load(xsltProcess
output = outputXML
Else
If TypeOf input Is XPathDocument Then
output = New XPathDocument(xsltProcesso
End If
End If
Return output
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xslURL As String = Application.StartupPath + "\test.xsl"
Dim xmlURL As String = Application.StartupPath + "\test.xml"
Dim xmlDocument As New XmlDocument
xmlDocument.Load(xmlURL)
Dim resultDocument As XmlDocument = CType(Transform(xmlDocumen
TextBox1.Text = resultDocument.OuterXml
End Sub
End Class
The only problem I have is that the outcome should be in RSS 2.0 format -> infact the outcome is RSS 2.0 ... it's just not well structured (it's one line instead of being a line for each tag!) ... and when I try to validate it using http://www.feedvalidator.org/ I'm receiving a lot of errors!
The only workarround that I can think of is to parse the content using my own functions ... but I guess that there should be a way to use .NET integrated functionality ... shouldn't it?
Best regards,
Raisor
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
thanks
ASKER
Thanks for your suggestion armoghan!
I've tested it but the outcome is still a "one-line-string" ...
... this is the workarround I've created:
Imports System
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.ICon
Friend WithEvents TextBox1 As System.Windows.Forms.TextB
Friend WithEvents Button1 As System.Windows.Forms.Butto
Friend WithEvents Button2 As System.Windows.Forms.Butto
<System.Diagnostics.Debugg
Me.TextBox1 = New System.Windows.Forms.TextB
Me.Button1 = New System.Windows.Forms.Butto
Me.Button2 = New System.Windows.Forms.Butto
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 8)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(712, 504)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(320, 528)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(104, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Create RSS"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(432, 528)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(104, 24)
Me.Button2.TabIndex = 2
Me.Button2.Text = "Resolve Time"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(752, 557)
Me.Controls.Add(Me.Button2
Me.Controls.Add(Me.Button1
Me.Controls.Add(Me.TextBox
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Public Shared Function Transform(ByVal input As IXPathNavigable, ByVal stylesheetURL As String) As IXPathNavigable
Dim xsltProcessor As New XslTransform
xsltProcessor.Load(stylesh
Dim output As IXPathNavigable = Nothing
If TypeOf input Is XmlDocument Then
Dim outputXML As New XmlDocument
outputXML.Load(xsltProcess
output = outputXML
Else
If TypeOf input Is XPathDocument Then
output = New XPathDocument(xsltProcesso
End If
End If
Return output
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myRawString As String = ""
Dim mySplitter
Dim xslURL As String = Application.StartupPath + "\test.xsl"
Dim xmlURL As String = Application.StartupPath + "\test.xml"
Dim xmlDocument As New XmlDocument
xmlDocument.Load(xmlURL)
Dim resultDocument As XmlDocument = CType(Transform(xmlDocumen
myRawString = resultDocument.OuterXml
mySplitter = Split(myRawString, "><")
Dim i As Int32
myRawString = ""
For i = 0 To 1000
Try
If i = 0 Then
myRawString = myRawString + mySplitter(i) + ">" + vbCrLf
Else
myRawString = myRawString + "<" + mySplitter(i) + ">" + vbCrLf
End If
Catch ex As Exception
myRawString = Mid(myRawString, 1, Len(myRawString) - 3)
Exit For
End Try
Next
TextBox1.Text = myRawString
End Sub
End Class
Allthough the lines are not really indented, the created feed validates now at http://www.feedvalidator.org/check.cgi?url=http://www.webmaster-online.org/rss/myrss4.rss2
... as your suggestion handles charset=EUC-JP and <xsl:output method="text" indent="yes"/> is a useful information for another XML project of mine, I'll give you full points!
Thanks a lot for your time!
Best regards,
Raisor