Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

¶ÁÈ¡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ÎļþÖеÄ×÷ÓÃ

½â¶ÁPHP DOMDocumentÔÚ½âÎöXMLÎļþÖеÄ×÷ÓÃ
http://developer.51cto.com  2009-12-02 10:39  ØýÃû  Áø³Ç²©¿Í  ÎÒÒªÆÀÂÛ(0)
PHP DOMDocumentµÄ¹¦Äܷdz£Ç¿´ó£¬ÎÒÃÇÔÚÕâÆªÎÄÕÂÖн«½éÉÜÈçºÎÕýÈ·µÄÔËÓÃPHP DOMDocumentÀ´½øÐÐXMLÎļþµÄ½âÎö¡£Ï£Íû¶ÔÓÖÐèÒªµÄÅóÓÑÓÐËù°ïÖú¡£
ÔÚʹÓÃPHP¶ÔXMLÎļþ½øÐнâÎöµÄʱ ......

xml£¬jsp,dtd,xsd ÌáʾÐÅÏ¢

½øÈëMyEclipse6.XÏÂ
Ð޸ģºeclipse.ini Îļþ
-Duser.language=en
¸Ä³É
-Duser.language=zh
µ¯³öÌáʾ£ºCtrl+"/"
dtd ÃüÃû¿Õ¼äµÄÌáʾÐÅÏ¢
window-->Preference-->xml-->XML Catalog-->add
Location :sql-map-2.dtd
key type :pubic ID
key:-//ibatis.apache.org//DTD SQL Map 2.0//EN (XMLÎļþÃüÃû¿Õ¼ ......

StringºÍXmlÖ®¼äµÄת»»¡¢StringתInputStream

ͨ³£ÔÚ²Ù×÷xmlµÄʱºò£¬¶¼ÊÇͨ¹ýinputstream£¨ºÜ¶àÇé¿öÏÂÊÇFileInputStream£©À´¶ÁÈëxml²¢×ªÎªdomµÄ£¬ºÜ¶àÈË»áÓöµ½ÕâÖÖÇé¿öÊý¾Ý²»ÊÇ´ÓÎļþ¶ÁÈëµÄ¶øÊÇ´ÓStringÖÐÈ¡µÃµÄ
ÓÚÊÇ»áʹÓÃ
InputStream in = new ByteArrayInputStream (str.getBytes());À´È¡µÃinputstream £¬µ«ÊÇÕâÖÖInputStreamÖÐÊý¾Ý±»×ª³ÉÁËbyteÊý×飬ËùÒÔתdom ......

¶ÁÈ¡xmlʱ EntityName ʱ³ö´í

public static Hashtable xml_unserialize(string strXml)
        {
//¼ÓÉÏÏÂÃæÕâ¾ä¾ÍºÃÁË
strXml = strXml.Replace("&", "&amp;");
Hashtable ht = new Hashtable();
XmlDocument XMLDom = new XmlDocument();
......

VC¶ÔÓÚXMLµÄ½âÎöÒÔ¼°²Ù×÷

XMLµÄ²éÕÒ
#include <stdio.h>
#include <iostream>
#import <msxml4.dll>
#include <string>
using namespace std;
void Travel(MSXML2::IXMLDOMNodePtr pDOMNode)
{
 if (pDOMNode->GetnodeTypeString()==(_bstr_t)"element") // »ñÈ¡½ÚµãÀàÐÍ
 {
  printf("%s ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ