发布时间:2024年11月06日 14:19:35分享人:累却坚持来源:互联网22
view plaincopy to clipboardprint?- usingSystem;
- usingSystem.Collections.Generic;
- usingSystem.ComponentModel;
- usingSystem.Data;
- usingSystem.Drawing;
- usingSystem.Text;
- usingSystem.Windows.Forms;
- usingSystem.Xml;
- namespaceXMLDOMDemo
- {
- publicpartialclassForm1:Form
- {
- publicForm1()
- {
- InitializeComponent();
- }
- privatevoidbtnLoad_Click(objectsender,EventArgse)
- {
- XmlDocumentxmlDoc=newXmlDocument();
- xmlDoc.Load("Books.xml");
- MessageBox.Show(xmlDoc.InnerXml);
- }
- //创建文档
- privatevoidbtnCreate_Click(objectsender,EventArgse)
- {
- XmlDocumentxmlDoc=newXmlDocument();
- //建立Xml的定义声明
- XmlDeclarationdec=xmlDoc.CreateXmlDeclaration("1.0","GB2312",null);
- xmlDoc.AppendChild(dec);
- //创建根节点
- XmlElementroot=xmlDoc.CreateElement("Books");
- xmlDoc.AppendChild(root);
- XmlNodebook=xmlDoc.CreateElement("Book");
- XmlElementtitle=xmlDoc.CreateElement("Title");
- title.InnerText="SQLServer";
- book.AppendChild(title);
- XmlElementisbn=xmlDoc.CreateElement("ISBN");
- isbn.InnerText="444444";
- book.AppendChild(isbn);
- XmlElementauthor=xmlDoc.CreateElement("Author");
- author.InnerText="jia";
- book.AppendChild(author);
- XmlElementprice=xmlDoc.CreateElement("Price");
- price.InnerText="120";
- price.SetAttribute("Unit","___FCKpd___0quot;);
- book.AppendChild(price);
- root.AppendChild(book);
- xmlDoc.Save("Books.xml");
- }
- privatevoidbtnInsert_Click(objectsender,EventArgse)
- {
- XmlDocumentxmlDoc=newXmlDocument();
- xmlDoc.Load("Books.xml");
- XmlNoderoot=xmlDoc.SelectSingleNode("Books");
- XmlElementbook=xmlDoc.CreateElement("Book");
- XmlElementtitle=xmlDoc.CreateElement("Title");
- title.InnerText="XML";
- book.AppendChild(title);
- XmlElementisbn=xmlDoc.CreateElement("ISBN");
- isbn.InnerText="333333";
- book.AppendChild(isbn);
- XmlElementauthor=xmlDoc.CreateElement("Author");
- author.InnerText="snow";
- book.AppendChild(author);
- XmlElementprice=xmlDoc.CreateElement("Price");
- price.InnerText="120";
- price.SetAttribute("Unit","___FCKpd___0quot;);
- book.AppendChild(price);
- root.AppendChild(book);
- xmlDoc.Save("Books.xml");
- MessageBox.Show("数据已写入!");
- }
- privatevoidbtnUpdate_Click(objectsender,EventArgse)
- {
- XmlDocumentxmlDoc=newXmlDocument();
- xmlDoc.Load("Books.xml");
- //"//Book[@Unit="$"]"
- //获取Books节点的所有子节点
- XmlNodeListnodeList=xmlDoc.SelectSingleNode("Books//Book").ChildNodes;
- //遍历所有子节点
- foreach(XmlNodexninnodeList)
- {
- //将子节点类型转换为XmlElement类型
- XmlElementxe=(XmlElement)xn;
- if(xe.Name=="Author")
- {
- xe.InnerText="amandag";
- }
- if(xe.GetAttribute("Unit")=="___FCKpd___0quot;)
- {
- xe.SetAttribute("Unit","¥");
- }
- //break;
- }
- //XmlNodeListnodeList=xmlDoc.SelectNodes("Books//Book");
- //foreach(XmlNodexninnodeList)
- //{
- //foreach(XmlNodexinxn.ChildNodes)
- //{
- ////将子节点类型转换为XmlElement类型
- //XmlElementxe=(XmlElement)x;
- //if(xe.Name=="Author")
- //{
- //xe.InnerText="amandag";
- //}
- //if(xe.GetAttribute("Unit")=="___FCKpd___0quot;)
- //{
- //xe.SetAttribute("Unit","¥");
- //}
- ////break;
- //}
- //}
- xmlDoc.Save("Books.xml");
- }
- privatevoidbtnDelete_Click(objectsender,EventArgse)
- {
- XmlDocumentxmlDoc=newXmlDocument();
- xmlDoc.Load("Books.xml");
- XmlNodeListnodeList=xmlDoc.SelectSingleNode("Books//Book").ChildNodes;
- //遍历所有子节点
- foreach(XmlNodexninnodeList)
- {
- //将子节点类型转换为XmlElement类型
- XmlElementxe=(XmlElement)xn;
- if(xe.Name=="Author")
- {
- xe.RemoveAll();
- }
- if(xe.GetAttribute("Unit")=="¥")
- {
- xe.RemoveAttribute("Unit");
- }
- }
- xmlDoc.Save("Books.xml");
- }
- }
- }

爱华网本文地址 » http://www.413yy.cn/a/25101011/97387.html
更多阅读

在Office XP中,可以使用“稿纸向导”将文档以稿纸方式打印出来,但在Word 2003中,却没有提供这一功能。不过,微软提供了另外一种方法来实现稿纸打印,通过下载并安装一个“Microsoft Office Word 2003 稿纸加载项”,即可使用稿纸功能。使用

Word文档如何添加删除线——简介怎样给Word文档添加删除线,添加单条删除线,添加两条删除线本经验说明:小编使用的是2013版本的office 的word,其它版本的word可能有些差异,请根据实际版本来进行操作。Word文档如何添加删除线——工具/

现在使用PDF格式文件的人越来越多,而要将制作好的Word文档转换成PDF格式,很多人都选择使用第三方工具,其实在Word 2010软件中用自带的另存为功能就能轻松将Word文档转换成PDF文件格式。Word文档怎样转换成PDF——步骤/方法Word文档怎

我们在使用Word2010编辑文档时,有时需要查看文档结构图,以便更清晰地了解整个文档的标题结构,而且还需要知道当前文档中包含的字数。本篇经验就来介绍一下显示文档结构图和查看字数的方法。Word2010中怎样显示文档结构图和查看字数—

?在word文档中使用摄氏度(℃)这个符号对于一般人来说应该是很少用得到的,但对于一些职业如地理、天气等,就会经常使用到了。当然要经常使用的人必定会知道怎样把摄氏度(℃)这个符号写上在word文档中的,但对于不经常使用的人就很难会找到符