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
LVL 15
Ralf KlattEmployee in Civil ServiceAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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/

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ralf KlattEmployee in Civil ServiceAuthor 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
armoghanCommented:
thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.