System.Xml.Serialization.XmlAttributes Class

Assembly: System.Xml.dll
Namespace: System.Xml.Serialization
Summary
Represents a collection of attribute objects that control how the XmlSerializer serializes and deserializes an object.
C# Syntax:
public class XmlAttributes
Remarks
Creating the XmlAttributes is part of a process that overrides the default way the XmlSerializer serializes class instances. For example, suppose you want to serialize an object that is created from a DLL which has an inaccessible source. By using the XmlAttributeOverrides, you can augment or otherwise control how the object is serialized.

The members of the XmlAttributes class correspond directly to a family of attribute classes that control serialization. For example, the XmlAttributes.XmlText property must be set to an XmlTextAttribute, which allows you to override serialization of a field or property by instructing the XmlSerializer to serialize the property value as XML text. For a complete list of attributes that control serialization, see the XmlSerializer.

For more details on using the XmlAttributeOverrides with the XmlAttributes class, see the conceptual topic at MSDN: overridingserializationofclasseswithxmlattributeoverridesclass.

Example
The following example serializes an instance of a class named Orchestra, which contains a single field named Instruments that returns an array of Instrument objects. A second class named Brass inherits from the Instrument class. The example creates an XmlAttributes object to override the Instrument field--allowing the field to accept Brass objects--and adds the XmlAttributes object to an instance of the XmlAttributeOverrides class.
using System;
using System.IO;
using System.Xml.Serialization;

public class Orchestra
{
   public Instrument[] Instruments;
}   

public class Instrument
{
   public string Name;
}

public class Brass:Instrument
{
   public bool IsValved;
}

public class Run
{
    public static void Main()
    {
       Run test = new Run();
       test.SerializeObject("Override.xml");
       test.DeserializeObject("Override.xml");
    }

    public void SerializeObject(string filename)
    {
      /* Each overridden field, property, or type requires 
      an XmlAttributes object. */
      XmlAttributes attrs = new XmlAttributes();

      /* Create an XmlElementAttribute to override the 
      field that returns Instrument objects. The overridden field
      returns Brass objects instead. */
      XmlElementAttribute attr = new XmlElementAttribute();
      attr.ElementName = "Brass";
      attr.Type = typeof(Brass);

      // Add the element to the collection of elements.
      attrs.XmlElements.Add(attr);

      // Create the XmlAttributeOverrides object.
      XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();

      /* Add the type of the class that contains the overridden 
      member and the XmlAttributes to override it with to the 
      XmlAttributeOverrides object. */
      attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

      // Create the XmlSerializer using the XmlAttributeOverrides.
      XmlSerializer s = 
      new XmlSerializer(typeof(Orchestra), attrOverrides);

      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Create the object that will be serialized.
      Orchestra band = new Orchestra();
      
      // Create an object of the derived type.
      Brass i = new Brass();
      i.Name = "Trumpet";
      i.IsValved = true;
      Instrument[] myInstruments = {i};
      band.Instruments = myInstruments;

      // Serialize the object.
      s.Serialize(writer,band);
      writer.Close();
   }

   public void DeserializeObject(string filename)
   {
      XmlAttributeOverrides attrOverrides = 
         new XmlAttributeOverrides();
      XmlAttributes attrs = new XmlAttributes();

      // Create an XmlElementAttribute to override the Instrument.
      XmlElementAttribute attr = new XmlElementAttribute();
      attr.ElementName = "Brass";
      attr.Type = typeof(Brass);

      // Add the element to the collection of elements.
      attrs.XmlElements.Add(attr);

      attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

      // Create the XmlSerializer using the XmlAttributeOverrides.
      XmlSerializer s = 
      new XmlSerializer(typeof(Orchestra), attrOverrides);

      FileStream fs = new FileStream(filename, FileMode.Open);
      Orchestra band = (Orchestra) s.Deserialize(fs);
      Console.WriteLine("Brass:");

      /* The difference between deserializing the overridden 
      XML document and serializing it is this: To read the derived 
      object values, you must declare an object of the derived type 
      (Brass), and cast the Instrument instance to it. */
      Brass b;
      foreach(Instrument i in band.Instruments) 
      {
         b = (Brass)i;
         Console.WriteLine(
         b.Name + "\n" + 
         b.IsValved);
      }
   }
}


    
See also:
System.Xml.Serialization Namespace | XmlAttributeOverrides | XmlSerializer

System.Xml.Serialization.XmlAttributes Member List:

Public Constructors
ctor #1 Overloaded:
.ctor()

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the XmlAttributes class.
ctor #2 Overloaded:
.ctor(ICustomAttributeProvider provider)

Public Properties
XmlAnyAttribute Read-write

Gets or sets the XmlAnyAttributeAttribute to override.
XmlAnyElements Read-only

Gets the collection of XmlAnyElementAttribute objects to override.
XmlArray Read-write

Gets or sets an object that specifies how the XmlSerializer serializes a public field or read/write property that returns an array.
XmlArrayItems Read-only

Gets or sets a collection of objects that specify how the XmlSerializer serializes items inserted into an array returned by a public field or read/write property.
XmlAttribute Read-write

Gets or sets an object that specifies how the XmlSerializer serializes a public field or public read/write property as an XML attribute.
XmlChoiceIdentifier Read-only

Gets or sets an object that allows you to disambiguate between a set of choices.
XmlDefaultValue Read-write

Gets or sets the default value of an XML element or attribute.
XmlElements Read-only

Gets or sets a collection of objects that specify how the XmlSerializer serializes a public field or read/write property as an XML element.
XmlEnum Read-write

Gets or sets an object that specifies how the XmlSerializer serializes an enumeration member.
XmlIgnore Read-write

Gets or sets a value that specifies whether or not the XmlSerializer serializes a public field or public read/write property.
Xmlns Read-write

XmlRoot Read-write

Gets or sets an object that specifies how the XmlSerializer serializes a class as an XML root element.
XmlText Read-write

Gets or sets an object that instructs the XmlSerializer to serialize a public field or public read/write property as XML text.
XmlType Read-write

Gets or sets an object that specifies how the XmlSerializer serializes a class to which the XmlTypeAttribute has been applied.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Xml.Serialization.XmlAttributes Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the XmlAttributes class.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public XmlAttributes();
Example
The following example serializes an instance of a class named Orchestra, which contains a single field named Instruments that returns an array of Instrument objects. A second class named Brass inherits from the Instrument class. The example creates an XmlAttributes object to override the Instrument field--allowing the field to accept Brass objects--and adds the XmlAttributes object to an instance of the XmlAttributeOverrides class.
using System;
using System.IO;
using System.Xml.Serialization;

public class Orchestra
{
   public Instrument[] Instruments;
}   

public class Instrument
{
   public string Name;
}

public class Brass:Instrument
{
   public bool IsValved;
}

public class Run
{
    public static void Main()
    {
       Run test = new Run();
       test.SerializeObject("Override.xml");
       test.DeserializeObject("Override.xml");
    }

    public void SerializeObject(string filename)
    {
      /* Each overridden field, property, or type requires 
      an XmlAttributes object. */
      XmlAttributes attrs = new XmlAttributes();

      /* Create an XmlElementAttribute to override the 
      field that returns Instrument objects. The overridden field
      returns Brass objects instead. */
      XmlElementAttribute attr = new XmlElementAttribute();
      attr.ElementName = "Brass";
      attr.Type = typeof(Brass);

      // Add the element to the collection of elements.
      attrs.XmlElements.Add(attr);

      // Create the XmlAttributeOverrides object.
      XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();

      /* Add the type of the class that contains the overridden 
      member and the XmlAttributes to override it with to the 
      XmlAttributeOverrides object. */
      attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

      // Create the XmlSerializer using the XmlAttributeOverrides.
      XmlSerializer s = 
      new XmlSerializer(typeof(Orchestra), attrOverrides);

      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Create the object that will be serialized.
      Orchestra band = new Orchestra();
      
      // Create an object of the derived type.
      Brass i = new Brass();
      i.Name = "Trumpet";
      i.IsValved = true;
      Instrument[] myInstruments = {i};
      band.Instruments = myInstruments;

      // Serialize the object.
      s.Serialize(writer,band);
      writer.Close();
   }

   public void DeserializeObject(string filename)
   {
      XmlAttributeOverrides attrOverrides = 
         new XmlAttributeOverrides();
      XmlAttributes attrs = new XmlAttributes();

      // Create an XmlElementAttribute to override the Instrument.
      XmlElementAttribute attr = new XmlElementAttribute();
      attr.ElementName = "Brass";
      attr.Type = typeof(Brass);

      // Add the element to the collection of elements.
      attrs.XmlElements.Add(attr);

      attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

      // Create the XmlSerializer using the XmlAttributeOverrides.
      XmlSerializer s = 
      new XmlSerializer(typeof(Orchestra), attrOverrides);

      FileStream fs = new FileStream(filename, FileMode.Open);
      Orchestra band = (Orchestra) s.Deserialize(fs);
      Console.WriteLine("Brass:");

      /* The difference between deserializing the overridden 
      XML document and serializing it is this: To read the derived 
      object values, you must declare an object of the derived type 
      (Brass), and cast the Instrument instance to it. */
      Brass b;
      foreach(Instrument i in band.Instruments) 
      {
         b = (Brass)i;
         Console.WriteLine(
         b.Name + "\n" + 
         b.IsValved);
      }
   }
}


    

Return to top


Overloaded ctor #2
Summary
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public XmlAttributes(
   ICustomAttributeProvider provider
);
Parameters:

provider

Return to top


Property: XmlAnyAttribute (read-write)
Summary
Gets or sets the XmlAnyAttributeAttribute to override.
C# Syntax:
public XmlAnyAttributeAttribute XmlAnyAttribute {get; set;}
Remarks
The XmlAnyAttributeAttribute can be applied to a member that returns an array of XmlAttribute objects on deserialization. This allows the XmlSerializer to deserialize any attributes that do not have a corresponding member in the object being deserialized--thus those elements are "unknown" to the XmlSerializer. This is useful when the XML stream may have been altered by a Web Service, or when it is known that random data will be always be included with the XML stream.

The XmlAttributes.XmlAnyAttribute property allows you to override the serialization of a member to function as a member to which the XmlAnyAttributeAttribute has been applied.

Return to top


Property: XmlAnyElements (read-only)
Summary
Gets the collection of XmlAnyElementAttribute objects to override.
C# Syntax:
public XmlAnyElementAttributes XmlAnyElements {get;}
Remarks
The XmlAnyElementAttribute can be applied to a member that returns an array of XmlElement objects on deserialization. This allows the XmlSerializer to deserialize any elements that do not have a corresponding member in the object being deserialized--thus those elements are "unknown" to the XmlSerializer. This is useful when the XML stream may have been altered by a Web Service, or when it is known that random data will be always be included with the XML stream.

The XmlAttributes.XmlAnyElements property allows you to override the serialization of a member to function as a member to which the XmlAnyElementAttribute has been applied.

Example
The following example creates a new XmlAnyElementAttribute object and adds it to the collection of objects accessed through the XmlAttributes.XmlAnyElements property. The XmlAttributes object is then added to a XmlAttributeOverrides object which is used to create an XmlSerializer object. The XmlSerializer is used to serialize or deserialize an object. To see the effect of using the XmlAnyElementAttributes property, create an XML document named "UnknownElements.xml" by running the SerializeObject method in the Main method. Edit the resulting document to include other (unknown) elements. Comment out the SerializeObject call in the Main method, and uncomment the call to the DeserializeObject method, which will print out the name and value of any unknown XML element.
using System;
using System.IO;
using System.Xml.Serialization;
using System.Xml;

public class Group{
   public string GroupName;
   [XmlAnyElement]
   public object[]Things;

}

public class Test{
   static void Main(){
      Test t = new Test();
      // 1 Run this and create the XML document.
      // 2 Add new elements to the XML document.
      // 3 Comment out the new line, and uncomment
      // the DeserializeObject line to deserialize the
      // XML document and see unknown elements.
      t.SerializeObject("UnknownElements.xml");
     
      // t.DeserializeObject("UnknownElements.xml");
   }

   private void SerializeObject(string filename){
      XmlSerializer ser = new XmlSerializer(typeof (Group));
      TextWriter writer = new StreamWriter(filename);
      Group g = new Group();
      g.GroupName = "MyGroup";
      ser.Serialize(writer, g);
      writer.Close();
   }

   
   private void DeserializeObject(string filename){

      XmlSerializer ser = CreateOverrideSerializer();
      // A FileStream is needed to read the XML document.
      FileStream fs = new FileStream(filename, FileMode.Open);
     Group g = (Group)
     	ser.Deserialize(fs);
     fs.Close();
     Console.WriteLine(g.GroupName);
     Console.WriteLine(g.Things.Length);
     foreach(XmlElement xelement in g.Things){
     Console.WriteLine(xelement.Name + ": " + xelement.InnerXml);
     }
   }

   private XmlSerializer CreateOverrideSerializer(){
      XmlAnyElementAttribute myAnyElement = 
      new XmlAnyElementAttribute();
      XmlAttributeOverrides xOverride = 
      new XmlAttributeOverrides();
      XmlAttributes xAtts = new XmlAttributes();
      xAtts.XmlAnyElements.Add(myAnyElement);
      xOverride.Add(typeof(Group), "Things", xAtts);
      return new XmlSerializer(typeof(Group) , xOverride);
   }
}

    
See also:
XmlAttributes.XmlAnyAttribute

Return to top


Property: XmlArray (read-write)
Summary
Gets or sets an object that specifies how the XmlSerializer serializes a public field or read/write property that returns an array.
C# Syntax:
public XmlArrayAttribute XmlArray {get; set;}
Remarks
There are two ways in which a public field or public read/write property that returns an array is serialized by the XmlSerializer: (1) the default serialization, and (2) the controlled serialization.

In the default serialization, no attribute is applied to the member. When serialized, the array will be serialized as a nested sequence of XML elements with the XML element name of the nested sequence taken from the member name.

To control the serialization more precisely, apply an XmlArrayAttribute to the field or property. For example, you can change the generated XML element name from the default to a different name by setting the XmlArrayAttribute.ElementName property to a new value.

The XmlAttributes.XmlArray property allows you to override the default serialization, as well as the serialization controlled by applying an XmlArrayAttribute to the member. For example, you can change the XML element name generated from the default (the member identifier) to a new value. In addition, if you apply an XmlArrayAttribute to a member, it will be overridden by any XmlArrayAttribute that is assigned to the XmlAttributes.XmlArray property.

Example
The following example serializes a class that contains a field named Members that returns an array of objects. The XmlArrayAttribute is used to override the serialization of the field, and rename the element name to Staff.
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class Group
{
   // This field will be overridden.
   public Member [] Members;
}

public class Member
{
   public string MemberName;
}

public class Run
{
   public static void Main()
   {
      Run test = new Run();
      test.SerializeObject("OverrideArray.xml");
      test.DeserializeObject("OverrideArray.xml");
   }
   // Return an XmlSerializer used for overriding. 
   public XmlSerializer CreateOverrider()
   {
      // Creating XmlAttributeOverrides and XmlAttributes objects.
      XmlAttributeOverrides xOver = new XmlAttributeOverrides();
      XmlAttributes xAttrs = new XmlAttributes();

      // Add an override for the XmlArray.    
      XmlArrayAttribute xArray = new XmlArrayAttribute("Staff");
      xArray.Namespace = "http://www.cpandl.com";
      xAttrs.XmlArray = xArray;
      xOver.Add(typeof(Group), "Members", xAttrs);

      // Create the XmlSerializer and return it.
      return new XmlSerializer(typeof(Group), xOver);
   }
   
 
   public void SerializeObject(string filename)
   {
      // Create an instance of the XmlSerializer class.
      XmlSerializer mySerializer =  CreateOverrider();
      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Create an instance of the class that will be serialized.
      Group myGroup = new Group();

      // Set the object properties.
      Member m = new Member();
      m.MemberName = "Paul";
      myGroup.Members = new Member[1] {m};
      
      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myGroup);
      writer.Close();
   }

   public void DeserializeObject(string filename)
   {
      XmlSerializer mySerializer = CreateOverrider();
      FileStream fs = new FileStream(filename, FileMode.Open);
      Group myGroup = (Group) 
      mySerializer.Deserialize(fs);
      foreach(Member m in myGroup.Members)
      {
         Console.WriteLine(m.MemberName);
      }
   }
}
   

    

Return to top


Property: XmlArrayItems (read-only)
Summary
Gets or sets a collection of objects that specify how the XmlSerializer serializes items inserted into an array returned by a public field or read/write property.
C# Syntax:
public XmlArrayItemAttributes XmlArrayItems {get;}
Remarks
The XmlAttributes.XmlArrayItems property allows you to specify the derived types that can be inserted into an array returned by a public field or public read/write property. For each new type you want the field or property to accept, create an XmlArrayItemAttribute object and XmlArrayItemAttributes.Add it to the XmlArrayItemAttributes) returned by the XmlAttributes.XmlArrayItems property. (The new type must be derived from the type already accepted by the field or property.) XmlAttributeOverrides.Add the XmlAttributes object to an XmlAttributeOverrides object, specifying the type of the object containing the field or property, and the name of the field or property. Construct an XmlSerializer with the XmlAttributeOverrides object before calling XmlSerializer.Serialize or XmlSerializer.Deserialize method.
Example
The following example serializes a class that contains a field named Members that returns an array of objects. Two XmlArrayItemAttribute objects are created to allow the field to accept objects that derive from the base class named Member. Each object is added to the XmlAttributes through the XmlAttributes.XmlArrayItems property.
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class Group
{
    public Member [] Members;
}

public class Member
{
    public string MemberName;
}

public class NewMember:Member
{
    public int MemberID;
}

public class RetiredMember:NewMember
{
    public DateTime RetireDate;
}
    

public class Run
{
   public static void Main()
   {
      Run test = new Run();
      test.SerializeObject("OverrideArrayItem.xml");
      test.DeserializeObject("OverrideArrayItem.xml");
   }

   // Return an XmlSerializer used for overriding. 
   public XmlSerializer CreateOverrider()
   {
      // Create XmlAttributeOverrides and XmlAttributes objects.
      XmlAttributeOverrides xOver = new XmlAttributeOverrides();
      XmlAttributes xAttrs = new XmlAttributes();

      // Add an override for the XmlArrayItem.    
      XmlArrayItemAttribute xArrayItem = 
      new XmlArrayItemAttribute(typeof(NewMember));
      xArrayItem.Namespace = "http://www.cpandl.com";
      xAttrs.XmlArrayItems.Add(xArrayItem);

      // Add a second override.
      XmlArrayItemAttribute xArrayItem2 = 
      new XmlArrayItemAttribute(typeof(RetiredMember));
      xArrayItem2.Namespace = "http://www.cpandl.com";
      xAttrs.XmlArrayItems.Add(xArrayItem2);

      // Add all overrides to XmlAttribueOverrides object.
      xOver.Add(typeof(Group), "Members", xAttrs);

      // Create the XmlSerializer and return it.
      return new XmlSerializer(typeof(Group), xOver);
   }
   
 
   public void SerializeObject(string filename)
   {
      // Create an instance of the XmlSerializer class.
      XmlSerializer mySerializer =  CreateOverrider();
      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Create an instance of the class that will be serialized.
      Group myGroup = new Group();

      // Set the object properties.
      NewMember m = new NewMember();
      m.MemberName = "Paul";
      m.MemberID = 2;

      // Create a second member.
      RetiredMember m2 = new RetiredMember();
      m2.MemberName = "Renaldo";
      m2.MemberID = 23;
      m2.RetireDate = new DateTime(2000, 10,10);

      myGroup.Members = new Member[2] {m, m2};
      
      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myGroup);
      writer.Close();
   }

   public void DeserializeObject(string filename)
   {
      XmlSerializer mySerializer = CreateOverrider();
      FileStream fs = new FileStream(filename, FileMode.Open);
      Group myGroup = (Group) 
      mySerializer.Deserialize(fs);
      foreach(Member m in myGroup.Members)
      {
          Console.WriteLine(m.MemberName);
      }
   }
}
   

    

Return to top


Property: XmlAttribute (read-write)
Summary
Gets or sets an object that specifies how the XmlSerializer serializes a public field or public read/write property as an XML attribute.
C# Syntax:
public XmlAttributeAttribute XmlAttribute {get; set;}
Remarks
By default, if no attribute is applied to a public field or public read/write property, it will be serialized as an XML element. You can also instruct the the XmlSerializer to generate an XML attribute by applying an XmlAttributeAttribute to the field or property. The XmlAttributes.XmlAttribute property allows you to override the default serialization, as well as the serialization controlled by applying an XmlAttributeAttribute to the member. To do this, create an XmlAttributeAttribute and set its properties (such as XmlAttributeAttribute.AttributeName). Assign the new object to the XmlAttributes.XmlAttribute property of an XmlAttributes object. Add the XmlAttributes object to an XmlAttributeOverrides object, specifying the type of the object that contains the field or propert, and the name of the field or property. Lastly, create an XmlSerializer using the XmlAttributeOverrides object and call the XmlSerializer.Serialize or XmlSerializer.Deserialize method.
Example
The following example serializes a class named Group that contains a property named GroupName; the GroupName property is serialized as an XML attribute. The example creates an XmlAttributeOverrides and an XmlAttributes object to override the default serialization of the field. The example then creates an XmlAttributeAttribute to specifically override the property, and the object is set to the XmlAttributes.XmlAttribute property The XmlAttributes object is added to the XmlAttributeOverrides object with the name of the overridden member specified. Finally, an XmlSerializer is constructed and returned using the XmlAttributeOverrides object.
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class Group
{
   // This is the attribute that will be overridden.
   [XmlAttribute]
   public string GroupName;
   public int GroupNumber;
}
 
public class Run
{
   public static void Main()
   {
      Run test = new Run();
      test.SerializeObject("OverrideAttribute.xml");
      test.DeserializeObject("OverrideAttribute.xml");
   }
   // Return an XmlSerializer used for overriding. 
   public XmlSerializer CreateOverrider()
   {
      // Create the XmlAttributeOverrides and XmlAttributes objects.
      XmlAttributeOverrides xOver = new XmlAttributeOverrides();
      XmlAttributes xAttrs = new XmlAttributes();

      /* Create an overriding XmlAttributeAttribute set it to 
      the XmlAttribute property of the XmlAttributes object.*/
      XmlAttributeAttribute xAttribute = new XmlAttributeAttribute("SplinterName");
      xAttrs.XmlAttribute = xAttribute;

      // Add to the XmlAttributeOverrides. Specify the member name.
      xOver.Add(typeof(Group), "GroupName", xAttrs);

      // Create the XmlSerializer and return it.
      return new XmlSerializer(typeof(Group), xOver);
   }
 
   public void SerializeObject(string filename)
   {
      // Create an instance of the XmlSerializer class.
      XmlSerializer mySerializer =  CreateOverrider();
      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Create an instance of the class that will be serialized.
      Group myGroup = new Group();

      /* Set the Name property, which will be generated 
      as an XML attribute. */
      myGroup.GroupName = ".NET";
      myGroup.GroupNumber = 1;
      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myGroup);
       writer.Close();
   }

   public void DeserializeObject(string filename)
   {
      XmlSerializer mySerializer = CreateOverrider();
      FileStream fs = new FileStream(filename, FileMode.Open);
      Group myGroup = (Group) 
      mySerializer.Deserialize(fs);
      
      Console.WriteLine(myGroup.GroupName);
      Console.WriteLine(myGroup.GroupNumber);
   }
}
   

    

Return to top


Property: XmlChoiceIdentifier (read-only)
Summary
Gets or sets an object that allows you to disambiguate between a set of choices.
C# Syntax:
public XmlChoiceIdentifierAttribute XmlChoiceIdentifier {get;}

Return to top


Property: XmlDefaultValue (read-write)
Summary
Gets or sets the default value of an XML element or attribute.
C# Syntax:
public object XmlDefaultValue {get; set;}
Remarks
You can specify the default value of an XML element or XML attribute by applying a DefaultValueAttribute to a member. To examine the result of applying the value, compile the application into a DLL or executable, and pass the resulting file as an argument to the XML Schema Definition tool (XSD.exe). In the XML schema document, a default value is assigned to the default attribute. In the example below, the default for the Animal element is "Dogs."
              <?xml version="1.0"?>
              <schema attributeFormDefault="qualified" 
              elementFormDefault="qualified" targetNamespace="" 
              xmlns="http://www.w3.org/2000/10/XMLSchema">
                <element name="Pets" nullable="true" type="Pets"/>
                <complexType name="Pets">
                  <sequence>
                    <element default="Dogs" name="Animal" nullable="true" 
                     type="string" minOccurs="0"/>
                  </sequence>
                </complexType>
              </schema>
                 
            

To override the default value, create an Object and assign it to the XmlAttributes.XmlDefaultValue.

If the value assigned to a field or property is equal to the default value for that field or property, the XmlSerializer will not serialize the value to the XML-instance. This is because the assigned value can be recovered from the XML schema. In other words, setting a field or property to its own default value is equivalent of not setting it at all. Likewise, if no value is set for the field or property, the XmlSerializer will use the default value found in the schema. In both cases, (setting the property to its default, or not setting it at all), the XML-document instance will not contain any value for the property.

Example
The following example shows a class named Pet that contains a field that has a default value set to "Dog". However, the example also creates an XmlAttributes object, and sets its XmlAttributes.XmlDefaultValue property to a new default value ("Cat"). This overrides the original default value. Thus, if the field value is set to "Cat", the XmlSerializer will treat it as the default value, and not serialize it. If it is set to any other value, the XmlSerializer will serialize the value.
using System; 
using System.IO; 
using System.Xml; 
using System.Xml.Serialization; 
using System.ComponentModel; 

// This is the class that will be serialized. 
public class Pet 
{
   // The default value for the Animal field is "Dog". 
   [DefaultValueAttribute("Dog")] 
   public string Animal ; 
} 

public class Run 
{ 
   public static void Main() 
   { 
      Run test = new Run();
      test.SerializeObject("OverrideDefaultValue.xml");
      test.DeserializeObject("OverrideDefaultValue.xml"); 
   }
 
   // Return an XmlSerializer used for overriding. 
   public XmlSerializer CreateOverrider() 
   { 
      // Create the XmlAttributeOverrides and XmlAttributes objects. 
      XmlAttributeOverrides xOver = new XmlAttributeOverrides(); 
      XmlAttributes xAttrs = new XmlAttributes(); 

      // Add an override for the default value of the GroupName. 
      Object defaultAnimal= "Cat";
      xAttrs.XmlDefaultValue = defaultAnimal; 

      // Add all the XmlAttributes to the XmlAttribueOverrides object. 
      xOver.Add(typeof(Pet), "Animal", xAttrs); 

      // Create the XmlSerializer and return it.
      return new XmlSerializer(typeof(Pet), xOver);
   }

   public void SerializeObject(string filename)
   {
      // Create an instance of the XmlSerializer class.
      XmlSerializer mySerializer = CreateOverrider(); 

      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename); 

      // Create an instance of the class that will be serialized. 
      Pet myPet = new Pet(); 

      /* Set the Animal property. If you set it to the default value,
         which is "Cat" (the value assigned to the XmlDefaultValue
         of the XmlAttributes object), no value will be serialized.
         If you change the value to any other value (including "Dog"),
         the value will be serialized.
      */
      // The default value "Cat" will be assigned (nothing serialized).
      myPet.Animal= ""; 
      // Uncommenting the next line also results in the default 
      // value because Cat is the default value (not serialized).
      //  myPet.Animal = "Cat"; 
      
      // Uncomment the next line to see the value serialized:
      // myPet.Animal = "fish";
      // This will also be serialized because Dog is not the 
      // default anymore.
      //  myPet.Animal = "Dog";
      // Serialize the class, and close the TextWriter. 
      mySerializer.Serialize(writer, myPet); 
      writer.Close(); 
   } 

   public void DeserializeObject(string filename) 
   {
      XmlSerializer mySerializer = CreateOverrider();
      FileStream fs = new FileStream(filename, FileMode.Open);
      Pet myPet= (Pet)mySerializer.Deserialize(fs);
      Console.WriteLine(myPet.Animal);
   }
}


    

Return to top


Property: XmlElements (read-only)
Summary
Gets or sets a collection of objects that specify how the XmlSerializer serializes a public field or read/write property as an XML element.
C# Syntax:
public XmlElementAttributes XmlElements {get;}
Remarks
For each overridden member that is serialized as an XML element, you must add a new XmlElementAttribute to an XmlElementAttributes by calling the XmlElementAttributes.Add method. By default, an XmlElementAttributes object is created and assigned to the XmlAttributes.XmlElements property.
Example
The following example serializes the Transportation class, which contains a single field named Vehicles that returns an ArrayList. The example applies two XmlElementAttribute attributes to the Vehicles field. The example creates two XmlElementAttribute objects and adds them to the XmlElementAttributes collection of an XmlAttributes object. To allow the array to accept different object types, the XmlAttributes object is added to the XmlAttributeOverrides object.
using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Xml;

public class Transportation
{
   // Subsequent code overrides these two XmlElementAttributes.
   [XmlElement(typeof(Car)),
   XmlElement(typeof(Plane))]
   public ArrayList Vehicles;
}

public class Car
{
   public string Name;
}

public class Plane
{
   public string Name;
}
public class Truck
{
   public string Name;
}
public class Train
{
   public string Name;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("OverrideElement.xml");
   }

   // Return an XmlSerializer used for overriding.
   public XmlSerializer CreateOverrider()
   {
      // Create the XmlAttributes and XmlAttributeOverrides objects.
      XmlAttributes attrs = new XmlAttributes();

      XmlAttributeOverrides xOver = 
      new XmlAttributeOverrides();
      
      
      /* Create an XmlElementAttribute to override 
      the Vehicles property. */
      XmlElementAttribute xElement1 = 
      new XmlElementAttribute(typeof(Truck));
      // Add the XmlElementAttribute to the collection.
      attrs.XmlElements.Add(xElement1);

      /* Create a second XmlElementAttribute, and 
      add it to the collection. */
      XmlElementAttribute xElement2 = 
      new XmlElementAttribute(typeof(Train));
      attrs.XmlElements.Add(xElement2);

      /* Add the XmlAttributes to the XmlAttributeOverrides,
      specifying the member to override. */
      xOver.Add(typeof(Transportation), "Vehicles", attrs);
      
      // Create the XmlSerializer, and return it.
      XmlSerializer xSer = new XmlSerializer
      (typeof(Transportation), xOver);
      return xSer;
   }

   public void SerializeObject(string filename)
   {
      // Create an XmlSerializer instance.
      XmlSerializer xSer = CreateOverrider();

      // Create the object and serialize it.
      Transportation myTransportation = 
      new Transportation();

      /* Create two new override objects that can be
      inserted into the array. */
      myTransportation.Vehicles = new ArrayList();
      Truck myTruck = new Truck();
      myTruck.Name = "MyTruck";

      Train myTrain = new Train();
      myTrain.Name = "MyTrain";

      myTransportation.Vehicles.Add(myTruck);
      myTransportation.Vehicles.Add(myTrain);

      TextWriter writer = new StreamWriter(filename);
      xSer.Serialize(writer, myTransportation);
      
   }
}


    

Return to top


Property: XmlEnum (read-write)
Summary
Gets or sets an object that specifies how the XmlSerializer serializes an enumeration member.
C# Syntax:
public XmlEnumAttribute XmlEnum {get; set;}
Remarks
For each identifer you want to override, you must create an XmlAttributes object, and set the XmlAttributes.XmlEnum property to an XmlEnumAttribute that overrides the identifier. Add the XmlAttributes object to the XmlAttributeOverrides object, specifying both the Type of the class that contains the enumeration, and the overridden member name.
Example
The following example serializes two classes named Food and FoodType. The FoodType class contains two enumerations that are overridden and, for each enumeration, the example creates an XmlEnumAttribute object which it assigns to the XmlAttributes.XmlEnum property of an XmlAttributes object. The example then adds the XmlAttributes object to an XmlAttributeOverrides object, which is used to create an XmlSerializer.
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class Food
{
   public FoodType Type;
}

public enum FoodType
{
   // Subsequent code overrides these enumerations.
   Low,
   High
}


 
public class Run
{
   public static void Main()
   {
      Run test = new Run();
      test.SerializeObject("OverrideEnum.xml");
      test.DeserializeObject("OverrideEnum.xml");
   }

   // Return an XmlSerializer used for overriding. 
   public XmlSerializer CreateOverrider()
   {
      // Create the XmlAttributeOverrides and XmlAttributes objects.
      XmlAttributeOverrides xOver = new XmlAttributeOverrides();
      XmlAttributes xAttrs = new XmlAttributes();

      // Add an XmlEnumAttribute for the FoodType.Low enumeration.
      XmlEnumAttribute xEnum = new XmlEnumAttribute();
      xEnum.Name = "Cold";
      xAttrs.XmlEnum = xEnum;
      xOver.Add(typeof(FoodType), "Low", xAttrs);

      // Add an XmlEnumAttribute for the FoodType.High enumeration.
      xAttrs = new XmlAttributes();
      xEnum = new XmlEnumAttribute();
      xEnum.Name = "Hot";
      xAttrs.XmlEnum = xEnum;
      xOver.Add(typeof(FoodType), "High", xAttrs);

      // Create the XmlSerializer, and return it.
      return new XmlSerializer(typeof(Food), xOver);
   }
   
 
   public void SerializeObject(string filename)
   {
      // Create an instance of the XmlSerializer class.
      XmlSerializer mySerializer =  CreateOverrider();
      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Create an instance of the class that will be serialized.
      Food myFood = new Food();

      // Set the object properties.
      myFood.Type = FoodType.High;

      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myFood);
      writer.Close();
   }

   public void DeserializeObject(string filename)
   {
      XmlSerializer mySerializer = CreateOverrider();
      FileStream fs = new FileStream(filename, FileMode.Open);
      Food myFood = (Food) 
      mySerializer.Deserialize(fs);

      Console.WriteLine(myFood.Type);
   }
}
   

    

Return to top


Property: XmlIgnore (read-write)
Summary
Gets or sets a value that specifies whether or not the XmlSerializer serializes a public field or public read/write property.
C# Syntax:
public bool XmlIgnore {get; set;}
Remarks
By default, all public fields and public read/write properties are serialized by the XmlSerializer. That is, the value of each public field or property is persisted as an XML element or XML attribute in an XML-document instance.

To override the default serialization of a field or property, create an XmlAttributes object, and set its XmlAttributes.XmlIgnore property to true. XmlAttributeOverrides.Add the object to an XmlAttributeOverrides object specifying the type of the object that contains the field or property to ignore, and the name of the field or property to ignore.

If an XmlIgnoreAttribute is applied to a field or property, the field or property will be ignored. However you can override that behavior by creating an XmlAttributes object, setting its XmlAttributes.XmlIgnore property to false, and adding it to an XmlAttributeOverrides object specifying the type of the object that contains the field or property, and the name of the field or property.

Example
The following example serializes a class named Group,which contains a member named Comment to which the XmlIgnoreAttribute is applied. The example creates an XmlAttributes object, and sets the XmlAttributes.XmlIgnore property to false, thereby overriding the XmlIgnoreAttribute.
using System;
using System.IO;
using System.Xml.Serialization;

// This is the class that will be serialized. 
public class Group
{
   // The GroupName value will be serialized--unless it's overridden.
   public string GroupName;

   /* This field will be ignored when serialized--
      unless it's overridden. */
   [XmlIgnoreAttribute]
   public string Comment;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("IgnoreXml.xml");
   }

   // Return an XmlSerializer used for overriding.
   public XmlSerializer CreateOverrider()
   {
      // Create the XmlAttributeOverrides and XmlAttributes objects.
      XmlAttributeOverrides xOver = new XmlAttributeOverrides();
      XmlAttributes attrs = new XmlAttributes();

      /* Setting XmlIgnore to false overrides the XmlIgnoreAttribute
         applied to the Comment field. Thus it will be serialized.*/
      attrs.XmlIgnore = false;
      xOver.Add(typeof(Group), "Comment", attrs);

      /* Use the XmlIgnore to instruct the XmlSerializer to ignore
         the GroupName instead. */
      attrs = new XmlAttributes();
      attrs.XmlIgnore = true;
      xOver.Add(typeof(Group), "GroupName", attrs);
      
      XmlSerializer xSer = new XmlSerializer(typeof(Group), xOver);
      return xSer;
   }

   public void SerializeObject(string filename)
   {
      // Create an XmlSerializer instance.
      XmlSerializer xSer = CreateOverrider();

      // Create the object to serialize and set its properties.
      Group myGroup = new Group();
      myGroup.GroupName = ".NET";
      myGroup.Comment = "My Comment...";
   
      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Serialize the object and close the TextWriter.
      xSer.Serialize(writer, myGroup);
      writer.Close();
   }
}


    
See also:
XmlIgnoreAttribute

Return to top


Property: Xmlns (read-write)
C# Syntax:
public bool Xmlns {get; set;}

Return to top


Property: XmlRoot (read-write)
Summary
Gets or sets an object that specifies how the XmlSerializer serializes a class as an XML root element.
C# Syntax:
public XmlRootAttribute XmlRoot {get; set;}
Example
The following example creates an XmlAttributeOverrides object, an XmlAttributes object, and an XmlRootAttribute object. The example assigns the XmlRootAttribute to the XmlAttributes.XmlRoot property of the XmlAttributes object, and adds the XmlAttributes object to the XmlAttributeOverrides object. Lastly, the example gets the XmlAttributes object by passing the Type of the serialized class to the XmlAttributeOverrides object. (In this example, the Type is Group.)
using System;
using System.IO;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class Group
{
   public string GroupName;
   [XmlAttribute]
   public int GroupCode;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("OverrideRoot.xml");
   }

   // Return an XmlSerializer for overriding attributes.
   public XmlSerializer CreateOverrider()
   {
      // Create the XmlAttributes and XmlAttributeOverrides objects.
      XmlAttributes attrs = new XmlAttributes();
      XmlAttributeOverrides xOver = new XmlAttributeOverrides();
   
      XmlRootAttribute xRoot = new XmlRootAttribute();

      // Set a new Namespace and ElementName for the root element.
      xRoot.Namespace = "http://www.cpandl.com";
      xRoot.ElementName = "NewGroup";
      attrs.XmlRoot = xRoot;

      /* Add the XmlAttributes object to the XmlAttributeOverrides. 
         No  member name is needed because the whole class is 
         overridden. */
      xOver.Add(typeof(Group), attrs);

      // Get the XmlAttributes object, based on the type.
      XmlAttributes tempAttrs;
      tempAttrs = xOver[typeof(Group)];

      // Print the Namespace and ElementName of the root.
      Console.WriteLine(tempAttrs.XmlRoot.Namespace);
      Console.WriteLine(tempAttrs.XmlRoot.ElementName);

      XmlSerializer xSer = new XmlSerializer(typeof(Group), xOver);
      return xSer;
   }

   public void SerializeObject(string filename)
   {
      // Create the XmlSerializer using the CreateOverrider method.
      XmlSerializer xSer = CreateOverrider();

      // Create the object to serialize.
      Group myGroup = new Group();
      myGroup.GroupName = ".NET";
      myGroup.GroupCode = 123;

      // To write the file, a TextWriter is required.
      TextWriter writer = new StreamWriter(filename);

      // Serialize the object and close the TextWriter.
      xSer.Serialize(writer, myGroup);
      writer.Close();
   }
}


    

Return to top


Property: XmlText (read-write)
Summary
Gets or sets an object that instructs the XmlSerializer to serialize a public field or public read/write property as XML text.
C# Syntax:
public XmlTextAttribute XmlText {get; set;}
Remarks
By default, a public field or public read/write property will be serialized as an XML element by the XmlSerializer. However, can force the field or property to be serialized as XML text by applying an XmlTextAttribute to the field or property.

Note The XmlTextAttribute cannot be applied to a field or property that returns an array.

To override the default serialization of a field or property (that does not return an array), create an XmlTextAttribute and assign it to the XmlAttributes.XmlText property of an XmlAttributes object. Add the XmlAttributes object to an XmlAttributeOverrides object, specifying the type of the object containing the overridden field or property, and the name of the overridden field or property.

Example
The following example serializes the class named Group, which contains a field named Comment. To override the default way the XmlSerializer serializes the field, the example creates an XmlAttributeOverrides and an XmlAttributes object. The example then creates an XmlTextAttribute object, which it assigns to the XmlAttributes.XmlText property, and adds the XmlAttributes object (with the name of the field to be serialized as XML text) to the XmlAttributeOverrides object. Lastly the example creates an XmlSerializer using the XmlAttributeOverrides object.
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class Group
{
   public string GroupName;

   // This field will be serialized as XML text. 
   public string Comment;
}
 
public class Run
{
   public static void Main()
   {
      Run test = new Run();
      test.SerializeObject("OverrideText.xml");
      test.DeserializeObject("OverrideText.xml");
   }

   // Return an XmlSerializer to be used for overriding. 
   public XmlSerializer CreateOverrider()
   {
      // Create the XmlAttributeOverrides and XmlAttributes objects.
      XmlAttributeOverrides xOver = new XmlAttributeOverrides();
      XmlAttributes xAttrs = new XmlAttributes();

      /* Create an XmlTextAttribute and assign it to the XmlText 
      property. This instructs the XmlSerializer to treat the 
      Comment field as XML text. */      
      XmlTextAttribute xText = new XmlTextAttribute();
      xAttrs.XmlText = xText;
      xOver.Add(typeof(Group), "Comment", xAttrs);

      // Create the XmlSerializer, and return it.
      return new XmlSerializer(typeof(Group), xOver);
   }
   
 
   public void SerializeObject(string filename)
   {
      // Create an instance of the XmlSerializer class.
      XmlSerializer mySerializer =  CreateOverrider();
      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Create an instance of the class that will be serialized.
      Group myGroup = new Group();

      // Set the object properties.
      myGroup.GroupName = ".NET";
      myGroup.Comment = "Great Stuff!";      
      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myGroup);
      writer.Close();
   }

   public void DeserializeObject(string filename)
   {
      XmlSerializer mySerializer = CreateOverrider();
      FileStream fs = new FileStream(filename, FileMode.Open);
      Group myGroup = (Group) 
      mySerializer.Deserialize(fs);
      Console.WriteLine(myGroup.GroupName);
      Console.WriteLine(myGroup.Comment);
   }
}
   

    

Return to top


Property: XmlType (read-write)
Summary
Gets or sets an object that specifies how the XmlSerializer serializes a class to which the XmlTypeAttribute has been applied.
C# Syntax:
public XmlTypeAttribute XmlType {get; set;}
Remarks
The XmlTypeAttribute can be used to control how a type is serialized by the XmlSerializer. For example, by default, when a type is serialized, the XmlSerializer uses the class name as the XML element name. By creating an XmlTypeAttribute, setting the XmlAttributes.XmlType property to it, and creating an XmlAttributeOverrides object, you can change the XML element name.
Example
The following example creates an XmlTypeAttribute object, and assigns it to the XmlAttributes.XmlType property of an XmlAttributes object.
using System;
using System.IO;
using System.Xml.Serialization;

public class Transportation
{
   public Car[] Cars;
}

public class Car
{
   public int ID;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("XmlType.xml");
   }

   // Return an XmlSerializer used for overriding.
   public XmlSerializer CreateOverrider()
   {
      // Create the XmlAttributes and XmlAttributeOverrides objects.
      XmlAttributes attrs = new XmlAttributes();
      XmlAttributeOverrides xOver = new XmlAttributeOverrides();
      
      /* Create an XmlTypeAttribute and change the name of the 
         XML type. */
      XmlTypeAttribute xType = new XmlTypeAttribute();
      xType.TypeName = "Autos";

      // Set the XmlTypeAttribute to the XmlType property.
      attrs.XmlType = xType;

      /* Add the XmlAttributes to the XmlAttributeOverrides,
         specifying the member to override. */
      xOver.Add(typeof(Car), attrs);

      // Create the XmlSerializer, and return it.
      XmlSerializer xSer = new XmlSerializer
      (typeof(Transportation), xOver);
      return xSer;
   }

   public void SerializeObject(string filename)
   {
      // Create an XmlSerializer instance.
      XmlSerializer xSer = CreateOverrider();

      // Create object and serialize it.
      Transportation myTransportation = 
      new Transportation();

      Car c1 = new Car();
      c1.ID = 12;

      Car c2 = new Car();
      c2.ID = 44;

      myTransportation.Cars = new Car[2]{c1,c2};

      // To write the file, a TextWriter is required.
      TextWriter writer = new StreamWriter(filename);
      xSer.Serialize(writer, myTransportation);
   }
}


    

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~XmlAttributes();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.