Groups | Blog | Home
all groups > dotnet xml > november 2005 >

dotnet xml : Attributes for XML serialization


Jeff Connelly
11/29/2005 4:43:51 PM
I'm using the XML attribute (.NET meaning) XMLArray on an array in a class,
to serialize it. What can I do to specify that I want to serialize an XML
attribute (regular XML meaning) for the element that is created?

e.g.
[XmlArray("namedUsers")]
[XmlArrayItem("user",typeof(User))]

public System.Collections.ArrayList userList = new
System.Collections.ArrayList();



This creates an element like

<namedUsers>
<user userName="User1" />
</namedUsers>

Where User has

[XmlAttribute("userName")]

public string userName;




What I want is
<namedUsers mode="individual">
<user userName="User1" />
</namedUsers>

DC
11/30/2005 9:31:44 PM
how about:

[XmlRoot("namedUsers")]
public class Container {
[XmlAttribute("mode")]
public string WantThisToAppearAsAttribute;
[XmlElement("user", typeof(User))]
public User[] u;
}


-D

--
-Dino
D i n o . C h i e s a AT M i c r o s o f t . c o m



[quoted text, click to view]

AddThis Social Bookmark Button