none
Xml Attribute in Xml Array

    Question

  • Hi,

    Im trying to serialize a xml document with an array element also have attributes like below:

    <HotelList d1="4" d2="3" d3="4">
      <Hotel>
       <Id>555</Id>
       <Price>50</Price>
      </Hotel>
      <Hotel>
       <Id>556</Id>
       <Price>55</Price>
      </Hotel>
      ....
    </HotelList>

    By creating a custom class name HotelList  i can get attribute array like this:

    ....    
      [XmlElement]
      public HotelList HotelList { get; set; }
    
    }
    
    public class HotelList
        {
            [XmlAnyAttribute]
            public XmlAttribute[] AttributeList{ get; set; }
    }

    And i can get the HotelList  like this:

            [XmlArray]
            [XmlArrayItem(ElementName = "Hotel"]
            public Hotel[] HotelList{ get; set; }

    Problem is i cant acchive both becouse i have to declare type of the HotelList as custom "HotelList" class or Hotel[] array;

    I tried to inherit custom HotelList class for IList and IEnumerable but it doesnt fill AttributeList;

    How can i get both array items and attributes,

    Thank you in advance.


    Monday, April 14, 2014 9:27 AM

Answers

  • Ok we have found the solution,

    public class HotelList
    {
     [XmlAnyAttribute]
     public XmlAttribute[] AttributeList{ get; set; }
    
     [XmlElement("Hotel")]
     public Hotel[] Hotels { get; set; }
    
    }

    • Marked as answer by Caner456 Monday, April 14, 2014 12:10 PM
    Monday, April 14, 2014 12:09 PM