473,326 Members | 2,061 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,326 software developers and data experts.

XmlAttribute question

I have the following situation

class A
{
public class B
{
int serlize;
public int Serlize
{
get {...} set {...}
}
}

private B somthing;

[XmlAttribute("B")]
public B Somthing { get{...} set{...} }
}

I serlizie and it bombs. What I would like ideally is:

<A B="0" />

In my case B is a highly complex class but it can serialize to a very
simple construct such as an integer as above. I would like to avoid
having to write a property just so I can serialize in this manner. I am
trying to develop these classes as an API within a DLL, and I would
like the interface to have as few redundancies as possible to ensure
that it is not overly complex.

Jul 7 '06 #1
1 1809
Hi Chris,

I'm shocked that the XmlSerializer doesn't support serializing an object as
an attribute value. I just tried it myself with a TypeConverter, implicit
and explicit operator overloads and ToString but nothing worked.

The runtime-error as well as the documentation for XmlAttributeAttribute
states that, ~ "XmlAttributeAtttribute and XmlTextAttribute cannot be used
to serialize complex types". Apparently that means TypeConverter, operator
overloads and the value of ToString() are all ignored by XmlSerializer. I
consider this a design flaw in the XmlSerializer class. At least one of the
aforementioned methods of Type conversion, preferably the TypeConverter,
should be used by the XmlSerializer.

- Dave

<ch***************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>I have the following situation

class A
{
public class B
{
int serlize;
public int Serlize
{
get {...} set {...}
}
}

private B somthing;

[XmlAttribute("B")]
public B Somthing { get{...} set{...} }
}

I serlizie and it bombs. What I would like ideally is:

<A B="0" />

In my case B is a highly complex class but it can serialize to a very
simple construct such as an integer as above. I would like to avoid
having to write a property just so I can serialize in this manner. I am
trying to develop these classes as an API within a DLL, and I would
like the interface to have as few redundancies as possible to ensure
that it is not overly complex.

Jul 8 '06 #2

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

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
3
by: Anita C | last post by:
I have the foll. code to update the value of an attribute: xmlDocument.Load("abc.xml"); XmlAttribute xmlAttrib = xmlDocument.SelectSingleNode(root/web/theme/@desc); xmlAttrib.Value =...
1
by: raffelm | last post by:
I have a class with a property is set to export as an XmlAttribute. I want the attribute to only be written if there is a value. Is that possible? Right now, the attribute is written no matter...
1
by: dpakpaul | last post by:
Hi, I have an XSD schema where I have attributes that are declared to contain non string values such as integers etc. Take for example, this declaration - <xs:attribute name="IsThisTrue"...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
5
by: Dirk Reske | last post by:
Hello, I've created a collection. public class MyCollection:CollectionBase { public int Version; }
1
by: Marc Gravell | last post by:
Apologies if this is a known issue... I don't know if this is an intentional feature change, or simply a bug... but! I recently upgraded a web service to WSE3, specifically to use MTOM in a...
3
by: Roy | last post by:
I have an XmlDocument loaded from an xml file. I have also an xsd schema file associated with it so that it will be in the XmlSchemaSet. How do I get the data type for the value of an XmlElement...
5
by: MaxMax | last post by:
If I have an XmlNode/XmlAttribute and I want to convert its value to a "native" c# type (for example boolean), how should I do? I can't (for example) simply use Boolean.TryParse, because Xml...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.