- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中org.jdom2.xpath.XPath.newInstance()
方法的一些代码示例,展示了XPath.newInstance()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XPath.newInstance()
方法的具体详情如下:
包路径:org.jdom2.xpath.XPath
类名称:XPath
方法名:newInstance
[英]Creates a new XPath wrapper object, compiling the specified XPath expression.
[中]创建新的XPath包装器对象,编译指定的XPath表达式。
代码示例来源:origin: simpligility/android-maven-plugin
XPath path = XPath.newInstance( xpath );
Object source = path.selectSingleNode( r.getRootElement() );
if ( !( source instanceof Element ) )
代码示例来源:origin: org.jdom/jdom
/**
* <i>[Serialization support]</i> Resolves the read XPathString
* objects into XPath implementations.
*
* @return an instance of a concrete implementation of
* XPath.
*
* @throws ObjectStreamException if no XPath could be built
* from the read object.
*/
private Object readResolve() throws ObjectStreamException {
try {
return XPath.newInstance(this.xPath);
}
catch (JDOMException ex1) {
throw new InvalidObjectException(
"Can't create XPath object for expression \"" +
this.xPath + "\": " + ex1.toString());
}
}
}
代码示例来源:origin: org.jdom/jdom
/**
* Evaluates the wrapped XPath expression and returns the first
* entry in the list of selected nodes (or atomics).
* <p>
* <strong>Note</strong>: This method should not be used when the
* same XPath expression needs to be applied several times (on the
* same or different contexts) as it requires the expression to be
* compiled before being evaluated. In such cases,
* {@link #newInstance allocating} an XPath wrapper instance and
* {@link #selectSingleNode(java.lang.Object) evaluating} it
* several times is way more efficient.
* </p>
*
* @param context the element to use as context for evaluating
* the XPath expression.
* @param path the XPath expression to evaluate.
*
* @return the first selected item, which may be of types: {@link Element},
* {@link Attribute}, {@link Text}, {@link CDATA},
* {@link Comment}, {@link ProcessingInstruction}, Boolean,
* Double, String, or <code>null</code> if no item was selected.
*
* @throws JDOMException if the XPath expression is invalid or
* its evaluation on the specified context
* failed.
*/
public static Object selectSingleNode(Object context, String path)
throws JDOMException {
return newInstance(path).selectSingleNode(context);
}
代码示例来源:origin: org.jdom/jdom
/**
* Evaluates an XPath expression and returns the list of selected
* items.
* <p>
* <strong>Note</strong>: This method should not be used when the
* same XPath expression needs to be applied several times (on the
* same or different contexts) as it requires the expression to be
* compiled before being evaluated. In such cases,
* {@link #newInstance allocating} an XPath wrapper instance and
* {@link #selectNodes(java.lang.Object) evaluating} it several
* times is way more efficient.
* </p>
*
* @param context the node to use as context for evaluating
* the XPath expression.
* @param path the XPath expression to evaluate.
*
* @return the list of selected items, which may be of types: {@link Element},
* {@link Attribute}, {@link Text}, {@link CDATA},
* {@link Comment}, {@link ProcessingInstruction}, Boolean,
* Double, or String.
*
* @throws JDOMException if the XPath expression is invalid or
* its evaluation on the specified context
* failed.
*/
public static List<?> selectNodes(Object context, String path)
throws JDOMException {
return newInstance(path).selectNodes(context);
}
代码示例来源:origin: org.openfuxml/ofx-wiki
public XhtmlCodePreMover()
{
try
{
xpathCode = XPath.newInstance("//code");
xpParent = XPath.newInstance("..");
xpathPre = XPath.newInstance("following-sibling::pre[position()=1]");
// xpath.addNamespace(Namespace.getNamespace("ofx", "http://www.openfuxml.org"));
// xpath.addNamespace(Namespace.getNamespace("wiki", "http://www.openfuxml.org/wiki"));
}
catch (JDOMException e) {logger.error("",e);}
}
代码示例来源:origin: org.openfuxml/ofx-wiki
protected double getChartValue(String xp, String type, Document doc)
{
double value=0;
try
{
XPath xPath = XPath.newInstance(xp+"[@type='"+type+"']");
Element element = (Element)xPath.selectSingleNode(doc);
value = new Double(element.getTextTrim());
}
catch (JDOMException e) {logger.error("",e);}
return value;
}
}
代码示例来源:origin: org.openfuxml/ofx-util
public OfxContentTrimmer()
{
lXpath = new ArrayList<XPath>();
try
{
Namespace nsOfx = Namespace.getNamespace("ofx", "http://www.openfuxml.org");
Namespace nsWiki = Namespace.getNamespace("wiki", "http://www.openfuxml.org/wiki");
XPath xpSections = XPath.newInstance("//ofx:paragraph");
xpSections.addNamespace(nsOfx); xpSections.addNamespace(nsWiki);
lXpath.add(xpSections);
}
catch (JDOMException e) {logger.error("",e);}
}
代码示例来源:origin: org.openfuxml/ofx-util
public OfxContainerMerger()
{
lXpath = new ArrayList<XPath>();
try
{
Namespace nsOfx = Namespace.getNamespace("ofx", "http://www.openfuxml.org");
Namespace nsWiki = Namespace.getNamespace("wiki", "http://www.openfuxml.org/wiki");
XPath xpSections = XPath.newInstance("//ofx:sections");
xpSections.addNamespace(nsOfx); xpSections.addNamespace(nsWiki);
lXpath.add(xpSections);
XPath xpSectionTransparent = XPath.newInstance("//ofx:section[@container='true']");
xpSectionTransparent.addNamespace(nsOfx); xpSectionTransparent.addNamespace(nsWiki);
lXpath.add(xpSectionTransparent);
}
catch (JDOMException e) {logger.error("",e);}
}
代码示例来源:origin: org.apache.jspwiki/jspwiki-main
XPath xp = XPath.newInstance( ALL_TEXT_NODES );
代码示例来源:origin: org.openfuxml/ofx-util
public OfxIdGenerator()
{
autoId = 1;
try
{
xpath = XPath.newInstance("//ofx:section");
xpath.addNamespace(Namespace.getNamespace("ofx", "http://www.openfuxml.org"));
xpath.addNamespace(Namespace.getNamespace("wiki", "http://www.openfuxml.org/wiki"));
// List<?> list = xpath.selectNodes(doc.getRootElement());
// logger.debug(list.size()+" hits");
}
catch (JDOMException e) {logger.error("",e);}
}
代码示例来源:origin: org.openfuxml/ofx-wiki
XPath xPath = XPath.newInstance(sbXpDataSeries.toString());
List<?> lDataSeries = xPath.selectNodes(doc);
logger.debug("xpath.DataSeries = "+lDataSeries.size());
sbXpDataSets.append("["+i+"]");
sbXpDataSets.append("/ofxchartcontainer[@type='dataset']");
xPath = XPath.newInstance(sbXpDataSets.toString());
List<?> lDataSets = xPath.selectNodes(doc);
logger.debug("xpath.lDataSets = "+lDataSets.size());
代码示例来源:origin: Renanse/Ardor3D
/**
* Compiles and return an XPath expression. Expressions are cached.
*
* @param query
* XPath query to compile
* @return new XPath expression object
*/
private XPath getXPathExpression(final String query) {
if (_dataCache.getxPathExpressions().containsKey(query)) {
return _dataCache.getxPathExpressions().get(query);
}
XPath xPathExpression = null;
try {
xPathExpression = XPath.newInstance(query);
} catch (final JDOMException e) {
e.printStackTrace();
}
_dataCache.getxPathExpressions().put(query, xPathExpression);
return xPathExpression;
}
代码示例来源:origin: org.apache.jspwiki/jspwiki-main
XPath xpath = XPath.newInstance( selector );
xpath.addNamespace( "j", J2EE_SCHEMA_25_NAMESPACE );
List<?> nodes = xpath.selectNodes( root );
xpath = XPath.newInstance( selector );
xpath.addNamespace( "j", J2EE_SCHEMA_25_NAMESPACE );
nodes = xpath.selectNodes( root );
代码示例来源:origin: org.openfuxml/ofx-wiki
public WikiTemplateCorrector()
{
nsPrefixMapper = new OfxNsPrefixMapper();
try
{
Namespace nsOfx = Namespace.getNamespace("ofx", "http://www.openfuxml.org");
Namespace nsWiki = Namespace.getNamespace("wiki", "http://www.openfuxml.org/wiki");
xpath = XPath.newInstance("//wiki:template");
xpath.addNamespace(nsOfx); xpath.addNamespace(nsWiki);
}
catch (JDOMException e) {logger.error("",e);}
}
代码示例来源:origin: org.openfuxml/ofx-wiki
public WikiExternalIntegrator(String wikiXmlDirName)
{
this.wikiXmlDirName=wikiXmlDirName;
try
{
ns = Namespace.getNamespace("ofx", "http://www.openfuxml.org");
ns = Namespace.getNamespace("wiki", "http://www.openfuxml.org/wiki");
xpath = XPath.newInstance("//wiki:content");
xpath.addNamespace(ns);
}
catch (JDOMException e) {logger.error("",e);}
xpath.addNamespace(ns);
counter = 1;
wikiQueries = new Contents();
}
代码示例来源:origin: org.apache.jspwiki/jspwiki-main
map.put( "width", img.getAttributeValue( "width" ) );
map.put( "alt", img.getAttributeValue( "alt" ) );
map.put( "caption", emptyToNull( XPath.newInstance( "CAPTION" ).valueOf( base ) ) );
map.put( "link", href );
map.put( "border", img.getAttributeValue( "border" ) );
代码示例来源:origin: org.openfuxml/ofx-util
public ExternalContentEagerLoader()
{
mrl = new MultiResourceLoader();
rpf = new RelativePathFactory(RelativePathFactory.PathSeparator.CURRENT);
try
{
xpath = XPath.newInstance("//*[@external='true']");
xpath.addNamespace(Namespace.getNamespace("ofx", "http://www.openfuxml.org"));
xpath.addNamespace(Namespace.getNamespace("wiki", "http://www.openfuxml.org/wiki"));
}
catch (JDOMException e) {logger.error("",e);}
xpFactory = XPathFactory.instance();
}
代码示例来源:origin: org.openfuxml/ofx-wiki
private org.jdom2.Document exchangeParagraphByTemplate(org.jdom2.Document doc)
{
try
{
Namespace nsOfx = Namespace.getNamespace("ofx", "http://www.openfuxml.org");
Namespace nsWiki = Namespace.getNamespace("wiki", "http://www.openfuxml.org/wiki");
XPath xpath = XPath.newInstance("//wiki:template");
xpath.addNamespace(nsOfx);
xpath.addNamespace(nsWiki);
Element result = exchangeParagraphByTemplate(doc.getRootElement(),xpath);
result.detach();
doc.setRootElement(result);
}
catch (JDOMException e) {logger.error("",e);}
return doc;
}
代码示例来源:origin: org.openfuxml/ofx-wiki
public static synchronized Template getTemplate(Templates templates, String name) throws OfxConfigurationException
{
Template result = new Template();
try
{
XPath xpath = XPath.newInstance( "//wiki:template[@name='"+name+"']" );
xpath.addNamespace(Namespace.getNamespace("ofx", "http://www.openfuxml.org"));
xpath.addNamespace(Namespace.getNamespace("wiki", "http://www.openfuxml.org/wiki"));
Document doc = JaxbUtil.toDocument(templates);
Element e = (Element)xpath.selectSingleNode(doc);
if(e!=null){result = (Template)JDomUtil.toJaxb(e, Template.class);}
else{throw new OfxConfigurationException("No template definition for templateName="+name);}
}
catch (JDOMException e) {logger.error("",e);}
return result;
}
代码示例来源:origin: Unidata/thredds
@Test
@Ignore("WMS not working")
public void checkWMSDates() throws JDOMException, IOException {
String endpoint = TestOnLocalServer.withHttpPath("/wms/cdmUnitTest/ncss/climatology/PF5_SST_Climatology_Monthly_1985_2001.nc?service=WMS&version=1.3.0&request=GetCapabilities");
byte[] result = TestOnLocalServer.getContent(endpoint, 200, ContentType.xml);
Reader in = new StringReader( new String(result, CDM.utf8Charset));
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(in);
if (show) {
XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
fmt.output(doc, System.out);
}
XPath xPath = XPath.newInstance("//wms:Dimension");
xPath.addNamespace("wms", doc.getRootElement().getNamespaceURI());
Element dimNode = (Element) xPath.selectSingleNode(doc);
//List<String> content = Arrays.asList(dimNode.getText().trim().split(","));
List<String> content = new ArrayList<>();
for (String d : Arrays.asList(dimNode.getText().trim().split(","))) {
// System.out.printf("Date= %s%n", d);
CalendarDate cd = CalendarDate.parseISOformat(null, d);
content.add(cd.toString());
}
assertEquals(expectedDatesAsDateTime, content);
}
编辑:为什么这被否决了?我真的不知道...顺便说一句 ../不起作用,因为我不想要 Table 的父级但实际上想要 ../td+1 我不知道这是否可能? 嗨,大家好。 我手头有一个相当复杂的问题..
我很难找到需要单击的输入(复选框)元素的 xpath。我正在尝试使用其他跨度元素来定位它。元素包含 Angular 属性,不知道这是否重要? 元素的结构如下: Company name
我正在尝试构建一个包含许多 XPath 作为参数的 DSL。我是 XPath 的新手,我需要一个 XPath 语法中从未使用过的字符,这样我就可以在脚本的一行中分隔 n 个 XPath。我的问题:哪些
使用xpath在父标签内找到特定标签: 输入样例:
我需要构造一个通用XPath来找到正确的节点,其中的标准是日期和时间。例如查找“ 5 May”,“ 12:17:44”的节点 XML具有日期和时间标签。 不方便地,日期标签仅在当天的第一次出现时填充。
我正在尝试获取xPath几个月内两个日期之间的差异。 几天之内我就没问题了(1127) days-from-duration(xs:date('2012-06-17')-xs:date('2009-0
我试图选择一个包含一段文本的元素,但是我不想选择包含该文本加上其他文本的元素。我通常会使用text()='abc def',但是这个特定元素在前后都包含空格。 这是一个示例片段:
亲爱的,您能帮我用这个XPATH吗?可以说我有以下HTML代码 text value1 value2 text 我需要构建一
我正在尝试提取带有排除项的 xpath,但无法执行此操作。 (//div[@class='row site country-names']/following-sibling::div)[1]/di
response.xpath('//*[@id="blah"]//text()') 假设我的html是 This is a simple text foo and this is after tag.
除了那些具有"//ul/li[not(@*)][count(*)=0]"父项的人以外,我需要全部接受。我已经尝试过,但是不幸的是它不起作用。 有谁知道,我该怎么处理? 提前致谢。 最佳答案 我认为您需
我使用XPath的问题是,每当我使用“子字符串”功能时,我只会得到一个匹配项,而我想全部获得它们。 另一个问题是,每当我使用“子字符串”和运算符的组合时它只是行不通(没有匹配项)。 例如:http:/
我正在尝试通过其位置和属性获取项目,但不知道如何做。 我要实现的是将这一点统一起来: Xpath("//h4/a[contains(@href,'#vuln_')]") 还有这个: Xpath
我有一个xpath如下: .//*[text()='Name:']/../child::select | .//*[text()='Name:']/../child::span 但是对我来说,它既不紧
我拼命试图在xpath中组合几个过滤器。假设我的数据如下所示: DELETE 1 This is my title my sh
我想在已经通过 xpath 设置的其他元素中使用 xpath 来指示元素的位置。 下面的一个已经通过 xpath 设置(我没有改变) //Base_Code
是否可以使用xpath直接在括号内抓取信息?还是以后再用正则表达式过滤? HTML如下所示: Product name (UN1QU3 C0D3) 使用以下Xpath表达式,我可以在此中获取所有内容:
我试图使用一个XPath表达式来选择一个节点,该节点的子节点与文档中的另一个节点匹配。 匹配将意味着该节点的所有属性都相同。因此,如果将一个节点与多个属性进行比较,则无法进行单独的属性比较。 作为示例
我想在 XPath 表达式中使用 Iverson 括号(即映射 true => 1,false => 0)。 示例:而不是书写 someNumber+(if(elem1/elem2[@attr='12
是否可以以类似方式选择节点? './tr[position() in (1, 3, 7)]' 我只找到以下解决方案: './tr[position() = 1 or position() = 3 or
我是一名优秀的程序员,十分优秀!