Search code examples
c#xmlxml-serializationgoogle-product-search

Writing Special Chars in Xml Tag ( Google Product Xml Feed )


I'm working on google product feed xml with C#

I can generate a xml with using XmlSerializer but I can't solve just one problem;

In xml feed example, product id has to be like this;

    ...
    <item>
        <title>Super item</title>
        <link>http://www.bla.com/13007/2202170/</link>
        <description>Test description</description>
        <g:id>1234678</g:id>
    </item>
    ...  

But as you can see special " : " char in xml element tag.

So when I write "[XmlElement("g:id")]" on my property like;

    [DataMember]
    [XmlElement("g:id")]
    public int Id { get; set; }

XmlSerializer generetad my xml tag like; < g_X003A_id > And generated xml looking like this;

...
<item>
    <title>Super item</title>
    <link>http://www.bla.com/13007/2202170/</link>
    <description>Test description</description>
    <g_X003A_id>1234678</g_X003A_id>
</item>
...  

How can I solve this problem ?


Solution

  • I solved this problem like;

            [DataMember]
            [XmlElement("id", Namespace = "http://base.google.com/ns/1.0")] //g:id
            public int Id { get; set; }