¶ÁÈ¡xmlÖ¸¶¨½ÚµãÖµ²¢Éú³ÉcsvÎļþ
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class XmlReader {
/**
* ¶ÁÈ¡xmlÎļþÖ¸¶¨½ÚµãÄÚÈݲ¢µ¼³öµ½csvÎļþÖÐ
* @param path
* Ö¸¶¨Îļþ¼Ð·¾¶
* @param destNode
* Ä¿±ê½Úµã
* @param fileName
* ³öÁ¦csvÎļþÃû
*/
public void readXmlFile(String path, String destNode, String fileName) {
File file = new File(fileName);
FileOutputStream out;
try {
// ½¨Á¢csvÊä³öÎļþÁ÷
out = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(out);
BufferedWriter bw = new BufferedWriter(osw);
// ³õʼ»¯csvÎļþ
initCSV(bw);
// µÃµ½Ö¸¶¨Îļþ¼ÐϵÄËùÓÐxmlÎļþ
List fileList = getXmlFiles(path);
// ´´½¨xmlÎļþ
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = null;
String xmlFileName;
Node root;
NodeList links;
for (int k = 0; k < fileList.size(); k++) {
xmlFileName = fileList.get(k).toString();
doc = builder.parse(xmlFileName);
doc.normalize();
// xmlÎļþ¸ù½Úµã
root = doc.getDocumentElement();
// xmlÎļþÖÐËùÓÐÖ¸¶¨½Úµã
links = doc.getElementsByTagName(destNode);
for (int i = 0; i < links.getLength(); i++) {
Node link = links.item(i);
// Ö¸¶¨½ÚµãµÄËùÓÐ×Ó½Úµã
NodeList childNodes = link.getChildNodes();
StringBuffer sb = new StringBuffer();
// ±éÀú×Ó½Úµã
for (int j = 0; j < childNodes.getLength(); j++) {
Node chi
Ïà¹ØÎĵµ£º
½â¶ÁPHP DOMDocumentÔÚ½âÎöXMLÎļþÖеÄ×÷ÓÃ
http://developer.51cto.com 2009-12-02 10:39 ØýÃû Áø³Ç²©¿Í ÎÒÒªÆÀÂÛ(0)
PHP DOMDocumentµÄ¹¦Äܷdz£Ç¿´ó£¬ÎÒÃÇÔÚÕâÆªÎÄÕÂÖн«½éÉÜÈçºÎÕýÈ·µÄÔËÓÃPHP DOMDocumentÀ´½øÐÐXMLÎļþµÄ½âÎö¡£Ï£Íû¶ÔÓÖÐèÒªµÄÅóÓÑÓÐËù°ïÖú¡£
ÔÚʹÓÃPHP¶ÔXMLÎļþ½øÐнâÎöµÄʱ ......
ͨ³£ÔÚ²Ù×÷xmlµÄʱºò£¬¶¼ÊÇͨ¹ýinputstream£¨ºÜ¶àÇé¿öÏÂÊÇFileInputStream£©À´¶ÁÈëxml²¢×ªÎªdomµÄ£¬ºÜ¶àÈË»áÓöµ½ÕâÖÖÇé¿öÊý¾Ý²»ÊÇ´ÓÎļþ¶ÁÈëµÄ¶øÊÇ´ÓStringÖÐÈ¡µÃµÄ
ÓÚÊÇ»áʹÓÃ
InputStream in = new ByteArrayInputStream (str.getBytes());À´È¡µÃinputstream £¬µ«ÊÇÕâÖÖInputStreamÖÐÊý¾Ý±»×ª³ÉÁËbyteÊý×飬ËùÒÔתdom ......
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//µ¼ÈëʹÓÃxmlÓ¦ÓÃËùÐèµ ......
¡¡ÔÚSQL ServerÊý¾Ý¿âÖУ¬µ±ÄãÏëʹÓÃÒ»¸öÊý¾Ý£¬¶øÕâ¸öÊý¾Ý²»±£´æÔÚ±íÖУ¬¼ÆËãÁкÜÓÐÓá£ÀýÈ磬ÄãÓÐÒ»ÕÅ±í£¬Ëü°üÀ¨ÁÐdollar amounts, wholesale pricesºÍretail prices¡£Äã¿Ï¶¨²»ÏëÔÚÿ´Î²éѯ±íʱÀ´¼ÆËãÄÇÁ½ÁÐÖ®¼äµÄ²îÖµ£¬ÄãÏ£Íû½«ÆäÖµ±£´æÔÚµÚÈýÁÐÖУ¬ÈÃÆä×Ô¶¯¼ÆËãǰÁ½ÁÐÖ®¼äµÄ²îÖµ¡£¶ø´ËÁоÍÊǼÆËãÁС£
¡¡¡¡ÔÚSQL ServerÖ ......
¡¡¡¡¡¡ÔÚ²»ÄÜÉÏÍâÍøµÄÇé¿öÏ£¬ÎÒÃÇÔÚeclipseÖÐдxmlʱÎÞ·¨µÃµ½±êÇ©µÄÌáʾ£¬ÒòΪxmlÖеÄdtd»ñÈ¡²»µ½.
¡¡¡¡¡¡¿´ÁËÏÂÍâÃæµÄ×ÊÁÏ¡£ËµÊÇÑ¡Ôñ"window"-->"preferences"--->"Myeclipse Enterprise Workbench"-->"Files and Editors"-->"xml"-->"xml category"
¡¡¡¡¡¡ÔÚuser specified EntriesÖÐÐÂÔöÒ»¸ö. £¨ ......