Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
XmlSerializer + Google Base Namespace
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
bmomal...@gmail.com  
View profile  
 More options May 23 2008, 1:04 pm
Newsgroups: microsoft.public.dotnet.xml
From: bmomal...@gmail.com
Date: Fri, 23 May 2008 10:04:10 -0700 (PDT)
Local: Fri, May 23 2008 1:04 pm
Subject: XmlSerializer + Google Base Namespace
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Martin Honnen  
View profile  
 More options May 23 2008, 1:27 pm
Newsgroups: microsoft.public.dotnet.xml
From: Martin Honnen <mahotr...@yahoo.de>
Date: Fri, 23 May 2008 19:27:06 +0200
Local: Fri, May 23 2008 1:27 pm
Subject: Re: XmlSerializer + Google Base Namespace

bmomal...@gmail.com wrote:
> 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:"?

Can you post a minimal but complete sample of the XML you want to create
so that we can see which elements you want in the Google namespace?

Generally if you want to ensure certain elements are in a certain
namespace then you do that by defining the Namespace =
"http://base.google.com/ns/1.0" in the XmlElementAttribute attribute e.g.

     <XmlElement(Namespace:="http://base.google.com/ns/1.0")> _
     Public price As Double

then make sure the root rss is in no namespace with e.g.

<XmlRoot(ElementName:="rss", Namespace:="")> _
Public Class rss

then I get (using the your remaining code unchanged)

<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
   <channel>
     <title>one</title>
     <link>three</link>
     <description>two</description>
     <language>en-us</language>
     <item>
       <id>1234</id>
       <g:price>0</g:price>
     </item>
   </channel>
</rss>

--

        Martin Honnen --- MVP XML
        http://JavaScript.FAQTs.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bmomal...@gmail.com  
View profile  
 More options May 23 2008, 1:50 pm
Newsgroups: microsoft.public.dotnet.xml
From: bmomal...@gmail.com
Date: Fri, 23 May 2008 10:50:43 -0700 (PDT)
Local: Fri, May 23 2008 1:50 pm
Subject: Re: XmlSerializer + Google Base Namespace
On May 23, 1:27 pm, Martin Honnen <mahotr...@yahoo.de> wrote:

> Generally if you want to ensure certain elements are in a certain
> namespace then you do that by defining the Namespace =
> "http://base.google.com/ns/1.0" in the XmlElementAttribute attribute e.g.

>      <XmlElement(Namespace:="http://base.google.com/ns/1.0")> _
>      Public price As Double

> then make sure the root rss is in no namespace with e.g.

> <XmlRoot(ElementName:="rss", Namespace:="")> _
> Public Class rss

Yes!  This is exactly what I was looking for.  Thank you, thank you,
thank you!

I knew it would be something simple like this.

Ironically, I had tried something similar to this a few hours ago, but
I ended up with:

<price xmlns:="http://base.google.com/ns/1.0">0</price>

instead of

<g:price>0</g:price>

I had to play around with the code a bit, and I believe it was because
I had:

xmlns.Add(String.Empty, String.Empty)

instead of

xmlns.Add("g", "http://base.google.com/ns/1.0")

In any event, thank again!

   - Bryan


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google