XML格式转化工具类
基于dom4j的XML格式转化类
package com.lixi.util;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
/**
* <p>Title: </p>
* <p>Description: XML格式转化工具</p>
* <p>Copyright: Copyright (c) 2010-02-05</p>
* <p>Company: </p>
* @author li.xi
* @version 1.0
*/
public class XmlHelper {
public XmlHelper() {
}
/**
* String格式的XML转Document
* @param xml
* @param charSet 字符集编码设置 如:GBK
* @return Document
* @throws Exception
*/
public static Document buildDoc(String xml, String charSet)
throws Exception {
InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
SAXReader reader = new SAXReader();
InputStreamReader inputStreamReader = new InputStreamReader(
inputStream, charSet);
Document document = reader.read(inputStreamReader);
inputStreamReader.close();
return document;
}
/**
* Document格式的XML转String
* @param document
* @param charSet 字符集编码设置
* @return String
* @throws Exception
*/
public static String setCharSet(Document document, String charSet)
throws Exception {
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding(charSet);
ByteArrayOutputStream fos = new ByteArrayOutputStream();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos,
charSet));
XMLWriter writer = new XMLWriter(bw, format);
writer.write(document);
bw.close();
String restr = fos.toString();
fos.close();
return restr;
}
}
相关文档:
1. 基础:对XML进行简单的查询, 插入, 删除, 编辑操作
在数据量不是很大的情况下,可以用xml代替数据库存储数据,但是要定义xsd文件来验证xml文件,保证xml数据格式。
以下网页介绍了如何利用C#实现xml的查询,插入,删除和更新操作,这表明xml可以代替数据库存储一定量的数据。
http://blog.csdn.net/cmoonc/archive/20 ......
精短高效的XML解析器,纯C单一程序,应用于银行的国税库行横向联网接口系统中,稳定可靠,运行速度飞快,非相应的JAVA程序可比.以下为大部分源码:
/* Copyright (c) 2005 wzs */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <varargs.h>
#i ......
If XML data in the table is less than 32K for each record, then you can directly unload the data as char. If XML data exceeds 32K for some records, then you have to unload the common data and the XML data separately. First, create a template for unloading XML into a PDS: TEMPLATE LOBFRV DSN 'AAA. ......
转自http://www0.ccidnet.com/tech/guide/2001/10/08/58_3392.html
SAX概念
SAX是Simple API for XML的缩写,它并不是由W3C官方所提出的标准,可以说是“民间”的事实标准。实际上,它是一种社区性质的讨论产物。虽然如此,在XML中对SAX的应用丝毫不比DOM少,几乎所有的XML解析器都会支持它。
与DOM比较而言 ......
SAX概念
SAX是Simple API for XML的缩写,它并不是由W3C官方所提出的标准,可以说是“民间”的事实标准。实际上,它是一种社区性质的讨论产物。虽然如此,在XML中对SAX的应用丝毫不比DOM少,几乎所有的XML解析器都会支持它。
与DOM比较而言,SAX是一种轻量型的方法。我们知道,在处理DOM的时候,我们需要读 ......