I serialize simply Person which has Items as collection using .NET XmlSerializer;
class Item
{
Name
Price
}
class Person
{
Name
List Items<Item>
}
Everthing fine…I use XmlWriterSettings to indent my xml file. The output is:
<?xml version="1.0" encoding="utf-8"?>
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<name>TestName</name>
<Items>
<Item>
<name>one</name>
<price>0</price>
</Item>
<Item>
<name>two</name>
<price>1</price>
</Item>
</Items>
</Viewport>
But what I want is :
<?xml version="1.0" encoding="utf-8"?>
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<name>TestName</name>
<Items>
<Item name="one" price="0" />
<Item name="two" price="1" />
</Items>
</Viewport>
Shortly instead of
<Item>
<name>one</name>
<price>0</price>
</Item>
I want to write xml as
<Item name="one" price="0" />
How can i do it in .NET(C#) ?
Decorate your
Name&Priceproperties withXmlAttribute