读取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
相关文档:
<script>
var flags ;
if(window.XMLHttpRequest) {
XMLHttpReq = new XMLHttpRequest(); //firefox下执行此语句
}
else if(window.ActiveXObject) {
try{
XMLHttpReq = new Acti ......
通常在操作xml的时候,都是通过inputstream(很多情况下是FileInputStream)来读入xml并转为dom的,很多人会遇到这种情况数据不是从文件读入的而是从String中取得的
于是会使用
InputStream in = new ByteArrayInputStream (str.getBytes());来取得inputstream ,但是这种InputStream中数据被转成了byte数组,所以转dom ......
号称xmlhelper的一个类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
namespace WebApplication2
{
/// <summary>
/// XMLHelper XML文档操作管理器
/// </summary>
public class XMLHelper
{
public X ......
/*样式*/
<style type="text/css">
td{font-size:12px;}
.item{text-decoration:none;width:100%;height:100%; line-height:22px;cursor:default;color:Black;vertical-align:middle}
.staticTab{cursor:default;height:22px}
  ......