I need Xml that looks like this
<foo>
  <bar ... />
  <bar ... />
</foo>
And currently have the following class structure :
[XmlRoot("foo")]
public class Foo
{
  [XmlArrayItem("bar")]
  public List<Bar> myBars;
}
But this gives me Xml w开发者_运维知识库here bar items are wrapped inside a bars element. How should I define my custom XmlAttributes so I'd get the Xml structure I need?
I had to solve something similar yesterday, and this was the solution for me:
[XmlRoot("foo")]
public class Foo
{
    [XmlElement("bar")]
    public List<Bar> myBars;
}
The solution I use is this:
[XmlRoot("foo")]
public class Foo : List<Bar>
{
}
[XmlType("bar")]
public class Bar
{
}
In fact, I defined Foo as a List<T>, so it works as a generic list. The type in that list just needs to define the XmlType attribute.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论