lucene-解析xml

阅读更多

1、安装DOM4j

http://www.dom4j.org/

2、安装jaxen

http://jaxen.org/releases.html

3、代码

package extract;
import java.io.*;
import org.dom4j.*;
import org.dom4j.io.*;
import java.util.*;

public class XmlExtract {
private SAXReader reader;
private Document document;

/**
* @param args
*/
public XmlExtract(){
reader=new SAXReader();
try {
document=reader.read(new File("./htmls/abcde.xml"));
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
public void exxml(String path){
if (document==null) return;
List l=document.selectNodes(path);
System.out.println(path);
Iterator it=l.iterator();
while (it.hasNext()){
Element ele=(Element) it.next();
List li=ele.elements();
Iterator i=li.iterator();
while (i.hasNext()){
Element e=(Element) i.next();
System.out.println("name:"+e.getName()+"\t text:"+e.getText());
}

}
}

public static void main(String[] args) {
// TODO Auto-generated method stub
XmlExtract xmlext=new XmlExtract();
xmlext.exxml("/Config/vmacore/threadPool");
}

}
4、效果与截图

/Config/vmacore/threadPool
name:TaskMax text:40
name:IoMax text:81
name:IoMin text:1

xml文件内容



40
81
1

true



ufa-slave.dll
vss
vsnap
true
vstor2-ws60


ufa-client.dll


ufa-sysReconfig.dll


ufa-sysMigration.dll


ufa-vmImporter.dll
true


ufa-agent.dll
true
false

true


namedPipe
vmware-ufad-ws60-beta3-vmdb


vmware-converter
verbose




ssl/rui.key

ssl/rui.crt

你可能感兴趣的:(XML,lucene,Vmware,VSS)