473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Attributes for XML serialization

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>
Nov 29 '05 #1
1 1090
DC
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

"Jeff Connelly" <no****@thank.you> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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>

Dec 1 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Christopher Ambler | last post by:
I have a class that I deserialize into as such: public class row { public string RecordFound; public string IsExpired; }
2
by: Mike LeBlanc | last post by:
Hi, I have a desired xml output that looks like this <?xml version="1.0" encoding="UTF-8"?><onhand_request><item organization_id="414">1</item><item...
1
by: Daniel Lidström | last post by:
Hi, is there a way to control the order XmlSerializer serializes attributes? With this class, value is serialized before value. Although it shouldn't matter, I would like it the other way...
1
by: Daniel Lidström | last post by:
Hi, I want to know how I can deal with empty attributes, like this example: <Spiral constant=""> </Spiral> My Spiral implementation contains this code: bool constantSpecified;
1
by: Steven Quail | last post by:
Hi to all, I have just started looking at XML.Serialization classes and would like to know how I set an attribute for an XML element. For example, I want my XML doc to look like the following:...
6
by: A.M | last post by:
Hi, I am trying to grasp a better underestanding of C# Attributes . I don't see them as a very usefull capability. Could anyone refer me to resources show me best practices and how can I...
3
by: Paulo Morgado [MVP] | last post by:
Hi all ..NET Framework 1.1 I have created several types that are serailized to XML as strings. Someting like this: public struct MyInt32 : IXmlSerializable { int value;
2
by: Glenn | last post by:
Hi Here's the scenario... I have a web method to which a pass a customer ID. The web method looks up the customer and returns an XmlNode which I deserialise into a type. I then update...
2
by: jamie | last post by:
Perhaps I'm using this wrong. When I use above an attribute I don't want serialized it ignores the attribute. It also ignores some other attributes. Have I done something wrong? Here's...
2
by: Jon Jon | last post by:
1st please forgive me if I posted this to the wrong news group(s), news group guidance would be appreciated. Question: I have the following sample class generated from XSD.exe (Vs 2005). I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.