deserialization - Deserializing the xml document is changing the value of node in the xml -
i have xml , update treeview based on text in xml. sample xml:
<taskseverity></taskseverity> <taskcategory></taskcategory> <tasktitle></tasktitle> <taskmessage></taskmessage> <taskcode></taskcode> <taskname>sql_mapping_companies</taskname> <schema>client</schema> <!-- schema required field --> <mapping>companies</mapping> <!-- mapping required field --> <cachedb>false</cachedb> <!-- cachedb optional field. default value false --> <deletetablebeforeexecute>true</deletetablebeforeexecute> <!-- deletetablebeforeexecute optional field. default value false -->
now have method that.
public void updatetreeview(xmldocument xdoc) { xmltreeviewadv.nodes.clear(); _nodetotaskdictionary.clear(); if (xdoc == null) return; treenodeadv rootnode = new treenodeadv(xdoc.documentelement.name); if (rootnode.text.equals("dmttask") && xdoc.documentelement != null) { foreach (xmlattribute attribute in xdoc.documentelement.attributes) { if (attribute.name.equals("xsi:type")) { rootnode.text = attribute.value; } } } xmltreeviewadv.nodes.add(rootnode); rootnode.font = new font(rootnode.font, fontstyle.bold); _nodetotaskdictionary.add(rootnode, dmttasktoolbox.fromxml(xdoc)); //this particular line deserialization part. }
// _nodetotaskdictionary
public dictionary<treenodeadv, dmttask> _nodetotaskdictionary = new dictionary<treenodeadv, dmttask>(); //where treenodeadv treeview (syncfusion) , dmttask abstract class public static class dmttasktoolbox { public static dmttask fromxml(xmldocument xdoc) { dmttask t = dmttask.dmtxmlserializer.deserialize(new xmlnodereader(xdoc)) dmttask; // above line executed value of last node deletetablebeforeexecute innertext changing false. not understand reason if (t == null) throw new exception("unable convert specific xml document dmttask"); return t; } }
public static xmlserializer dmtxmlserializer = new xmlserializer(typeof(dmttask), dmttasktypes);
based on value of node deleting entire records table , insert new records. returning false.
this see after deserialization
<taskseverity></taskseverity> <taskcategory></taskcategory> <tasktitle></tasktitle> <taskmessage></taskmessage> <taskcode></taskcode> <taskname>sql_mapping_companies</taskname> <schema>client</schema> <!-- schema required field --> <mapping>companies</mapping> <!-- mapping required field --> <cachedb>false</cachedb> <!-- cachedb optional field. default value false --> <deletetablebeforeexecute>false</deletetablebeforeexecute> <!-- deletetablebeforeexecute optional field. default value false -->
any appreciated
the issue public variable defined in abstract class deletetablebeforeexectue different spelling of tag deletetablebeforeexecute defined in xmldocument trying deserialize.
when serializing classes xml, each public property , field value transformed xml element. name of element matches name of property. xmlelement attribute allows names , formatting of xml tags modified