.net - Trying to understand XML Serialization in C# -


i working on amazon mechanical turk survey project. need understanding how following class translates xml when serialized.

public class contenttype {     public contenttype();      [xmlchoiceidentifier("itemselementname")]     [xmlelement("application", typeof(applicationcontenttype))]     [xmlelement("binary", typeof(binarycontenttype))]     [xmlelement("formattedcontent", typeof(string))]     [xmlelement("text", typeof(string))]     [xmlelement("title", typeof(string))]      public object[] items { get; set; }      [xmlelement("itemselementname")]     [xmlignore]     public itemschoicetype[] itemselementname { get; set; } } 

i making attempt generated following xml document using c# program.

<questionform xmlns="[the questionform schema url]">   <overview>     <title>game 01523, "x" play</title>     <text>       helping decide next move in game of tic-tac-toe.  board looks this:     </text>   </overview>   <question>     <questioncontent>       <text>         coordinates of best move player "x" in game?       </text>     </questioncontent>   </question> </questionform> 

both overview , question elements objects of type "contenttype".

below incomplete , incorrect c# code im trying correct.

using system; using system.collections.generic; using system.text; using amazon.webservices.mechanicalturk; using amazon.webservices.mechanicalturk.domain; using amazon.webservices.mechanicalturk.advanced;  namespace createhitprogram {     class firsthit     {         static void main(string[] args)         {             // create hit specified parameters.             simpleclient client = new simpleclient();              questionform qnform = new questionform();             contenttype qnoverview=new contenttype();             qnform.overview = qnoverview;             questionformquestion[] testquestion1 = new questionformquestion[1];             testquestion1[0] = new questionformquestion();             testquestion1[0].isrequired = true;             testquestion1[0].questionidentifier = "1";             contenttype questioncontenttype=new contenttype();             object[] questionitems=new object[1];             questionitems[0]=new object();             questionitems[0]="swaroop";             questioncontenttype.items = questionitems;             itemschoicetype[] ict = new itemschoicetype[1];             ict[0] = new itemschoicetype();             ict[0] = itemschoicetype.text;             questioncontenttype.itemselementname = ict;             list<qualificationrequirement> qrlist = new list<qualificationrequirement>();              qualificationrequirement qr=new qualificationrequirement();             qr.comparator=comparator.equalto;             qr.integervalue=10;             qr.qualificationtypeid="00000000000000000040";             qr.requiredtopreview=false;             qrlist.add(qr);             string[] rsghit=new string[1];             rsghit[0]="minimal";             decimal reward=0.05m;              hit hit = client.createhit("3lgowex152i2q5fusen2gzft8112f3", "my hopes hit", "almost last attempt", string.empty, qnform, reward, 600, 600, 600, 10, "swarup", qrlist, rsghit);              // write new hit id console.             console.writeline("created hit: {0}", hit.hitid);              console.writeline("hit location: {0}", client.getpreviewurl(hit.hittypeid));         }     } } 

error message when ran above code:

unhandled exception: system.argumentexception: cannot serialize question form (contains no questions) @ amazon.webservices.mechanicalturk.questionutil.serializequestionform(questionform form) @ amazon.webservices.mechanicalturk.simpleclient.createhit(string hittypeid, string title, string description, string keywords, questionform question, nullable1 reward, nullable1 assignmentdurationinseconds, nullable1 autoapprovaldelayinseconds, int64 lifetimeinseconds, nullable1 maxassignments, string requesterannotation, list`1 qualificationrequirements, string[] responsegroup)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -