473,386 Members | 1,610 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,386 software developers and data experts.

xml attributes and serialization

i need to serialize my class into xml that looks like this:

<dog>
<breed type="large">spaniel</breed>
</dog>

but i'm not sure how to get an attribute into a property of my class, i can
use the xmlattribute tag to make an attribute of my dog class but i want an
attribute on my property, is this possible? if so how do i do it?

many thanks

Giles Morris
Nov 23 '05 #1
1 813
Hi,

you should be able to do this. I've just tested this class and it
produces the output you where giving as an example. (with an
additional namespace)

[XmlRootAttribute(Namespace="http://www.marv-in.net/Examples/XMLandSuch",
sNullable=false)]
public class Dog
{
/// <remarks/>
public DogBreed breed;
}
/// <remarks/>
public class DogBreed
{
/// <remarks/>
[XmlTextAttribute]
public string Text;
/// <remarks/>
[XmlAttributeAttribute]
public string type;
}

Hope this helps,

Marvin Smit.

On Fri, 5 Aug 2005 06:47:03 -0700, "Giles M" <Giles
M@discussions.microsoft.com> wrote:
i need to serialize my class into xml that looks like this:

<dog>
<breed type="large">spaniel</breed>
</dog>

but i'm not sure how to get an attribute into a property of my class, i can
use the xmlattribute tag to make an attribute of my dog class but i want an
attribute on my property, is this possible? if so how do i do it?

many thanks

Giles Morris


Nov 23 '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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.