all groups > dotnet xml > july 2004 >
You're in the

dotnet xml

group:

XmlAttribute question (0727)



XmlAttribute question (0727) matt.raffel NO[at]SPAM mindspring.com
7/27/2004 8:28:24 AM
dotnet xml: 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
Re: XmlAttribute question (0727) Dino Chiesa [Microsoft]
7/27/2004 6:41:03 PM
Here is an example I posted on Friday that illustrates this.
http://www.winisp.net/cheeso/srcview.aspx?dir=xml-serialization&file=DateOptional.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-us/cpref/html/frlrfSystemXmlSerializationXmlSerializerClassTopic.asp

and look for the discussion on propertyNameSpecified .


-Dino



[quoted text, click to view]

AddThis Social Bookmark Button