views:

76

answers:

3

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; } 
}
A: 

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..

Petoj
A: 

Look at XmlAnyElementAttribute.

XOR
+3  A: 

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; }
}
Marc Gravell
Yes it does what I want... but O_o I'm tried and it didn't work for me previously
AlfeG