jdom对xml文件的读写操作
jdom对xml文件的读写操作
1. 读取XML文件Java源代码:
1) xml文件:
<?xml version="1.0" encoding="gb2312"?>
<messages>
<message id="1">
<title>软件工程师</title>
<content>
<name>solidwang</name>
<age>23</age>
</content>
<email>wzzcctv@126.com</email>
</message>
<message id="2">
<title>导游</title>
<content>
<name>eillenwang</name>
<age>20</age>
</content>
<email>eillenwang@163.com</email>
</message>
</messages>
2) 读取xml文件的Java源代码:
package com.solid.xml;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
public class ReadXML {
public static void main(String[] args) throws FileNotFoundException, JDOMException {
//创建构造器
SAXBuilder sb = new SAXBuilder();
//读入指定文件
Document doc = sb.build(new FileInputStream("WebRoot/xmlFile/test.xml"));
//获得根节点
&
相关文档:
test.html
———————————————————————————————————————& ......
个人收集、整理了一些LINQ TO XML的基本方法,希望各位大虾多多指导:
/// <summary>
///Xml节点属性
/// </summary>
public class XmlAttribute
{
public XmlAttribute()
{
}
public XmlAttribute(string _key,object _value)
&nbs ......
xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<mobile-list>
<mobile type="Nokia2652">
<wap2>false</wap2>
<width>115</width>
</mobile>
<mobile type="Nokia2650">
......
xml文件为:
<?xml version="1.0" encoding="UTF-8"?>
<mobile-list>
<mobile type="Nokia2652">
<wap2>false</wap2>
<width>115</width>
</mobile>
<mobile type="Nokia2650">
<wap2>false</wa ......
ArrayCollection转成xml类型示例
下面模拟一组数据exams,将其转化为xml形式.详细代码见下:
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12" creationComplet ......