473,804 Members | 3,462 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Seri alization

' Taken from http://www.philweber.com/articles/easy_rss_in_vbnet.htm
Public Class rss
<XmlElementAttr ibute("channel" )_
Public channel As New rssChannel()
<XmlAttributeAt tribute("versio n")_
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"
<XmlElementAttr ibute("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 GenerateGoogleB ase()
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(rssIt em)

Dim xml As New XmlSerializer(G etType(rss), "http://
base.google.com/ns/1.0")
Dim strFile As New FileStream("C:\ Test.xml", FileMode.Create )

Dim xmlns As New XmlSerializerNa mespaces()
xmlns.Add("g", "http://base.google.com/ns/1.0")

xml.Serialize(s trFile, 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
Jun 27 '08 #1
2 2339
bm*******@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 XmlElementAttri bute attribute e.g.

<XmlElement(Nam espace:="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(Elemen tName:="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>tw o</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/
Jun 27 '08 #2
On May 23, 1:27 pm, Martin Honnen <mahotr...@yaho o.dewrote:
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 XmlElementAttri bute attribute e.g.

<XmlElement(Nam espace:="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(Elemen tName:="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(Strin g.Empty, String.Empty)

instead of

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

In any event, thank again!

- Bryan
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4323
by: Bluetears76 | last post by:
Hi I have a hirachy of classes which are Message(base), then FileMessage and ChatMessage (extended) I want to serialize the objects and when i am deserizaling i dont know if i am getting FileMessage or ChatMessage. So how to get that object and use it I have written following code for serialization public void Send(Message message) { NetworkStream netWorkStream=null;
16
9554
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ....... </ArrayOfClassname>
2
942
by: magister | last post by:
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different attributes, all share a base set of 4, one of the question types can have children with <option> elements, this is how the xml looks after serialization.... If you notice there is an extra <SelectionList> around the <option>'s in the final...
0
3030
by: keith bannister via .NET 247 | last post by:
(Type your message here) -------------------------------- From: keith bannister Hi, I'm new to .net (as of last week) but here goes. I want to serialize/deserialize a file the conforms to an XML schema (xsd).
5
7288
by: Keith Bannister | last post by:
I'm new to .net so here goes. I'm tying to deserialize a class that is associated with an XML schema. I created the C# class with xsd.exe as below: xsd.exe /c /n:somenamespace properties.xsd this creates properties.cs
4
11807
by: Sebastien Tardif | last post by:
Subject: XmlSerializer.Deserialize complain when root declare the namespace If I do XmlSerializer.Deserialize( myString ) and myString is: String myString = "<?xml version=\"1.0\" encoding=\"utf-16\"?><DocumentResponse ><documentSize xmlns=\"urn:webservices.docharbor.com\">23</documentSize></DocumentResponse>"; It's working
3
4519
by: Loui Mercieca | last post by:
Hi, I have created a class, named FormField , which basically contains two fields, name and value. I have set the tag before the class and the field is set as an XmlAttribute whil the name as XmlText. In my main class, i have created an arraylist which contains a collection of this class FormField. Basically its: public void Add( string sName, string sValue )
1
5124
by: Yewen Tang | last post by:
I have a schema file datamodel.xsd, element "properties" is declared as a type of "baseProperty". The schema file also defines "derivedProperty" is a derived type of "baseProperty". <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:myns="uri:myschema" targetNamespace="uri:myschema" elementFormDefault="qualified" version="1.0"> <xs:complexType name="derivedProperty">
0
2805
by: theonlydavewilliams | last post by:
Hi there I'm hoping there's an easy answer to a (hopefully) not too long-winded issue... I'm building a C# web client using a proxy wsdl.exe'd from a wsdl file and six schemas, each in a different namespace. Some schemas extend complex types in others. When i get a soap:Fault from my test server it could contain a serialized exception object (called fault) from one of two of these schemas (and different namespaces, call them xmlns:b0="ns1" and...
0
9588
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.