flynny
asked on
Serializing XML to Class C#
Hi all I have a xml file which I want to serialize to a class.
Now I want to serialize an array of items, before I have had to encase the items in a parent node for example
in the xml file
and in the class
Now is it possible to lose the encasing element? i.e. the the parent node? and load seelcted elements into an array? Or do I need this preceeding element?
Now I want to serialize an array of items, before I have had to encase the items in a parent node for example
in the xml file
<myclass>
<item1></item1>
<item2></item2>
<parent>
<child></child>
<child></child>
<child></child>
</parent>
</myclass>
and in the class
[XmlArray("parent")]
[XmlArrayItem("child", typeof(myclass))]
public myclass[] children { get; set; }
Now is it possible to lose the encasing element? i.e. the the parent node? and load seelcted elements into an array? Or do I need this preceeding element?
ASKER
Hi Fernando,
thanks for the reply.
Basically I want to create the array as above, but in the XML i would ideally like to remove the parent node wrapping the items. i.e. so i have for example
so the class would be as follows
thanks for the reply.
Basically I want to create the array as above, but in the XML i would ideally like to remove the parent node wrapping the items. i.e. so i have for example
<myclass>
<element1></element1>
<element2></element2>
<element3></element3>
<element3></element3>
<element3></element3>
</myclass>
so the class would be as follows
myclass {
string element1
string element2;
element3[] elements;
}
So you are saying that the XML has this format. It has only one element1 and one element2 and multiple values of element3 and no other nodes are defined, correct? Also are these the actual node names that will be in the document? If they are not what will be the mapping of the nodes in the XML to what you want in the class?
<myclass>
<element1></element1>
<element2></element2>
<element3></element3>
<element3></element3>
<element3></element3>
</myclass>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What do you want this class to look like? Can you post the class definition please.