using System.Xml.Serialization;
public class Alert {
[XmlAttribute("Type")] // a named attribute
public string Type;
[XmlTextAttribute()] // the text attribute
public bool Status;
static void Main(string[] args) {
Alert a1 = new Alert();
a1.Type= "pager";
a1.Status= true;
XmlSerializer s = new XmlSerializer(typeof(Alert));
// use this to "suppress" the default xsd and xsd-instance namespaces
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add( "", "" );
// Serialize to stdout
s.Serialize(System.Console.Out,a1, ns);
}
}
-Dino
Microsoft
ps:
no need to cross post.
actually there is a more appropriate newsgroup:
microsoft.public.dotnet.xml
"Amy L." <am**@paxemail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I am trying to serialize a class to xml and I havent been able to figure
out how to add attributes. I am trying to get a node to look like this
<alert type="pager" >True</alert>
I have this so far which produces this
<alert>True</alert>
[XmlElement("alert")]
public string Alert
{
get { return this.alert ; }
set { this.alert = value ; }
}
How would I embed an XML Attribute into that?
Thanks
Amy.