存入xml操作

 1         //存入数据库
 2         try {
 3             //解析xml
 4             SAXReader reader = new SAXReader();
 5             String path = this.getServletContext().getRealPath("WEB-INF/classes/users.xml");
 6             Document dom = reader.read(path);
 7             Element root = dom.getRootElement();
 8             //凭空创建userEle保存用户信息
 9             Element userEle = DocumentHelper.createElement("user");
10             userEle.setAttributeValue("username", username);
11             userEle.setAttributeValue("password", password);
12             userEle.setAttributeValue("nickname", nickname);
13             userEle.setAttributeValue("email", email);
14             //挂载到根节点
15             root.add(userEle);
16             //更新xml
17             XMLWriter wrtier = new XMLWriter(new FileOutputStream(path),OutputFormat.createPrettyPrint());
18             wrtier.write(dom);
19             wrtier.close();
20         } catch (Exception e) {
21             e.printStackTrace();
22             throw new RuntimeException(e);
23         }
24     }
时间: 2024-12-09 03:19:31

存入xml操作的相关文章

XML操作

XML: XML 指可扩展标记语言 XML 被设计用来传输和存储数据. XML 被设计用来结构化.存储以及传输信息. xml文档展示: -----------------------------xml文档 <?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>George</to> <from>John</from> <heading

c#xml操作

简单的xml操作--解析技能xml xml文件 <skills> <skill> <id>1</id> <name lang="cn">大荒囚天指</name> <demage>100</demage> </skill> <skill> <id>2</id> <name lang="en">绝对零度</na

使用 IntraWeb (31) - IntraWeb 的 Xml 操作使用的是 NativeXml

在 IWNativeXml 单元. 知道了这个, 以后在其他 Delphi 程序中也可以直接 Uses IWNativeXml 了. TNativeXml (IWNativeXml.TNativeXml property AbortParsing: Boolean property BinaryEncoding: TBinaryEncodingType property CommentString: UTF8String property DropCommentsOnParse: Boolean

C#对一个XML操作的实用类

using System; using System.Collections.Generic; using System.Text; using System.Xml; using System.Data; using System.IO; namespace eBlog.Common.Files { public class XmlHelper { protected string strXmlFile; protected XmlDocument objXmlDoc = new XmlDoc

C#常用操作类库三(XML操作类)

/// <summary> /// XmlHelper 的摘要说明. /// xml操作类 /// </summary> public class XmlHelper { protected string strXmlFile; protected XmlDocument objXmlDoc = new XmlDocument(); public XmlHelper(string XmlFile) { // // TODO: 在这里加入建构函式的程序代码 // try { objX

php xml 操作。

参考 文章:http://www.cnblogs.com/zcy_soft/archive/2011/01/26/1945482.html DOMDocument相关的内容. 属性: Attributes 存储节点的属性列表(只读) childNodes 存储节点的子节点列表(只读) dataType 返回此节点的数据类型 Definition 以DTD或XML模式给出的节点的定义(只读) Doctype 指定文档类型节点(只读) documentElement 返回文档的根元素(可读写) fi

C#:XML操作类

写的一个XML操作类,包括读取/插入/修改/删除. using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlContro

Python XML操作

XML(可扩展性标记语言)是一种非常常用的文件类型,主要用于存储和传输数据.在编程中,对XML的操作也非常常见. 本文根据python库文档中的xml.etree.ElementTree类来进行介绍XML的解析:https://docs.python.org/3.5/library/xml.etree.elementtree.html BTW,xml.etree.cElementTree模块从3.3以后就被弃用了. XML格式 首先,来看一下XML所包含的元素类型 1. 标签 <tag> 2.

xml 操作

//////////////////////////////////////////////////////////////////////////// 要操作的xml文件 <?xml version="1.0" encoding="GB2312" standalone="no"?><PhoneInfo>    <Brand name="华为">        <Type name=&