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

x33g5p2x  于2022-02-03 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(149)

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

XPath.addNamespace介绍

[英]Adds a namespace definition (prefix and URI) to the list of namespaces known of this XPath expression.

Note: In XPath, there is no such thing as a 'default namespace'. The empty prefix always resolves to the empty namespace URI.
[中]将名称空间定义(前缀和URI)添加到此XPath表达式已知的名称空间列表中。
注意:在XPath中,没有“默认名称空间”这样的东西。空前缀始终解析为空命名空间URI。

代码示例

代码示例来源:origin: org.jdom/jdom

/**
 * Adds a namespace definition (prefix and URI) to the list of
 * namespaces known of this XPath expression.
 * <p>
 * <strong>Note</strong>: In XPath, there is no such thing as a
 * 'default namespace'.  The empty prefix <b>always</b> resolves
 * to the empty namespace URI.</p>
 *
 * @param  prefix   the namespace prefix.
 * @param  uri      the namespace URI.
 *
 * @throws IllegalNameException   if the prefix or uri are null or
 *                                empty strings or if they contain
 *                                illegal characters.
 */
public void addNamespace(String prefix, String uri) {
  addNamespace(Namespace.getNamespace(prefix, uri));
}

代码示例来源: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.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-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-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.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.apache.jspwiki/jspwiki-main

xpath.addNamespace( "j", J2EE_SCHEMA_25_NAMESPACE );
List<?> nodes = xpath.selectNodes( root );
for( Iterator<?> it = nodes.iterator(); it.hasNext(); )
xpath.addNamespace( "j", J2EE_SCHEMA_25_NAMESPACE );
nodes = xpath.selectNodes( root );
for( Iterator<?> it = nodes.iterator(); it.hasNext(); )

代码示例来源: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: org.apache.jspwiki/jspwiki-main

xpath.addNamespace( "j", J2EE_SCHEMA_25_NAMESPACE );
List<?> constraints = xpath.selectNodes( root );
xpath.addNamespace( "j", J2EE_SCHEMA_25_NAMESPACE );
List<?> roles = xpath.selectNodes( root );

代码示例来源: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);
}

相关文章

微信公众号

最新文章

更多