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"));
//获得根节点
&
相关文档:
wsdl.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<definitions name="MobilePhoneService"
targetNamespace="www.mobilephoneservice.com/MobilePhoneService-interface"
xmlns="http://schemas.xmlsoap.org/wsdl/"
  ......
xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<mobile-list>
<mobile type="Nokia2652">
<wap2>false</wap2>
<width>115</width>
</mobile>
<mobile type="Nokia2650">
......
数据通常是以 XML 格式提供给 Web 应用程序的。但是,XML 数据本质上是分层的,因此您可能希望能够在基于列表的控件中使用 XML 数据,如 GridView 或 DropDownList 控件。此演练演示如何将 XML 数据视为表格数据库表中的数据进行处理。
通过此演练,您将学会如何执行以下任务:
·使用数据源控件读取 XM ......
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 ......