怎样将XML的Document 转换成 String
import java.io.StringWriter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.xerces.dom.DocumentImpl;
import org.apache.xerces.dom.DOMImplementationImpl;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.Serializer;
import org.apache.xml.serialize.XMLSerializer;
public class HelloApache
{
public static void main (String[] args)
{
try
{
Document doc = new DocumentImpl();
// Create Root Element
Element root = doc.createElement("BOOK");
// Create 2nd level Element and attach to the Root Element
Element item = doc.createElement("AUTHOR");
item.appendChild(doc.createTextNode("Bachelard.Gaston"));
root.appendChild(item);
// Create one more Element
item = doc.createElement("TITLE");
item.appendChild(doc.createTextNode
("The Poetics of Reverie"));
root.appendChild(item);
item = doc.createElement("TRANSLATOR");
item.appendChild(doc.createTextNode("Daniel
Russell"));
root.appendChild(item);
// Add the Root Element to Document
doc.appendChild(root);
//Serialize DOM
OutputFormat format = new OutputFormat (doc);
// as a String
StringWriter stringOut = new StringWriter (); &nb
相关文档:
XML 作为数据源的实例(TESTED)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" preinitialize="preInit()" fontSize="12" height="500">
<mx:Script>
  ......
写这篇文章的原因有如下几点:1)C++标准库中没有操作XML的方法,用C++操作XML文件必须熟悉一种函数库,LIBXML2是其中一种很优秀的XML库,而且它同时支持多种编程语言;2)LIBXML2库的Tutorial写得不太好,尤其是编码转换的部分,不适用于中文编码的转换;3)网上的大多数关于Libxml2的介绍仅仅是翻译了自带的资料,没有详细介 ......
对于小型数据存储很方便。
但多了就要遇到IO瓶颈。
另外,XML格式比较通用。
一般来说,复杂型的数据存储还是用数据库好些。处理方便。而且效率高。
通用性强,可以在任何平台上使用。小型的数据都可以使用XML。
缺点就是有一个缓存的问题
1)XML可以用于本地计算的数据。传递到桌面的数据可以进行本地计算。XM ......
package demo.oath ;
import org.jdom.* ;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class AccountHelper
{
......