Reputation: 1473
Have an XML with next form:
<categories someAttribute="test">
<category id="1">
<title></title>
</category>
<category id="1">
<title></title>
</category>
</categories>
There is no way to change XML structure. But what I want is to replace buggy hand coded XML generation with XMLSerialization.
Please help with those Category list. Is there a way to instruct XML serializer to not wrap list of categories
Code for Example:
public class Category
{
public int Id{get;set;}
}
public class Categories
{
public List<Category> CategoriesList { get; set; }
}
Upvotes: 1
Views: 139
Reputation: 1063338
Like so:
public class Category
{
[XmlAttribute("id")]
public int Id { get; set; }
[XmlElement("title")]
public string Title { get; set; }
}
[XmlRoot("categories")]
public class Categories
{
[XmlAttribute("someAttribute")]
public string SomeValue { get; set; }
[XmlElement("category")]
public List<Category> CategoriesList { get; set; }
}
Upvotes: 3
Reputation: 38515
with the IXmlSerializable interface you can define on your own how to write the xml or you could make your list to an array i think it would be written the way you want but im not sure..
Upvotes: -1