ÈçºÎÀûÓÃdom4jÉú³ÉXMLÎļþ!
´Ë²¿·ÖÔ´ÂëΪ×îºËÐIJ¿·Ö´úÂ룡
package com.etong.allen;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import com.etong.common.util.StringUtils;
import com.roger.database.DBAction;
public class BaseXMLOperator {
/**
* Éú³ÉÒ»¸öеÄDocument¶ÔÏó
* @return document
*/
protected Document createDocument() {
Document document = DocumentHelper.createDocument();
return document;
}
/**
* ´´½¨Ò»¸öеÄElement¶ÔÏó
* @param paramName Element¶ÔÏóÃû³Æ
* @param paramValue Element¶ÔÏóÖµ
* @return element
*/
protected Element createElement(Document document, String paramName, String paramValue) {
if (paramValue != null) {
return document.addElement(paramName, paramValue);
} else {
return document.addElement(paramName);
}
}
/**
* ÏòXMLÎļþÖÐÔö¼Ó½Úµã
* @param document ÔØÈëXMLÎļþºó»ñµÃµÄDocument¶ÔÏó
* @param fatherElementId ÒªÔö¼Ó½ÚµãµÄ¸¸½ÚµãId
* @param element ÒªÔö¼ÓµÄ½Úµã¶ÔÏó
*/
protected Element addElement(Element element, String titleName) {
return element.addElement(titleName);
}
/**
* ÏòXMLÎļþÖÐÔö¼ÓÒ»¸ö×Ó½Úµã--ÓÃ
Ïà¹ØÎĵµ£º
JDOM ÊÇÒ»¸ö¿ªÔ´µÄ´¿java API,ÓÃÓÚ¿ìËÙ¿ª·¢ XML Ó¦ÓóÌÐò,JDOM½«XMLÎĵµ±íʾΪÊ÷£¬°üÀ¨ÔªËØ¡¢ÊôÐÔ¡¢ËµÃ÷¡¢´¦ÀíÖ¸Áî¡¢Îı¾½Úµã¡¢CDATA¶Î£¬µÈµÈ¡£JDOM¿ÉÒÔËæʱ·ÃÎÊÊ÷ÖеÄÈÎÒⲿ·Ö¡£Ê÷ÖÐËùÓв»Í¬½Úµã¾ùΪ¾ßÌåµÄÀà¡£ÔÚhttp://jdom.org¿ÉÒÔÏÂÔØJDOMµÄ×îа汾(ÎÒÕâÀïÊÇ1.0)¡£ÏÂÔغó½âѹ£¬JDOMµÄjarÎļþ¾ÍÊÇbuildÄ ......
XMLµÄÈ«³ÆExtensible Markup Language,Òâ˼ÊÇ¿ÉÀ©Õ¹µÄ±ê¼ÇÓïÑÔ£¬ÊDZê׼ͨÓñê¼ÇÓïÑÔSGML(Standard Generalized Markup Language)µÄÒ»¸ö×Ó¼¯¡£1998Äê2Ô£¬W3C·¢²¼ÁËXML1.0±ê×¼£¬ÆäÄ¿µÄÊÇΪÁËÔÚWebÉÏÄÜÒÔÏÖÓеij¬Îı¾±ê¼ÇÓïÑÔHTMLµÄʹÓ÷½Ê½Ìṩ£¬½ÓÊպʹ¦ÀíͨÓõÄSGML¡£XMLÊÇSGMLµÄÒ»¸ö¼ò»¯×Ó¼¯£¬ËüÒÔÒ»ÖÖ¿ª·ÅµÄ£¬×ÔÎÒÃèÊöµÄ ......
ÔÚ
SQLServer2005
ÖжÔ
XML
µÄ´¦Àí¹¦ÄÜÏÔÈ»ÔöÇ¿Á˺ܶ࣬ÌṩÁË
query(),value(),exist(),modify(),nodes()
µÈº¯Êý¡£
¹ØÓÚ
xml
£¬ÄÑÒÔÀí½âµÄ²»ÊÇ
SQLServer
ÌṩµÄº¯Êý£¬¶øÊǶÔ
xml
±¾ÉíµÄÀí½â£¬¿´Ëƺܼòµ¥µÄÎļþ¸ñʽ£¬´¦ÀíÆðÀ´È´ÊǷdz£À§Äѵġ£±¾ÎÄÖ»Êdzõ̽һ϶øÒÑ¡£
Ïê¼û
SQLServer
Áª»ú°ïÖú£º
Ö÷Ìâ
˵ ......
¶ÔÓÚ½«TXTÎĵµÖÐÊý¾Ýµ¼ÈëXMLÖеijÌÐòÍøÉϲ»¶à£¬µ«ÊÇÓкܶàÊÇÏȽ«TXTµ¼Èëµ½DataSetÖУ¬ÔÚÓÃXML½øÐд«Êä¡£ËùÒÔ±¾È˾ÍÔÚÕâÀïÓë´ó¼Ò·ÖÏíÒ»ÏÂÖ±½Óµ¼ÈëµÄÕâÖÖ·½Ê½¡£
±¾³ÌÐòÒ²¿ÉÒÔÓ¦ÓÃÓÚASP.NETÖУ¬ÄÇôÏÂÃæµÄÃüÃû¿Õ¼ä¼°Ò»Ð©µØ·½¾ÍµÃ¸Ä¸ÄÁË£¬»¹ÓÐÒª½«³ÌÐò¶¼·ÅÓÚPage_LoadÖС£
using System;
using System.Collections.Generic;
......
---xml²ð·ÖÒÔ²»¶¨¿Õ¸ñΪ·Ö¸î·ûºÅµÄ×Ö·û´®
--²âÊÔÊý¾Ý
if object_id('[tb]') is not null drop table [tb]
create table [tb]([a] varchar(200))
go
insert [tb]
select 'aaaa bbbb cccc dddd'
insert [tb]
select 'eeeeee ffff hhhh   ......