gpt4 book ai didi

org.jdom2.xpath.XPath.newInstance()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-25 04:43:05 25 4
gpt4 key购买 nike

本文整理了Java中org.jdom2.xpath.XPath.newInstance()方法的一些代码示例,展示了XPath.newInstance()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XPath.newInstance()方法的具体详情如下:
包路径:org.jdom2.xpath.XPath
类名称:XPath
方法名:newInstance

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);
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com