简体   繁体   English

在Xml标签中编写特殊字符(Google产品Xml Feed)

[英]Writing Special Chars in Xml Tag ( Google Product Xml Feed )

I'm working on google product feed xml with C# 我正在使用C#开发Google产品Feed xml

I can generate a xml with using XmlSerializer but I can't solve just one problem; 我可以使用XmlSerializer生成xml,但是我不能解决一个问题。

In xml feed example, product id has to be like this; 在xml feed示例中,产品ID必须是这样;

    ...
    <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. 但是您可以在xml元素标记中看到特殊的“:” char。

So when I write "[XmlElement("g:id")]" on my property like; 因此,当我在属性上写“ [XmlElement(“ g:id”)]]“时;

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

XmlSerializer generetad my xml tag like; XmlSerializer Generetad我的xml标签一样; < g_X003A_id > And generated xml looking like this; <g_X003A_id>生成的xml看起来像这样;

...
<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 ? 我怎么解决这个问题 ?

I solved this problem like; 我解决了这个问题

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM