Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I got answers for serializing my class in the link xml deserialization using XML element/attributes[^]

But I have to include all the elements irrespective of their position in the XML.

XML:
HTML
       <form>
<question id="QnA">
	<answer>AnswerforA</answer>
</question>
<question id="QnB">
	<answer>AnswerforB</answer>
</question>
<question id="QnC">
	<answer>AnswerforC1</answer>
</question>
<section>
<question id="Qnd">
	<answer>Answerford</answer>
</question>
</section>
</form>

.cs:
C#
[XmlRoot("form")]
    public class Form
    {
        [XmlElement("question")]
        public List<question> Questions { get; set; }

        public Form()
        {
            Questions = new List<question>();
        }
    }
    public struct Question
    {
        [XmlAttribute("id")]
        public string ID { get; set; }

        [XmlElement("answer")]
        public string Answer { get; set; }
    }</question></question>



In this, I can get the three elements QnA,QnB,QnC in the Questions list.

How to specify the XML element such that it includes all the question elements under <form> i.e to include the QnD element also in the list.

Thanks
Posted
Updated 18-Oct-11 5:31am
v2

1 solution

With reference to your post, you can create array of Test class.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900