I'm using System.Xml.Serialization.XmlSerializer
to serialize my class into a XML document.
These are my classes:
public class Test
{
public List<ListItem> ListItems { get; set; }
[XmlAttribute]
public String Name { get; set; }
[XmlAttribute]
public String ID { get; set; }
public Scenario()
{
this.ListItems = new List<ListItem>();
}
}
public class ListItem
{
public String Name { get; set; }
}
and this is the XML that I get:
<?xml version="1.0"?>
<Test xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ListItems>
<ListItem>
<Name>test1</Name>
</ListItem>
<ListItem>
<Name>test2</Name>
</ListItem>
</ListItems>
</Test>
Is it possible to get XML like this:
<?xml version="1.0"?>
<Test xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ListItem>
<Name>test1</Name>
</ListItem>
<ListItem>
<Name>test2</Name>
</ListItem>
</Test>
Notice that in second Xml example (the one that I need to generate) ListItem
nodes do not have parent ListItems
node.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With