Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

serialize simple array object with top level attribute

$
0
0

Hi

I'm trying to get this into object form

<?xml version="1.0" encoding="UTF-8"?>
<presenceList type="basic">
    <contact contactURI="lsste@nxodev.intra" presenceStatus="UNAVAILABLE"/>
    <contact contactURI="wengerp@nxodev.intra" presenceStatus="AWAY"/>
    <contact contactURI="tdiladm@nxodev.intra" presenceStatus="UNKNOWN"/>
    <contact contactURI="humstermann@nxodev.intra" presenceStatus="UNAVAILABLE"/>
</presenceList>

I got this at the moment, which is almost there, but not quite.. I get dual presenceList.. I know I need the outer presenceList due to the attribute on the top level element

[XmlRoot("presenceList")]
    public class PresenceList
    {
        [XmlAttribute(AttributeName="type")]
        public string PresenceType { get; set; }

        [XmlArray("presenceList")]
        [XmlArrayItem("contact", typeof(PresenceContact))]
        public List<PresenceContact> BasicPresence { get; set; }
    }

    public class PresenceContact
    {
        [XmlAttribute(AttributeName = "contactURI")]
        public string ContactUri { get; set; }

        [XmlAttribute("presenceStatus")]
        public PresenceStatue PresenceStatus { get; set; }

    }
How can I tell my BasicPresence property "you're an array of type PresenceContact", but I don't want any xml element from you (but still get the contacts)?


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>