Going round in circles here so some help would be appreciated. (C#)
I'm trying to serialize an object, similar to the code below, to XML.
That bit is simple enough and produces XML which looks like:
My question is: Is it possible to change the name of the <string> elements to something else like <value>?? Its creating the name based on the list type (List<string>).
I've tried creating another object called 'Value' which just returns a string and using that as the List type but I just get an extra layer of nesting/grouping which isnt the XML structure I need.
Any alternative ways of doing this? Any suggestions appreciated thanks.
I'm trying to serialize an object, similar to the code below, to XML.
Code:
public class someObject
{
public string key { get; set; }
public List<string> values;
//constructor and stuff
}
Code:
someObject obj1 = new someObject() { key = "test1" };
obj1.add("Value 1");
obj1.add("Value 2");
obj1.add("Value 3");
XmlSerializer x = new XmlSerializer(obj1.GetType());
x.Serialize(Console.Out, obj1);
That bit is simple enough and produces XML which looks like:
Code:
<?xml version="1.0" ?>
<someObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<values>
<string>Value 1</string>
<string>Value 2</string>
<string>Value 3</string>
</values>
<key>test1</key>
</someObject>
My question is: Is it possible to change the name of the <string> elements to something else like <value>?? Its creating the name based on the list type (List<string>).
I've tried creating another object called 'Value' which just returns a string and using that as the List type but I just get an extra layer of nesting/grouping which isnt the XML structure I need.
Any alternative ways of doing this? Any suggestions appreciated thanks.
Last edited: