2

i need to create the following in XML:

<DATAITEMS>
  <DATAITEM>ABC</DATAITEM>
  <DATAITEM>1</DATAITEM>
</DATAITEMS>

when i configure my property as:

public List<string> DATAITEMS { get; set; }

this gives me an output of:

<DATAITEMS>
  <string>ABC</string>
  <string>1</string>
</DATAITEMS>

any idea how can i create collection of DATAITEM instead of string?

thanks

2
  • How are you currently converting the list into XML?
    – Cameron
    Feb 3, 2011 at 17:40
  • well are you serializing your class?
    – Rozuur
    Feb 3, 2011 at 17:53

1 Answer 1

6

I hope you are trying to serialize your data, if so you have to use XmlArrayItem to control array item names.

 [XmlArray("DATAITEMS")]
 [XmlArrayItem("DATAITEM")]
 public List<string> DATAITEMS { get; set; }
2
  • well i was trying serialization now a days :P.
    – Rozuur
    Feb 3, 2011 at 17:47
  • it would really help other if you can edit your question to answer Cameron's and my question :).
    – Rozuur
    Feb 3, 2011 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.