易截截图软件、单文件、免安装、纯绿色、仅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解析xml示例

<!-- xml 格式
<books>
<book id='1001'>
<author>andylin</author>
<title>c language</title>
<publisher id="aaa">O'Reilly</publisher>
</book>

<book id='1002'>
<author>congfeng</author>
<t ......

javascript解析返回的xml各式的字符串

<script>
var flags ;
  if(window.XMLHttpRequest) { 
   XMLHttpReq = new XMLHttpRequest(); //firefox下执行此语句
   }
   else if(window.ActiveXObject) {
    try{
    XMLHttpReq = new Acti ......

将Java对象保存为XML文档

package com.kiloway.trace.utils;
import java.lang.reflect.Field;
/**
* @author Zhang Qi
* @Create Time 2010/01/09
* */
public class ObjectToXML {
public String toString(Object object) throws Exception {
StringBuilder sb = new StringBuilder();
//得到类的名称
String classname = obj ......

PKM2数据导出的xml显示用的XSL

PKM2这个个人知识管理软件相信很多人用过,可以把数据导出为chm电子书,但是不知道为什么倒出来的chm不能按照标题排序,所以我就导出为xml格式,弄个xsl来显示它.
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output me ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号