I really need some help with this.
The problem is that a collection class is not serializing it's "properties"
that I've defined (and marked as an XmlAttribute) it will not export the
attribute properly.
I've listed below some sample code the demonstrates this.
As a result, here's what you get:

<?xml version="1.0" encoding="utf-16"?>
<Master xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:xsd="
http://www.w3.org/2001/XMLSchema";>
 <orders>
   <order id="1a055971-8324-44dd-aacf-f6e9fe982737" />
   <order id="50c4b5b1-d2ba-419b-9c1c-e80169ad738e" />
 </orders>
</Master>

Notice that on the <orders> element there is no attribute.
If you look at the sample code below within the Orders class, I created a
public field called TestAttribute and put an XmlAttribute serialization
declaration around it.

Any help would be greatly appreciated.

Thanks,
Mike

Here's the sample code:

       public static void SetOrders() {

           Master m = new Master();
           Order o = null;

           o = new Order();
           o.id = Guid.NewGuid();

           m.Orders.Add(o);

           o = new Order();
           o.id = Guid.NewGuid();

           m.Orders.Add(o);

           string data = Serialization.GetSerializedXml<Master>(m);
       }

   public static class Serialization {

       /// <summary>
       /// Builds the Serialized xml that represents the specified object
       /// </summary>
       /// <returns></returns>
       public static string GetSerializedXml<ItemType>(ItemType item) {
           //Serialze this object and send to the webservice.
           XmlSerializer xs = new XmlSerializer(typeof(ItemType));
           StringWriter sw = new StringWriter();
           xs.Serialize(sw, item);
           return sw.ToString();
       }

   }

   public class Orders : List<Order> {
       [System.Xml.Serialization.XmlAttribute("testAttribute")]
       public string TestAttribute;
   }

   public class Order {
       [System.Xml.Serialization.XmlAttribute("id")]
       public Guid id;
   }

   public class Master {

       public Master() {
           _orders = new Orders();
       }

       private Orders _orders;
       [System.Xml.Serialization.XmlArray("orders"),
        System.Xml.Serialization.XmlArrayItem("order",
typeof(Order))]
       public Orders Orders {
           get { return _orders; }
           set { _orders = value; }
       }

   }

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to