XMLDocument对xml文件的增删改查操作.docx

从结构上讲.XmlElement是XmlNode派生类.所以两者比较没什么意义 XmlNode 为抽像类,不能直接实例化. 已知有一个 xml文件(bookstore.xml )如下: ?xml version=1.0 encoding=gb2312? bookstore book gen re=fa ntasy ISBN=2-3631-4 titleOber ons Legacy/title authorCorets, Eva/author PRice5.95/price /book /bookstore 1、往bookstore 节点中插入一个 book 节点: XmlDocume nt xmlDoc =new XmlDocume nt (); xmlDoc.Load(bookstore.xml); XmlNode root=xmlDoc. SelectSingleNode (bookstore); // 查找 bookstore XmlElement xe仁xmlDoc. CreateElement (book); // 创建一个 book 节点 xe1.SetAttribute(genre, 李赞红);// 设置该节点 genre 属性 xe1.SetAttribute(ISBN,2-3631-4);〃 设置该节点 ISBN 属性 XmlEleme nt xesub仁xml

文档评论(0)

1亿VIP精品文档

相关文档