本文整理汇总了Java中org.jdom2.xpath.XPath类的典型用法代码示例。如果您正苦于以下问题:Java XPath类的具体用法?Java XPath怎么用?Java XPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XPath类属于org.jdom2.xpath包,在下文中一共展示了XPath类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isExcludedCommit
import org.jdom2.xpath.XPath; //导入依赖的package包/类
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;
}
示例2: selectNodes
import org.jdom2.xpath.XPath; //导入依赖的package包/类
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;
}
示例3: getXMLObjects
import org.jdom2.xpath.XPath; //导入依赖的package包/类
@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;
}
示例4: readXML
import org.jdom2.xpath.XPath; //导入依赖的package包/类
@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;
}
示例5: loadFile
import org.jdom2.xpath.XPath; //导入依赖的package包/类
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);
}
}