• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

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.IContainer

    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Button1 = New System.Windows.Forms.Button
        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.TextBox1)
        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(stylesheetURL)
        Dim output As IXPathNavigable = Nothing
        If TypeOf input Is XmlDocument Then
            Dim outputXML As New XmlDocument
            outputXML.Load(xsltProcessor.Transform(input, CType(Nothing, XsltArgumentList), CType(Nothing, XmlResolver)))
            output = outputXML
        Else
            If TypeOf input Is XPathDocument Then
                output = New XPathDocument(xsltProcessor.Transform(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(xmlDocument, 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
0
Ralf Klatt
Asked:
Ralf Klatt
  • 2
1 Solution
 
armoghanCommented:
It shoudl be indented with the following tag in XSL

<xsl:output method="text" indent="yes"/>
http://www.developerfusion.co.uk/show/89/14/
0
 
Ralf KlattPrincipal ConsultantAuthor Commented:
Hi,

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.IContainer

    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        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.TextBox1)
        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(stylesheetURL)
        Dim output As IXPathNavigable = Nothing
        If TypeOf input Is XmlDocument Then
            Dim outputXML As New XmlDocument
            outputXML.Load(xsltProcessor.Transform(input, CType(Nothing, XsltArgumentList), CType(Nothing, XmlResolver)))
            output = outputXML
        Else
            If TypeOf input Is XPathDocument Then
                output = New XPathDocument(xsltProcessor.Transform(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 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(xmlDocument, xslURL), XmlDocument)
        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
0
 
armoghanCommented:
thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now