Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

How to serialize a class with an array without generating a root node

$
0
0
 I created classes and want to generate the following xml.
class books
{public VersionInfo version;
 [XmlAttribute("book")]public bookinfo[] book
}class VersionInfo
{publicstring name;
}

 [XmlRootAttribute("book", IsNullable = false)]class bookinfo
{publicstring name;
}
 
 This is what I want to get
 
<books><version><number>1.00<number></version><book><name>file1</name></book><book><name>file2</name></book></books>
but in fact, I can only get xml like the following
<books><version><number>1.00<number></version><book><bookinfo><name>file1</name></bookinfo><bookinfo><name>file2</name></bookinfo></book></books>
1. I just want <book> information is placed directly under node <books>, how to do it?
2. even if I set the Xml attribut, the <bookinfo> still can't be changed to <book>, what's wrong?

Thanks a lot.


Viewing all articles
Browse latest Browse all 935

Trending Articles