Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i would like to do xmlelements like java in c# code.
I have java model like this:

Java
@XmlElements({ @XmlElement(name = "form", type = FormCondition.class), @XmlElement(name = "idianchargeweapon", type = IdianChargeCondition.class) })
	protected List<Condition> conditions;


There are any solutions for my issue? if yes so i need a example model in c# code.

Thanks for your read and help

What I have tried:

As i know in c# dont exist [XmlElement"s"]
Posted
Updated 11-Dec-16 23:34pm
Comments
dan!sh 12-Dec-16 0:42am    
Could you update the question with a sample XML? BTW, C# does have XMLElement attribute.
EADever 12-Dec-16 4:21am    
I just need to put elements into 1 element and they are in 1 List collection

You will need to decorate Condition class with proper C# attributes. The class must have a XMLType(Name="NameOfChoice") attribute. All the properties that you need to be serialized as XML attributes, must be decorated with XMLAttribute(Name="AttributeName").

While serializing, you can use this:

C#
new XmlSerializer(typeof(List<Condition>), new XmlRootAttribute("Conditions"));


Once serialized, your XML would look like:

XML
<Conditions>
<NameOFChoice AttributeName="ValueOfAttribute" />
<NameOFChoice AttributeName="ValueOfAttribute" />
<NameOFChoice AttributeName="ValueOfAttribute" />
</Conditions>
 
Share this answer
 
there is System.Xml namespace in c# also which is providing all the XMl related facility. for eg. we have XmlNode class containing XmlElement, XmlNodeType etc.
 
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