VB.NET中操作xml文件(插入节点、修改、删除)
已知有一个XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
</bookstore>
1、往<bookstore>节点中插入一个<book>节点:
Dim xmlDoc As New XmlDocument()
xmlDoc.Load("bookstore.xml")
Dim root As XmlNode = xmlDoc.SelectSingleNode("bookstore") '查找<bookstore>
Dim xe1 As XmlElement = xmlDoc.CreateElement("book") '创建一个<book>节点
xe1.SetAttribute("genre", "李赞红") '设置该节点genre属性
xe1.SetAttribute("ISBN", "2-3631-4") '设置该节点ISBN属性
Dim xesub1 As XmlElement = xmlDoc.CreateElement("title")
xesub1.InnerText = "CS从入门到精通" '设置文本节点
xe1.AppendChild(xesub1) '添加到<book>节点中
Dim xesub2 As XmlElement = xmlDoc.CreateElement("author")
xesub2.InnerText = "候捷"
xe1.AppendChild(xesub2)
Dim xesub3 As XmlElement = xmlDoc.CreateElement("price")
xesub3.InnerText = "58.3"
xe1.AppendChild(xesub3)
root.AppendChild(xe1) '添加到<bookstore>节点中
xmlDoc.Save("bookstore.xml")
//===============================================
结果为:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
<book genre="李赞红" ISBN="2-3631-4">
<title>CS从入门到精通</title>
<author>候捷</author>
<price>58.3</price>
</book>
</bookstore>
2、修改节点:将genre属性值为“李赞红“的节点的genre值改为“update李赞红”,将该节点的子节点<author>的文本修改为“亚胜”。
Dim nodeList As XmlNodeList = xmlDoc.SelectSingleNode("bookstore").ChildNodes '获取bookstore节点的所有子节点
Dim xn As XmlNode
For Each
相关文档:
上集中只是显示星期几,不够全面,完善后如下:
1、创建lbl1、lbl2、lbl3、txt1、cmd1、Timer1
2、lbl:“输入年月日(如2000-8-16):”,设置lbl、txt1、cmd1的字体大小和颜色。Timer1的Enable属性设为False,Interval属性设为:1000。
3、双击cmd1,进入代码编辑窗口,敲入:
Private Sub Timer1_Timer()
......
原来的错误是:Timer1的Enabled属性设为True。
代码错误是:
Private Sub Timer1_Timer()
Dim c As Date
c = Time
lbl3.Caption = CStr(c)
End Sub
————————————————&mdas ......
窗体设置,控件布局时用:
alt+v+x可以快速显示出工具框
Alt+P+N 引用
ctrl+左右键头可以移动控件
shift+左右键头调整控件大小
F7 切换到编辑窗口
Shift+f7 切换代码窗口
开发代码,调试代码都能用的:
Ctrl+C复制
Ctrl+V粘贴
Ctrl+X剪贴
Ctrl+F查找
开发代码时用的:
Tab 向右推
Shi ......
原贴: http://topic.csdn.net/u/20100414/11/c69748ac-e0b2-490f-bde9-7c5284c3660c.html?seed=1832202493
declare @xml xml=
'<upd:Update xmlns:lar="http://schemas.microsoft.com/msus/2002/12/LogicalApplicabilityRules" xmlns:cmd="http://schemas.microsoft.com/msus/2002/12/UpdateHandlers/Command ......
string file = "c:\\work.xml";
private void btnCearte_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
  ......