当前位置: 首页>>代码示例>>Java>>正文


Java XPathFactory.newInstance方法代码示例

本文整理汇总了Java中javax.xml.xpath.XPathFactory.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java XPathFactory.newInstance方法的具体用法?Java XPathFactory.newInstance怎么用?Java XPathFactory.newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.xpath.XPathFactory的用法示例。


在下文中一共展示了XPathFactory.newInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: XPathMetadataExtracter

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
/**
 * Default constructor
 */
public XPathMetadataExtracter()
{
    super(new HashSet<String>(Arrays.asList(SUPPORTED_MIMETYPES)));
    try
    {
        DocumentBuilderFactory normalFactory = DocumentBuilderFactory.newInstance();
        documentBuilder = normalFactory.newDocumentBuilder();
        
        DocumentBuilderFactory dtdIgnoringFactory = DocumentBuilderFactory.newInstance();
        dtdIgnoringFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        dtdIgnoringFactory.setFeature("http://xml.org/sax/features/validation", false);
        dtdIgnoringDocumentBuilder = dtdIgnoringFactory.newDocumentBuilder();
        
        xpathFactory = XPathFactory.newInstance();
    }
    catch (Throwable e)
    {
        throw new AlfrescoRuntimeException("Failed to initialize XML metadata extractor", e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:24,代码来源:XPathMetadataExtracter.java

示例2: countNodes

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
/**
 * Count nodes which are given via xpath expression
 */
public static Double countNodes(Node node, String nodePath)
        throws XPathExpressionException {
    final XPathFactory factory = XPathFactory.newInstance();
    final XPath xpath = factory.newXPath();
    final XPathExpression expr = xpath.compile("count(" + nodePath + ')');
    return (Double) expr.evaluate(node, XPathConstants.NUMBER);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:11,代码来源:XMLConverter.java

示例3: EasyTravelScenarioService

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
public EasyTravelScenarioService(RestTemplate restTemplate, EasyTravelConfigurationProperties conf) {
    this.restTemplate = restTemplate;
    this.xPathFactory = XPathFactory.newInstance();
    this.documentBuilderFactory = DocumentBuilderFactory.newInstance();

    this.apiUrl = conf.getApiUrl();
    this.availableScenarioConfigsMap = conf.getAvailableScenarios().stream().collect(Collectors.toMap(ScenarioConfigProperty::getId, sc -> sc));
    this.availableScenarioNames = conf.getAvailableScenarioNames();
}
 
开发者ID:opsgenie,项目名称:playground-scenario-generator,代码行数:10,代码来源:EasyTravelScenarioService.java

示例4: jaxpFactories

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
@DataProvider(name = "jaxpFactories")
public Object[][] jaxpFactories() throws Exception {
    return new Object[][] {
            { DocumentBuilderFactory.newInstance(), (Produce)factory -> ((DocumentBuilderFactory)factory).newDocumentBuilder() },
            { SAXParserFactory.newInstance(), (Produce)factory -> ((SAXParserFactory)factory).newSAXParser() },
            { SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI), (Produce)factory -> ((SchemaFactory)factory).newSchema() },
            { TransformerFactory.newInstance(), (Produce)factory -> ((TransformerFactory)factory).newTransformer() },
            { XMLEventFactory.newInstance(), (Produce)factory -> ((XMLEventFactory)factory).createStartDocument() },
            { XMLInputFactory.newInstance(), (Produce)factory -> ((XMLInputFactory)factory).createXMLEventReader(new StringReader("")) },
            { XMLOutputFactory.newInstance(), (Produce)factory -> ((XMLOutputFactory)factory).createXMLEventWriter(new StringWriter()) },
            { XPathFactory.newInstance(), (Produce)factory -> ((XPathFactory)factory).newXPath() },
            { DatatypeFactory.newInstance(), (Produce)factory -> ((DatatypeFactory)factory).newXMLGregorianCalendar() }
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:DefaultFactoryWrapperTest.java

示例5: createXPath

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
private XPath createXPath() throws XPathFactoryConfigurationException {
    XPathFactory xpathFactory = XPathFactory.newInstance();
    Assert.assertNotNull(xpathFactory);
    XPath xpath = xpathFactory.newXPath();
    Assert.assertNotNull(xpath);
    return xpath;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:Bug4992793.java

示例6: testClassLoader

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
@Test
public void testClassLoader() {
    MyClassLoader cl = runWithAllPerm(() -> new MyClassLoader());
    runWithAllPerm(() -> Thread.currentThread().setContextClassLoader(cl));
    XPathFactory xPathFactory = XPathFactory.newInstance();

    if (!cl.isCalled()) {
        Assert.fail("Context class loader should be used.");
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ClassLoaderTest.java

示例7: getXPathFactory

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
private static synchronized XPathFactory getXPathFactory()
{
	if( xpathFactory == null )
	{
		xpathFactory = XPathFactory.newInstance();
	}
	return xpathFactory;
}
 
开发者ID:equella,项目名称:Equella,代码行数:9,代码来源:XmlDocument.java

示例8: initializeXPath

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
private static XPath initializeXPath() {
    final Map<String, String> mappings = new HashMap<>();
    mappings.put(BRP_NAMESPACE_PREFIX.replace(":", ""), BRP_NAMESPACE_URI);
    final SimpleNamespaceContext simpleNamespaceContext = new SimpleNamespaceContext();
    simpleNamespaceContext.setBindings(mappings);
    final XPathFactory xPathFactory = XPathFactory.newInstance();
    final XPath xpath = xPathFactory.newXPath();
    xpath.setNamespaceContext(simpleNamespaceContext);
    return xpath;
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:11,代码来源:AbstractGeneriekeBerichtParser.java

示例9: transform

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
private String transform(Document document) throws Exception {
    XPathFactory xpf = XPathFactory.newInstance();
    XPath xpath = xpf.newXPath();
    XPathExpression testNameExpression = xpath.compile("//test-case/name");
    NodeList testNameNodes = (NodeList) testNameExpression.evaluate(document, XPathConstants.NODESET);
    for (int i = 0; i < testNameNodes.getLength(); i++) {
        testNameNodes.item(i).getFirstChild().setNodeValue(testNameNodes.item(i).getTextContent().replace("'", ""));
    }
 String xmlAfterTransform = Util.getXMLFile(document);
 return xmlAfterTransform;
}
 
开发者ID:Esprizzle,项目名称:allure-report-processor,代码行数:12,代码来源:AllureReportProcessor.java

示例10: AddNotificationSchemaXML

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
@SuppressWarnings("nls")
public AddNotificationSchemaXML()
{
	XPathFactory factory = XPathFactory.newInstance();
	xpath = factory.newXPath();
	try
	{
		allNodes = xpath.compile("nodes/com.tle.common.workflow.node.WorkflowItem");
	}
	catch( XPathExpressionException e )
	{
		throw new RuntimeException(e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:15,代码来源:AddNotificationSchemaXML.java

示例11: getNode

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
public Node getNode(String xPathExpression, Object item) throws XPathExpressionException{
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath = xPathFactory.newXPath();
return (Node)xPath.evaluate(xPathExpression, item, XPathConstants.NODE);
   }
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:6,代码来源:ConfigReader.java

示例12: init

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
public void init() {
	factory = XPathFactory.newInstance();
	xpath = factory.newXPath();
	expCache = new Hashtable<String, XPathExpression>();
}
 
开发者ID:DataAgg,项目名称:DaUtil,代码行数:6,代码来源:XPathEvaluator.java

示例13: LoadFromXML

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
public boolean LoadFromXML(Document doc, boolean colando) {

        HashMap<Element, FormaElementar> link = new HashMap<>();

        try {

            //<editor-fold defaultstate="collapsed" desc="Remover espaços - http://stackoverflow.com/questions/978810/how-to-strip-whitespace-only-text-nodes-from-a-dom-before-serialization">
            XPathFactory xpathFactory = XPathFactory.newInstance();
            // XPath to find empty text nodes.
            XPathExpression xpathExp = xpathFactory.newXPath().compile(
                    "//text()[normalize-space(.) = '']");
            NodeList emptyTextNodes = (NodeList) xpathExp.evaluate(doc, XPathConstants.NODESET);

            // Remove each empty text node from document.
            for (int i = 0; i < emptyTextNodes.getLength(); i++) {
                Node emptyTextNode = emptyTextNodes.item(i);
                emptyTextNode.getParentNode().removeChild(emptyTextNode);
            }
            //</editor-fold>

            NodeList nodeLst = doc.getElementsByTagName(Diagrama.nodePrincipal);
            Node mer = nodeLst.item(0);
            nodeLst = mer.getChildNodes();

            if (colando) {
                ClearSelect(true);
                ((InfoDiagrama) infoDiagrama).setDiagramaOldUniversalUnicID(String.valueOf(((Element) mer).getAttribute("UniversalUnicID")));
            }

            this.isLoadCreate = true;
            this.isCarregando = true;
            int tl = 0;
            int maxID = 0;
            for (int s = 0; s < nodeLst.getLength(); s++) {
                Node fstNode = nodeLst.item(s);
                if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element fstElmnt = (Element) fstNode;
                    FormaElementar res = runCriadorFromXml(fstElmnt, colando);
                    if (res == null) {
                        util.BrLogger.Logger("ERROR_DIAGRAMA_LOAD", "Lixo ou objeto alienígena encontrado: " + fstElmnt.toString() + " - não é possível colar este objeto", "[]");
                        continue;
                    }
                    tl++;
                    if (!colando) {
                        maxID = Math.max(maxID, res.getID());
                    }
                    link.put(fstElmnt, res);
                    maxID = OnLoadingXMLitem(res, fstElmnt, colando, maxID, link);
                }
            }
            if (!colando) {
                TotalID = maxID;
            }
            this.isLoadCreate = false;

            link.keySet().stream().forEach((el) -> {
                FormaElementar proc = link.get(el);
                proc.CommitXML(el, link);
            });
            this.isCarregando = false;

            if (colando) {
                if (((Element) mer).hasAttribute("FIRST_SEL")) {
                    ReestrutureSelecao(((Element) mer).getAttribute("FIRST_SEL"), link);
                }
            }
            if (tl > 0 && colando) {
                DoMuda(null);
            }
            PerformInspector();

        } catch (Exception e) {
            util.BrLogger.Logger("ERROR_DIAGRAMA_LOAD", e.getMessage());
            this.isLoadCreate = false;
            this.isCarregando = false;
            return false;
        }
        repaint();
        return true;
    }
 
开发者ID:chcandido,项目名称:brModelo,代码行数:81,代码来源:Diagrama.java

示例14: testNewInstance

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
/**
 * Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
 * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
 * points to correct implementation of javax.xml.xpath.XPathFactory , should
 * return newInstance of XPathFactory
 *
 * @param uri
 * @param factoryClassName
 * @param classLoader
 * @throws XPathFactoryConfigurationException
 */
@Test(dataProvider = "parameters")
public void testNewInstance(String uri, String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException {
    XPathFactory xpf = XPathFactory.newInstance(uri, factoryClassName, classLoader);
    XPath xpath = xpf.newXPath();
    assertNotNull(xpath);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:XPathFactoryTest.java

示例15: getElementByXPath

import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
public static Element getElementByXPath(Element e, String xPathExpression) throws XPathExpressionException {
   	XPathFactory factory=XPathFactory.newInstance();
       XPath xPath=factory.newXPath();
               
       return (Element)(xPath.evaluate(xPathExpression, e, XPathConstants.NODE));
       		
}
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:8,代码来源:XmlUtils.java


注:本文中的javax.xml.xpath.XPathFactory.newInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。