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