Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.StringReader;

import java.util.ArrayList;
import java.util.List;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

public class Main {
    public static List<String> xPathEvalList(String content, String expression) throws XPathExpressionException {
        List<String> retValues = new ArrayList<String>();
        XPath xpath = XPathFactory.newInstance().newXPath();
        InputSource inputSource = new InputSource(new StringReader(content));
        NodeList ox = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
        for (int i = 0; i < ox.getLength(); i++) {
            retValues.add(ox.item(i).getNodeValue());
        }

        return retValues;
    }
}