operate XML file (Open,Insert)
1. Some specific name: XmlDocument XmlNodeList XmlNode XmlElement
The whole architecture and relation among them is following
Attentions:selectsinglenodelist(”users”),用于获取users下面的所有直接子节点。这个方法经常用到
2. the difference between xmlnode and xmlelement
XmlElement从XmlNode继承而来,功能基本相同,但XmlElement有更多的功能
3. Insert data into XML file sample:
Sample 1:
XmlDocument xdoc = new XmlDocument();
xdoc.Load(HttpContext.Current.Server.MapPath("user.config"));
XmlElement xde = xdoc.DocumentElement;
XmlElement xe = xdoc.CreateElement("user");
xe.SetAttribute("Login", login);
xe.SetAttribute("Password", pwd);
xe.SetAttribute("RootFolder", rootfolder);
xe.SetAttribute("Rights", rights);
xde.AppendChild(xe);
xdoc.Save(HttpContext.Current.Server.MapPath("user.config"));
the xml file is the following
<?xml version="1.0" standalone="yes"?>
<users>
<user Login="sanxumei" Password="sanxumei" RootFolder="c:\inetpub\wwroot" Rights="User" />
</users>
Sample 2:
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("bookstore.xml");
XmlNode root=xmlDoc.SelectSingleNode("bookstore");//查找<bookstore>
XmlElement xe1=xmlDoc.CreateElement("book");//创建一个<book>节点
xe1.SetAttribute("genre","李赞红");//设置该节点genre属性
xe1.SetAttribute("ISBN","2-3631-4");//设置该节点ISBN属性
XmlElement xesub1=xmlDoc.CreateElement("title");
xesub1.InnerText="CS从入门到精通";//设置文本节点
xe1.AppendChild(xesub1);//添加到<book>节点中
XmlElement xesub2=xmlDoc.CreateElement("author");
xesub2.InnerText="候捷";
xe1.AppendChild(xesub2);
XmlElement xesub3=xmlDoc.CreateElement("price");
xesub3.InnerText="58.3";
xe1.AppendChild(xesub3);
root.AppendChild(xe1);//添加到<bookstore>节点中
xmlDoc.Save("bookstore.xml");
转载于:https://www.cnblogs.com/Winston/archive/2008/01/04/1026475.html
operate XML file (Open,Insert)相关推荐
- Binary XML file line #8: Error inflating class android.support.v7.widget.RecyclerView
今天创建了一个 demo ,然后就是复制RecyclerView 过去, 到最后完成运行的时候发现 系统奔溃了, 然后 提示 Binary XML file line #8: Error inflat ...
- Android运行时候报错:android.view.InflateException: Binary XML file line #19: Binary XML file lin
Android运行时候报错:android.view.InflateException: Binary XML file line #19: Binary XML file lin 这个问题自己大致在 ...
- android.view.InflateException: Binary XML file line #7: Binary XML file line #7
错误如下 11-21 08:19:44.040 3608-3608/com.leon.oldrecyclerview E/AndroidRuntime: FATAL EXCEPTION: main ...
- android Binary XML file line #1: Binary XML file line #1: Error inflating class x 问题详解
话不多少,上错误堆栈: Process: com.mci.smagazine, PID: 25065java.lang.RuntimeException: Unable to start activi ...
- 报错android.view.InflateException: Binary XML file line #11: Attempt to invoke virtual method 'boolean
出现这种问题,打开Android monitor的调试信息发现是 android.view.InflateException: Binary XML file line #11: Attempt to ...
- 安卓(android)建立项目时失败,出现Android Manifest.xml file missing几种解决方法?...
安卓(android)建立项目时失败,出现AndroidManifest.xml file missing几种解决方法? Eclipse新建项目,遇到这样的问题,注意如下: 1.文件名最好不要用中文. ...
- UI Automator Viewer Error while obtaining UI hierarchy XML file
Error obtaining UI hierarchy Reason: Error while obtaining UI hierarchy XML file: com.android.ddmlib ...
- Android --- Binary XML file line2 Binary XML file line 2 Error inflating class unknown
报错信息如下: 05/21 10:18:21: Launching app $ adb push D:\android install files\jishi\app\build\outputs\ap ...
- XML file does not appear to have any style information associated with it. XHTML程序出现这个错误
编写xhtml代码出现错误: This XML file does not appear to have any style information associated with it. The d ...
最新文章
- hbuildx打包成apk_HBuilder打包webapp为apk的方法
- P1063 能量项链
- wxWidgets:wxInitDialogEvent类用法
- 06.QT菜单栏QAction学习(二)
- 记录——《C Primer Plus (第五版)》第十章编程练习第八题
- 搭建dubbo框架的遇到的一些问题
- UiPath安装pdf
- WES7 定制界面完整过程
- HTML5生日快乐代码 (烟花蛋糕+3D相册) HTML+CSS+JavaScript
- matlab分析电路,基于Matlab的电路节点分析法
- 微电子电路——PMOS网表详解
- 如何对待新事物_以积极态度看待不断出现的新事物
- selenium自动化之PO模型
- [转]技术经纪人将成职业新宠
- ExoPlayer修改播放器UI
- FreeMarker的基础操作
- 各种智能优化算法比较与实现(matlab版)
- 妈,别再乱买保健品了!
- Outlook Express邮件丢失的原因
- JAVA电影院管理系统计算机毕业设计Mybatis+系统+数据库+调试部署