Say I have an xml file like so:
<ArrayOfInternetProxy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<InternetProxy>
<ProxyName />
<ProxyIP>23.19.34.127:8800</ProxyIP>
<Username />
<Password />
</InternetProxy>
</ArrayOfInternetProxy>
There where many more <InternetProxy> in the xml file, but I removed them for clarity.
<InternetProxy> representes an object in my program, while <ArrayOfInternetProxy> represents an array of said object.
How can I change the tags <ArrayOfInternetProxy> and <InternetProxy> to be whatever I like?
I managed to change the attributes by using:
[XmlElement("ProxyName")]
public string ProxyName { get; set; }
But this doesn’t work on the other tags.
Thanks.
My class:
public class InternetProxy //I want to change this in the xml output
{
[XmlElement("ProxyName")]
public string ProxyName { get; set; }
[XmlElement("ProxyIP")]
public string Address { get; set; }
[XmlElement("Username")]
public string UserName { get; set; }
[XmlElement("Password")]
public string Password { get; set; }
}
Edit:
Here is what I tried, why doesn’t this work for me??
[XmlElement("Proxies")]
[XmlArray("Proxies")]
List<InternetProxy> proxies;
You should have something like:
To control how it’s serialized you can apply following attributes:
XmlArrayAttribute: it’ll change the name of the array (your actualArrayOfInternetProxy).XmlArrayItemAttribute: it’ll change the name of the array items (your actualInternetProxy).If you serialize directly your array (so you don’t have such property with the array) you should apply XmlType attribute, like:
See http://msdn.microsoft.com/en-us/library/2baksw0z(v=vs.10).aspx for details.