Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

XML List serialization and control of element names for list items

$
0
0

What is the proper way to attribute your List in order to get the element names correct?

I want to serialize a list of SiteMapElements as follows:

<urlSet xmlns:xsd="http://www.w3.org/2001/XMLSchema"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">  <url Title="Home" ID="8effda05-87f6-6207-ad9b-ff0000c60da7">    <loc>http://www.branxx.com/home</loc>    <lastmod>2014-01-29</lastmod>    <changefreq>monthly</changefreq>    <priority>0.50</priority>  </url>  <url Title="Institutions" ID="0b7adb05-87f6-6207-ad9b-ff0000c60da7">    <loc>http://www.branxx.com/us/institutions</loc>    <lastmod>2014-11-20</lastmod>    <changefreq>monthly</changefreq>    <priority>0.50</priority>  </url>

However, when I do serialize it, my code is improperly naming the url element (as seen below)

urlSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">  <SiteMapElement title="E1" id="00000000-0000-0000-0000-000000000000">    <loc>E1</loc>    <lastmod>2014-12-16</lastmod>    <changefreq>monthly</changefreq>    <priority>0.50</priority>  </SiteMapElement>

My SiteMapElement code has attributed the classes as follows.

   [XmlRoot( ElementName = "url" )]   public class SiteMapElement : IXmlSerializable   { ... properties below

My List of SiteMapElements (SiteMapElementList) looks as follows:

[XmlRoot( Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9", IsNullable = false, ElementName = "urlSet" )]     publicclassSiteMapElementList : List<SiteMapElement>     {     }

I have tried several approaches and none give me what I need.

  


Jerry Noll


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>