473,498 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlAttribute question (0727)

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 what.

eg:
[XmlRoot("Server")]
class Server
{
[XmlAttribute("shareName")]
public string ShareName
{
get {return shareName;}
set {shareName = value; shareNameChanged = true;}
}

}
Thanks
Matt
Nov 12 '05 #1
1 1165
Here is an example I posted on Friday that illustrates this.
http://www.winisp.net/cheeso/srcview...ateOptional.cs

For more background on this, search for the thread entitled "XmlSerializer
for optional xs:date", starting 21 July 2004.

For the doc on this, see
http://msdn.microsoft.com/library/en...ClassTopic.asp

and look for the discussion on propertyNameSpecified .
-Dino

"raffelm" <ma*********@mindspring.com> wrote in message
news:ba**************************@posting.google.c om...
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 what.

eg:
[XmlRoot("Server")]
class Server
{
[XmlAttribute("shareName")]
public string ShareName
{
get {return shareName;}
set {shareName = value; shareNameChanged = true;}
}

}
Thanks
Matt

Nov 12 '05 #2

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

Similar topics

3
14901
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 =...
2
10373
by: David Elliott | last post by:
I am creating a configuration class to read / write a standard configuration file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ConnectionString"...
1
4117
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"...
5
1780
by: Dirk Reske | last post by:
Hello, I've created a collection. public class MyCollection:CollectionBase { public int Version; }
1
1939
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...
1
1811
by: chris.dannemiller | last post by:
I have the following situation class A { public class B { int serlize; public int Serlize { get {...} set {...}
4
1266
by: Ruth | last post by:
Which edition of Visual Studio do I have? "About" says that I have Visual Studio 8.0.5.0727.42: is this the professional, express, or enterprise edition? I do not beleive it is the Team edition....
3
5084
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
4720
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
6993
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
7197
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...
1
6881
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
5456
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
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.