Java 类org.jdom2.xpath.XPath 实例源码

项目:SvnStat    文件:SvnStat.java   
private boolean isExcludedCommit(Element logEntry) throws JDOMException {
    boolean isExclude = false;
    String file = "none";
    List nodes = XPath.selectNodes(logEntry, "paths/path");
    for (Iterator j = nodes.iterator(); j.hasNext();) {
        Element element = (Element) j.next();
        file = element.getValue();

        for (String exclusion : getExclusions()) {
            if (file.matches(exclusion)) {
                return true;
            }
        }
    }
    return false;
}
项目:xml-patch    文件:Patcher.java   
private static List<Object> selectNodes(Document target, Element patch) throws JDOMException {

        boolean isMultiSelect = false;

        String selector = patch.getAttributeValue("sel");
        if (selector == null) {
            selector = patch.getAttributeValue("msel");
            isMultiSelect = true;
        }

        XPath xpath = XPath.newInstance(selector);
        bindNamespacePrefixes(xpath, patch);
        List content = xpath.selectNodes(target);

        if (content.isEmpty()) {
            throw new PatchException(ErrorCondition.UNLOCATED_NODE,
                    "no matches for selector \"" + selector + "\"");
        }
        if (!isMultiSelect && content.size() > 1) {
            throw new PatchException(ErrorCondition.UNLOCATED_NODE,
                    "more that one match for selector \"" + selector + "\" -- if you want to select multiple nodes, use the 'msel' attribute instead of 'sel'.");
        }
        return content;
    }
项目:yawl    文件:XMLUtils.java   
@SuppressWarnings("unchecked")
public static List getXMLObjects(Document doc, String xpath)
{
    List objects = new ArrayList();
    try
    {
        XPath xp = XPath.newInstance(xpath);
        objects = xp.selectNodes(doc);
    }
    catch (Exception e)
    {
        logger.error("cannot process xpath: " + xpath + " on document: "
                + Utils.element2String(doc == null ? null : doc.getRootElement(), true));
    }
    return objects;
}
项目:FeeCalculator    文件:XMLCreator.java   
@SuppressWarnings({ "unchecked" })
public List<String> readXML(String cityName) {
    List<String> results  = new ArrayList<String>();
    Document doc;
    try {
        SAXBuilder builder = new SAXBuilder();
        doc = (Document) builder.build(xmlFile);

        List<Element> nodes;
        nodes = (List<Element>) XPath.selectNodes(doc, "/costcalculator/city");

        for (Element element : nodes) {
            if (cityName.equals(element.getAttributeValue("name"))) {
                results.add(element.getAttributeValue("name"));
                results.add(element.getChildText(ELEMENT_DISTANCE));
                results.add(element.getChildText(ELEMENT_DURATION));
                results.add(element.getChildText(ELEMENT_TICKET));
                results.add(element.getChildText(ELEMENT_DTICKET));
                results.add(element.getChildText(ELEMENT_HOTEL));
                results.add(element.getChildText(ELEMENT_PUBLICTRANSPORT));
            } 
        }
    } catch (JDOMException | IOException e) {
        e.printStackTrace();
    }
    return results;             
}
项目:ANNeML-Lab    文件:AL_gui.java   
public void loadFile(String pathname, String filename) {

        try {
            // Build & creat the document with SAX, use XML schema validation
            URL path = ClassLoader.getSystemResource("ANNeML.xsd");
            if(path.getFile()==null) {
                jLabel2.setForeground(Color.RED);
                jLabel2.setText("error loading XML schema");  
            }
            else{
                //File argylexsd = new File(path.toURI());
                //XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory(argylexsd);
                XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory("ANNeML.xsd"); //***for .jar deployment
                SAXBuilder builder = new SAXBuilder(schemafac);
                AL_gui.NNetMap = builder.build(pathname);
                java.util.List subnets = XPath.newInstance("//SUBNET").selectNodes(AL_gui.NNetMap);
                java.util.List layers = XPath.newInstance("//LAYER").selectNodes(AL_gui.NNetMap);
                java.util.List inputNeurodes = XPath.newInstance("//NEURODE[SYNAPSE/@ORG_NEURODE='INPUT']").selectNodes(AL_gui.NNetMap);
                java.util.List hiddenNeurodes = XPath.newInstance("//LAYER[@LAYER_NAME='HIDDEN']/NEURODE").selectNodes(AL_gui.NNetMap);
                java.util.List outputNeurodes = XPath.newInstance("//LAYER[@LAYER_NAME='OUTPUT']/NEURODE").selectNodes(AL_gui.NNetMap);                
                jLabel2.setForeground(Color.GREEN);
                jLabel2.setText("Valid ANNeML file.");
            } 
            } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(AL_gui.this, "There was an error parsing the file.\n" + e.toString(), "Warning", JOptionPane.WARNING_MESSAGE);
        }


    }