Saturday, 16 August 2014

deserialize list of XElement without list root member



In my case I've a XMLTAG named "phrase" that can contains one or more XMLTAG but they can appear in phraseTag value in a random order. Here it is an example of xmlcode:



<phrase level="1">
Where
<q>are</q>
<subject>you</subject>
<q>going?</q>
</phrase>


For deserialize I'm using this class:



[XmlRoot("phrase")]
public class Phrase
{
[XmlAttribute("level")]
public int Level { get; set; }
[XmlElement("subject")]
public string Subject { get; set; }
[XmlText]
public string Value { get; set; }
}


When I deserialize XML document all class members are successfully serialized:



Phrase.Level = 1
Phrase.Subyect = "you"
Phrase.Value = "Where"


How can I deserialize <q> tags? I've tried to use XmlArrayAttibute and XmlArrayItemAttibute but I have not a member for this list (eg. QTags).


No comments:

Post a Comment