Hi Folks,
I need help, because I am just at a loss. I'm not super comfortable
with XML, but I'm trying to fight my way through generating an RSS XML
file for Google Base, and I'm stuck with a Namespace issue.
How can I get XmlSerializer to generate the standard RSS tags with no
prefix, but ensure that the Google specific tags a prefixed with "g:"?
Here's a sample of the code I'm using, and it puts g: in front of ALL
the tags (rss, title, everything):
RSS.vb
Imports System.Xml.Serialization
' Taken from http://www.philweber.com/articles/easy_rss_in_vbnet.htm
Public Class rss
<XmlElementAttribute("channel")_
Public channel As New rssChannel()
<XmlAttributeAttribute("version")_
Public version As String = "2.0"
End Class
Public Class rssChannel
Public title As String
Public link As String
Public description As String
Public language As String = "en-us"
<XmlElementAttribute("item")_
Public item As New rssChannelItems()
End Class
Public Class rssChannelItems
Inherits CollectionBase
Public Sub Add(ByVal Item As rssChannelItem)
Dim I As Integer = List.Add(Item)
End Sub
Default Public ReadOnly Property Item(ByVal Index As Integer) As
rssChannelItem
Get
Return CType(List.Item(Index), rssChannelItem)
End Get
End Property
End Class
Public Class rssChannelItem
' Required
Public id As String
Public title As String
Public description As String
Public link As String
Public price As Double
' Recommended
Public provider_class As String
End Class
Export.vb
Sub GenerateGoogleBase()
Dim rssFeed As rss = Nothing
Dim rssItem As rssChannelItem
Try
rssFeed = New rss
With rssFeed.channel
.title = "one"
.description = "two"
.link = "three"
End With
rssItem = new rssChannelItem
rssItem.id = "1234"
rssFeed.channel.item.Add(rssItem)
Dim xml As New XmlSerializer(GetType(rss), "http://
base.google.com/ns/1.0")
Dim strFile As New FileStream("C:\Test.xml", FileMode.Create)
Dim xmlns As New XmlSerializerNamespaces()
xmlns.Add("g", "http://base.google.com/ns/1.0")
xml.Serialize(strFile, rssFeed, xmlns)
Catch ex As Exception
End Try
End Sub
What am I missing? I'm sure it's something simple, but I have
tinkered for hours now and I can't figure it out.
THANK YOU in advance for any light you can shed on this...
- Bryan