0

How do we read an attribute of an XML array element? The below code I use to read an attribute of an XML array element which is not working. please let me know an alternate solution to read if avaliable or what i was missing. I saw a lot of samples but unable to identify what i was missing.

Source xml to read is

 <RootElement>
  <devices AttNAme="attValue">
   <device>
     <sometag/>
   <device>
   <device>
      <sometag/>
    <device>
 </devices>
<RootElement>

The Code i use is

[XmlRoot("RootElement")]
public class RootElement
{
[XmlArrayItem("DeviceType", typeof(DeviceTypeSection))]
    [XmlArray("devices")]
    public DeviceTypesSection DeviceTypesInfo { get; set; }

 }

[XmlType("DeviceTypes")]
public class DeviceTypesSection : List<DeviceTypeSection>
{
    [XmlAttribute("AttNAme")]
    public string AttNAme{ get; set; }
}

..and so on

Thanks,

7
  • How about matching up "DeviceType" and "DeviceTypes" ? Commented Oct 31, 2012 at 11:46
  • @HenkHolterman : Thanks , but I did not understand the logic you said. Commented Oct 31, 2012 at 11:53
  • I cannot make them same because i use 'devices' tab attribute to save all devices level info and and for each device info i have separate set of info to save with more sub tags. But is there any clue what i am possibly missing here? Commented Oct 31, 2012 at 12:07
  • Temp fix: Currently resolved this issue using LINQ to XML to directly find those array nodes and reading the attributes of that nodes. Permamnent fix : welcome. (looking how i can read attributes of arrylist node directly when deserialzing the document at once). Commented Nov 1, 2012 at 4:53
  • OK, "make them same" was too simple. But you need full info for mapping types to tags, not clear from your question. Commented Nov 1, 2012 at 8:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.