Atitit dom4j xpath get node n at

2018-06-14  本文已影响12人  ati艾龙AttilaxAkb

Atitit dom4j xpath get node n attrib获取节点与属性结点

/FulltxtLucenePrj/src/com/attilax/util/websvrTomcatUtil.java

package com.attilax.util;

import java.io.File;

import java.io.IOException;

import java.io.StringReader;

import java.util.List;

import org.apache.commons.io.FileUtils;

import org.dom4j.Document;

import org.dom4j.DocumentException;

import org.dom4j.Element;

import org.dom4j.Node;

import org.dom4j.io.SAXReader;

import org.jdom2.JDOMException;

import org.jdom2.input.SAXBuilder;

import org.jdom2.xpath.XPath;

import org.xml.sax.InputSource;

public class websvrTomcatUtil {

public static void main(String[] args) throws IOException, JDOMException, DocumentException {

String xml_f = "C:\\d\\jdk\\tomcatcfg_tmplt\\conf\\server.xml";

  SAXReader reader = new SAXReader();           

       Document   document = reader.read(new File(xml_f));  

       Element root = document.getRootElement(); 

       Node node=document.selectSingleNode("//Connector[@protocol='HTTP/1.1']");

       Element Connector=(Element) node;

       System.out.println(Connector.attributeValue("redirectPort"));

       System.out.println(node.getText());

// jdom2(xml_f);

}

// private static void jdom2(String xml_f) throws IOException, JDOMException {

// SAXBuilder builder = new SAXBuilder();

// StringReader read = new StringReader(FileUtils.readFileToString(new File(xml_f)));

// InputSource source = new InputSource(read);

// Document document = builder.build(source);

// Element root = document.getRootElement();// 获得根节点

//     XPath xpath = XPath.newInstance("//Connector[@protocol='HTTP/1.1']");

//      List list = xpath.selectNodes(root);

//      Element item = (Element) list.get(0);

//      System.err.println(item.getAttributeValue("redirectPort"));

// }

}

Jdom laosh sinbsheo jaxen,,,,act   dom4j yash need jaxen??

简单用DOM4J结合XPATH解析XML - 凌晨。。。三点 - 博客园.html

上一篇下一篇

猜你喜欢

热点阅读