xml があり、xml のテキストに基づいてツリービューを更新します。サンプル XML:
<TaskSeverity></TaskSeverity>
<TaskCategory></TaskCategory>
<TaskTitle></TaskTitle>
<TaskMessage></TaskMessage>
<TaskCode></TaskCode>
<TaskName>SQL_MAPPING_COMPANIES</TaskName>
<Schema>CLIENT</Schema>
<!-- Schema is a required field -->
<Mapping>Companies</Mapping>
<!-- Mapping is a required field -->
<CacheDb>false</CacheDb>
<!-- CacheDb is an optional field. Default value is false -->
<DeleteTableBeforeExecute>true</DeleteTableBeforeExecute>
<!-- DeleteTableBeforeExecute is an optional field. Default value is false -->
今、私はそれを行う方法を持っています。
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 does the deserialization part.
}
// _nodeToTaskDictionary は
public Dictionary<TreeNodeAdv, DmtTask> _nodeToTaskDictionary = new Dictionary<TreeNodeAdv, DmtTask>();
//where TreeNodeAdv is the Treeview (Syncfusion) and DmtTask is an abstract class
public static class DmtTaskToolbox
{
public static DmtTask FromXml(XmlDocument xDoc)
{
DmtTask t = DmtTask.DmtXmlSerializer.Deserialize(new XmlNodeReader(xDoc)) as DmtTask;
// As soon as the above line is executed the value of the last node DeleteTableBeforeExecute innerText is changing to False. I could not understand the reason for it
if (t == null)
throw new Exception("Unable to convert the specific XML document DmtTask");
return t;
}
}
public static XmlSerializer DmtXmlSerializer = new XmlSerializer(typeof(DmtTask), DmtTaskTypes);
そのノードの値に基づいて、テーブルからレコード全体を削除し、新しいレコードを挿入します。しかし、それは false を返します。
これは、逆シリアル化後に表示されるものです
<TaskSeverity></TaskSeverity>
<TaskCategory></TaskCategory>
<TaskTitle></TaskTitle>
<TaskMessage></TaskMessage>
<TaskCode></TaskCode>
<TaskName>SQL_MAPPING_COMPANIES</TaskName>
<Schema>CLIENT</Schema>
<!-- Schema is a required field -->
<Mapping>Companies</Mapping>
<!-- Mapping is a required field -->
<CacheDb>false</CacheDb>
<!-- CacheDb is an optional field. Default value is false -->
<DeleteTableBeforeExecute>false</DeleteTableBeforeExecute>
<!-- DeleteTableBeforeExecute is an optional field. Default value is false -->
どんな助けでも大歓迎です