我有一个 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;
}
}
公共静态 XmlSerializer DmtXmlSerializer = new XmlSerializer(typeof(DmtTask), DmtTaskTypes);
基于该节点的值,我将从表中删除整个记录并插入新记录。但它返回错误。
这是反序列化后看到的
<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 -->
任何帮助将不胜感激