六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

創(chuàng)建可編輯的xml文檔(之4) 刪除、改名、插入設(shè)置

[摘要]執(zhí)行刪除、改名、插入操作 實(shí)現(xiàn)了拖放操作就已經(jīng)完了最難的部分,但是出于完整性考慮,還應(yīng)該提供一些更好的基本的編輯功能。下面僅僅用四行代碼就可以實(shí)現(xiàn)刪除操作:[C#] string xpath_query = buildXPathQuery(this.SelectedNode);...
執(zhí)行刪除、改名、插入操作
實(shí)現(xiàn)了拖放操作就已經(jīng)完了最難的部分,但是出于完整性考慮,還應(yīng)該提供一些更好的基本的編輯功能。下面僅僅用四行代碼就可以實(shí)現(xiàn)刪除操作:
[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()
重命名操作需要更多的一些考慮,你可以調(diào)用buildXPathQuery 去查找那個(gè)文件夾正在被編輯,還有如何確定是哪一個(gè)屬性,如何確定被顯示名稱相應(yīng)的返回結(jié)構(gòu)的元素或者子元素?這是一個(gè)誤導(dǎo)的問(wèn)題,XPath filte函數(shù)已經(jīng)被定義了,你只需應(yīng)用現(xiàn)面的轉(zhuǎn)換就可以了:
[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
最后一個(gè)挑戰(zhàn)就是如何按照需求創(chuàng)建一個(gè)新的文件夾。query filter 允許用戶用一組文件夾而不是xml元素操作xml文檔。這樣對(duì)你想在那些文件夾周圍進(jìn)行移動(dòng)很有幫助的,而且它還可以告訴在哪里插入一個(gè)文件夾,但是它不能告訴你這個(gè)文件夾應(yīng)該包含什么東西,你應(yīng)該猜測(cè)文檔中的所有文件夾是否含有相同的結(jié)構(gòu)或者內(nèi)容。但是我們的目標(biāo)是創(chuàng)建一個(gè)不需要任何預(yù)定的顯示xml 方法。因此,我選擇將這些怎人委托給應(yīng)用程序控制。例如,客戶端代碼可以下面這樣寫:
[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 控件可以緩存一個(gè)結(jié)構(gòu)的副本,將它作為一個(gè)臨時(shí)變量來(lái)創(chuàng)建一個(gè)新的文件夾集合。你所要做的僅僅是確保被定義得文件夾可以被filter query 識(shí)別,否則treeview 將不能顯示它。因?yàn)閷?duì)于我們操作的文檔,xml通常是外部的(external)。在我使用它之前需要導(dǎo)入到文檔中


[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()


主站蜘蛛池模板: 人人干在线 | 日本免费一区二区在线观看 | 中文字幕亚洲第一 | 天堂网ww | 青青草国产| 污视频免费在线观看 | 日韩中文字幕精品视频在线 | 中文字幕第99页 | 日本在线看 | 日韩在线成人 | 色综合久久中文字幕综合网 | 欧洲另类一二三四区 | 日产日韩亚洲欧美综合搜索 | 午夜影院免费版 | 人人干在线 | 天天欧美| 人人婷婷色综合五月第四人色阁 | 亚洲精品亚洲人成在线观看麻豆 | 日本道综合一本久久久88 | 日本成人免费在线观看 | 性国产| 色网站免费 | 中文字幕在线三浦惠理子 | 热久久最新视频 | 亚洲天堂欧美 | 四虎影院com | 亚洲综合视频在线观看 | 欧美一线视频 | 日韩黄色一级大片 | 伊人剧场| 午夜免费网站 | 婷婷六月久久综合丁香可观看 | 午夜免费视频观看在线播放 | 日本高清视频在线三级 | 亚洲欧美日本韩国综合在线观看 | 五月激情视频 | 亚洲福利精品一区二区三区 | 四虎影永久在线观看网址 | 婷婷丁香花 | 污污网站国产精品白丝袜 | 探花 在线 |