惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
S
SegmentFault 最新的问题
Project Zero
Project Zero
D
DataBreaches.Net
I
InfoQ
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
The Register - Security
The Register - Security
Recorded Future
Recorded Future
Vercel News
Vercel News
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
Intezer
The Hacker News
The Hacker News
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Scott Helme
Scott Helme
T
Threatpost
爱范儿
爱范儿
N
Netflix TechBlog - Medium
D
Docker
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
K
Kaspersky official blog
H
Help Net Security
S
Secure Thoughts
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
G
Google Developers Blog
Forbes - Security
Forbes - Security
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
B
Blog
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
P
Privacy International News Feed
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog

博客园 - 飞鼠

面试时英语自我介绍范文 判斷一天是否是年月中正確的日 - 飞鼠 - 博客园 Javascript中parseInt的一個問題 NUMERIC(3,1) 的含義 在 google 里找书下载的捷径 - 飞鼠 使用asp.net发送邮件详解 創建用戶控件 - 飞鼠 - 博客园 SQL密码 不斷提醒 datagrid用xml作为数据源,并且有更新,删除和排序的操作(VB) - 飞鼠 - 博客园 将xml作为DataGrid 操作(Sort, Edit, Delete) - 飞鼠 用ASP.NET结合XML制作广告管理程序 用ASP.NET结合XML制作广告管理程序(2) - 飞鼠 - 博客园 XML、DataSet、DataGrid结合写成广告管理程序(下)(转载) - 飞鼠 - 博客园 XML、DataSet、DataGrid结合写成广告管理程序(上)(转载) 分别用DataGrid、Repeater、DataList绑定XML数据的例子 - 飞鼠 - 博客园 将某一目录下的所有相同格式的 XML文件绑定到不同的DataGrid - 飞鼠 - 博客园 创建可编辑的xml文档(之五)执行中的treeview 控件 创建可编辑的xml文档(之三)执行拖放操作
创建可编辑的xml文档(之四) 删除、改名、插入操作
飞鼠 · 2005-12-29 · via 博客园 - 飞鼠

执行删除、改名、插入操作
实现了拖放操作就已经完了最难的部分,但是出于完整性考虑,还应该提供一些更好的基本的编辑功能。下面仅仅用四行代码就可以实现删除操作:
[C#]
string xpath_query =
buildXPathQuery(this.SelectedNode);
System.Xml.XmlNode node =
xml_document.DocumentElement.SelectSingleNode(
xpath_query);
node.ParentNode.RemoveChild(node);
SelectedNode.Remove();

[VB]
Dim xpath_query As String = _
buildXPathQuery(Me.SelectedNode)
Dim node As System.Xml.XmlNode = _
xml_document.DocumentElement.SelectSingleNode( _
xpath_query)
node.ParentNode.RemoveChild(node)
SelectedNode.Remove()
重命名操作需要更多的一些考虑,你可以调用buildXPathQuery 去查找那个文件夹正在被编辑,还有如何确定是哪一个属性,如何确定被显示名称相应的返回结构的元素或者子元素?这是一个误导的问题,XPath filte函数已经被定义了,你只需应用现面的转换就可以了:
[C#]
private void XmlTreeView_AfterLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
string xpath_query = buildXPathQuery(e.Node);
System.Xml.XmlNode node =
xml_document.DocumentElement.SelectSingleNode(
xpath_query);
System.Xml.XmlNode label =
node.SelectSingleNode(xpath_filter);
label.Value = e.Label;
}

[VB]
Private Sub XmlTreeView_AfterLabelEdit( _
ByVal sender As Object, _
ByVal e As
System.Windows.Forms.NodeLabelEditEventArgs) _
Handles MyBase.AfterLabelEdit

Dim xpath_query As String = buildXPathQuery(e.Node)
Dim node As System.Xml.XmlNode = _
xml_document.DocumentElement.SelectSingleNode( _
xpath_query)
Dim label As System.Xml.XmlNode =
node.SelectSingleNode(xpath_filter)
label.Value = e.Label
End Sub
最后一个挑战就是如何按照需求创建一个新的文件夹。query filter 允许用户用一组文件夹而不是xml元素操作xml文档。这样对你想在那些文件夹周围进行移动很有帮助的,而且它还可以告诉在哪里插入一个文件夹,但是它不能告诉你这个文件夹应该包含什么东西,你应该猜测文档中的所有文件夹是否含有相同的结构或者内容。但是我们的目标是创建一个不需要任何预定的显示xml 方法。因此,我选择将这些怎人委托给应用程序控制。例如,客户端代码可以下面这样写:
[C#]
System.Xml.XmlDocument insert_fragment =
new System.Xml.XmlDocument();
insert_fragment.LoadXml(
"<product id='New Item'>" +
"<description/><ordercode/><price/>" +
"<image/></product>");

// The TreeView uses XmlInsertionNode to add
// a new folder to the tree's underlying XML
// document on request
xmlTreeView1.XmlInsertionNode =
insert_fragment.DocumentElement;

[VB]
Dim insert_fragment As New System.Xml.XmlDocument()
insert_fragment.LoadXml(" & _
"<product id='New Item'>" & _
"<description/><ordercode/>"<price/>" & _
"<image/></product>")
xmlTreeView1.XmlInsertionNode = _
insert_fragment.DocumentElement
treeview 控件可以缓存一个结构的副本,将它作为一个临时变量来创建一个新的文件夹集合。你所要做的仅仅是确保被定义得文件夹可以被filter query 识别,否则treeview 将不能显示它。因为对于我们操作的文档,xml通常是外部的(external)。在我使用它之前需要导入到文档中

[C#]
// First you need to clone the node template, and
// import it, because it originates from a different
// document
System.Xml.XmlNode copy_node = new_node.Clone();
System.Xml.XmlNode insert_node =
xml_document.ImportNode(copy_node, true);

// Next locate which node should be its parent, and
// insert it
string xpath_query =
buildXPathQuery(this.SelectedNode);
System.Xml.XmlNode node =
xml_document.DocumentElement.SelectSingleNode(
xpath_query);
node.AppendChild(insert_node);

// Finally, apply the xpath filter to determine what
// to display
System.Xml.XmlNode expr =
insert_node.SelectSingleNode(xpath_filter);
System.Windows.Forms.TreeNode new_child =
SelectedNode.Nodes.Add(expr.Value);
populateTreeControl(insert_node, new_child.Nodes);

// Select the node, to force the tree to expand
SelectedNode = new_child;

// And start editing the new folder name
suppress_label_edit = false;
new_child.BeginEdit();

[VB]
' First you need to clone the node template, and
' import it, because it originates from a different
' document.
Dim copy_node As System.Xml.XmlNode = new_node.Clone()
Dim insert_node As System.Xml.XmlNode = _
xml_document.ImportNode(copy_node, True)

' Next locate which node should be its parent,
' and insert it
Dim xpath_query As String = _
buildXPathQuery(Me.SelectedNode)
Dim node As System.Xml.XmlNode =
xml_document.DocumentElement.SelectSingleNode( _
xpath_query)
node.AppendChild(insert_node)

' Finally, apply the xpath filter to determine what
' should be
' displayed
Dim expr As System.Xml.XmlNode = _
insert_node.SelectSingleNode(xpath_filter)
Dim new_child As System.Windows.Forms.TreeNode = _
SelectedNode.Nodes.Add(expr.Value)
populateTreeControl(insert_node, new_child.Nodes)

' Select the node, to force the tree to expand
SelectedNode = new_child

' And start editing the new folder name
suppress_label_edit = False
new_child.BeginEdit()