How to establish an object to this XML file to make objects and XML file serialization and deserialization

xiaoxiao2021-03-06  50

--------- -------------------------------------------------- ---------------------------------------- // Custom XML format [XMLROOT "TEST")] public class clstest {public set room {[xmlattribute (attributename = "n")] public int in; [xmlattribute (attributename = "q")] public int q;}

Private void button3_click (object sender, system.eventargs e) {// object serialized output for XML

XMLSerializer AXML = New XMLSERIALIZER (CLSTEST CLS = New Clstest (); ROM ROM = New Room (); rom.in = 3; rom.iq = 4; cls.myroom = rom; // Create File For Writing Out Textwriter Writer = New StreamWriter (@ "f: /order.xml", false, system.text.encoding.getencoding ("GB2312")); // Serialize Data To file

Axml.Serialize (Writer, CLS); Writer.close ();} ---------------------------------- -------------------------------------------------- ------------------------- There is another problem < Room n = "3" q = "4"> Here are two Room, how should you build an object, And can it be reappeared into an object collection? -------------------------------------------------- -------------------------------------------------- ----------- [XMLROOT ("Test")] public class clstest {public room myroom;

Change to:

[XMLROOT ("test")] public class clstest {public room [] myroom; // use array}

Serialization: ROOM ROM1 = New Room (); rom1.in = 3; rom1.iq = 4;

转载请注明原文地址:https://www.9cbs.com/read-84211.html

New Post(0)