DOM4J生成XML文档
public int createXMLFile(String filename) {
int returnValue = 0;
Document document = DocumentHelper.createDocument(); //生成Document,用于管理XML文档
Element booksElement = document.addElement("books"); //添加根节点
booksElement.addComment("This is a test for dom4j, holen, 2004.9.11"); //添加注释
Element bookElement = booksElement.addElement("book"); //在跟节点books下添加一个book子节点
bookElement.addAttribute("show", "yes"); //为bookElement添加属性,并制定属性的值
Element titleElement = bookElement.addElement("title"); //为bookElement节点添加一个title子节点
titleElement.setText("Dom4j Tutorials"); //为title子节点设置文本节点内容
try {
XMLWriter writer = new XMLWriter(new FileWriter(new File(filename)));
writer.write(document); //普通格式,比较不美观
OutputFormat format =null;
// format=OutputFormat.createPrettyPrint(); //美化格式,读取后美化显示
// writer = new XMLWriter( System.out, format );
// writer.write( document );
// format = OutputFormat.createCompactFormat(); //缩减格式,读取后缩减显示
// writer = new XMLWriter( System.out, format );
// writer.write( document );
writer.close();
return
相关文档:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using System.Data;
using System.Dat ......
Android 是针对移动设备的一种新兴的开源操作系统和 SDK。借助它,您可以创建功能强大的移动应用程序。当您的应用程序可以访问 Web 服务时,其吸引力会大大增加,这意味着您需要使用 Web 语言:XML。在本文中,您将了解在 Android 上使用 XML 的不同方法,以及如何使用它们构建自己的 Android 应用程序。
入门
在本文中 ......
IsolatedStorageFile:包含文件和数据的独立存储区
dataset数据存储到本地xml文档,代码处理如下
public static void WriteDataToXML(DataSet dataset, string dataname)
{
try
{
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForAssembly(); / ......
Definition comparer class,
class ItemComparer : IEqualityComparer<XElement>
{
public bool Equals(XElement x, XElement y)
{
return x.Attribute("Name").Value == x.Attribute("Name").Value;
}
public int GetHashCode(XElement obj)
......