How can I specify the element name when the object will be serialized

I have the following class

    [XmlRoot(ElementName= "webSites")] //No capital w at the beginning
public class WebSites : List<WebSite>
{

}

public class WebSite
{
    [XmlAttribute("name")]
    public string Name { set; get; }
    [XmlAttribute("url")]
    public String Url { set; get; }
}

      

this is serialized for

 <?xml version="1.0" encoding="DOS-862"?>
<webSites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http:
//www.w3.org/2001/XMLSchema">
  <WebSite name="nice website" url="mydomain.com" />

      

it's almost okay, but I want WebSite

(with capital) to be WebSite

(without capital) I know I can only specify this for the root, but how can I use the inner term?

+1


source to share


1 answer


[XmlType("webSite")]
public class WebSite {...}

      

or to manage a collection property in a wrapper class:



[XmlArrayItem("webSite")]
[XmlArray("sites")]
public WebSites Sites { get; set; }

      

+3


source







All Articles