c# generating of xml feed according xsd

I need help with generating xml file for googleshop. I have some simple example xml feed for googleshop

  <?xml version="1.0" encoding="utf-8"?>
  <rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
    <channel>
      <title>title</title>
      <item>
        <g:id>tddy123uk</g:id>
      </item>   
    </channel> 
  </rss>

from this I have created xsd schema and c# class (xsd od xsd2code) and then I am filling the c# class by data and create xml feed.

The main problem is, output xml does not have prefix (like g:id) and namespace for google - xsd is manually edited and then generated c# class (xsd or xsd2code)

<?xml version="1.0"?>
  <rss>
    <channel>
      <item>
        <id>4</id>
      </item>
    </channel>
  </rss>

or it has it, but the namespace is in every element and it is surrounded by 'NewDataSet' element - it is from class generated automatically (xsd or xsd2code)

<?xml version="1.0"?>
<NewDataSet>
  <rss version="2.0">
    <channel>
      <item>
        <g:id xmlns:g="http://base.google.com/ns/1.0">4</g:id>
      </item>
    </channel>
  </rss>
</NewDataSet>

Can anybody help me, how to get xml structure like used xml sample? Thanks.


Try this:

[XmlElement("id", Namespace = "http://base.google.com/ns/1.0")] 

Let me know if it works for you.

链接地址: http://www.djcxy.com/p/34318.html

上一篇: 从XSD生成C#类(xhtml.blkstruct.class)

下一篇: c#根据xsd生成xml提要