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


Java XPathExpression类代码示例

本文整理汇总了Java中javax.xml.xpath.XPathExpression的典型用法代码示例。如果您正苦于以下问题:Java XPathExpression类的具体用法?Java XPathExpression怎么用?Java XPathExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: compile

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
XPathExpression compile(String xPathQuery, NamespaceContext namespaceContext)
{
	try
	{
		XPath xPath = this.xPathConfigurer.getXPath(namespaceContext);
		return xPath.compile(xPathQuery);
	}
	catch (XPathExpressionException ex)
	{
		throw new FluentXmlProcessingException(ex);
	}
}
 
开发者ID:fluentxml4j,项目名称:fluentxml4j,代码行数:13,代码来源:FluentXPathContext.java

示例2: isMavenFXProject

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
public static boolean isMavenFXProject(@NonNull final Project prj) {
    if (isMavenProject(prj)) {
        try {
            FileObject pomXml = prj.getProjectDirectory().getFileObject("pom.xml"); //NOI18N
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(FileUtil.toFile(pomXml));
            XPathFactory xPathfactory = XPathFactory.newInstance();
            XPath xpath = xPathfactory.newXPath();
            XPathExpression exprJfxrt = xpath.compile("//bootclasspath[contains(text(),'jfxrt')]"); //NOI18N
            XPathExpression exprFxPackager = xpath.compile("//executable[contains(text(),'javafxpackager')]"); //NOI18N
            XPathExpression exprPackager = xpath.compile("//executable[contains(text(),'javapackager')]"); //NOI18N
            boolean jfxrt = (Boolean) exprJfxrt.evaluate(doc, XPathConstants.BOOLEAN);
            boolean packager = (Boolean) exprPackager.evaluate(doc, XPathConstants.BOOLEAN);
            boolean fxPackager = (Boolean) exprFxPackager.evaluate(doc, XPathConstants.BOOLEAN);
            return jfxrt && (packager || fxPackager);
        } catch (XPathExpressionException | ParserConfigurationException | SAXException | IOException ex) {
            LOGGER.log(Level.INFO, "Error while parsing pom.xml.", ex);  //NOI18N
            return false;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:JFXProjectUtils.java

示例3: findNodes

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
public static List<Node> findNodes ( final Node node, final String expression ) throws XPathExpressionException
{
    final XPath path = xpf.newXPath ();
    final XPathExpression expr = path.compile ( expression );
    final NodeList nodeList = (NodeList)expr.evaluate ( node, XPathConstants.NODESET );

    if ( nodeList == null )
    {
        return Collections.emptyList ();
    }

    final List<Node> result = new LinkedList<Node> ();
    for ( int i = 0; i < nodeList.getLength (); i++ )
    {
        result.add ( nodeList.item ( i ) );
    }

    return result;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:20,代码来源:XmlHelper.java

示例4: getByXpath

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
/**
 * Get values matching passed XPath expression
 * @param node
 * @param expression XPath expression
 * @return matching values
 * @throws Exception
 */
private static String[] getByXpath( Node node, String expression ) throws Exception {

    XPathFactory xPathFactory = XPathFactory.newInstance();
    XPath xPath = xPathFactory.newXPath();
    XPathExpression xPathExpression = xPath.compile(expression);

    NodeList nlist = (NodeList) xPathExpression.evaluate(node, XPathConstants.NODESET);

    int nodeListSize = nlist.getLength();
    List<String> values = new ArrayList<String>(nodeListSize);
    for (int index = 0; index < nlist.getLength(); index++) {
        Node aNode = nlist.item(index);
        values.add(aNode.getTextContent());
    }
    return values.toArray(new String[values.size()]);
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:24,代码来源:XmlUtilities.java

示例5: countNodes

import javax.xml.xpath.XPathExpression; //导入依赖的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

示例6: getExpr

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
public XPathExpression getExpr(String exp) {
	XPathExpression expr = expCache.get(exp);
	if (expr == null) {
		try {
			expr = xpath.compile(exp);
			if (expr != null) {
				expCache.put(exp, expr);
			}
			return expr;
		} catch (XPathExpressionException e) {
			LOG.error(e.getMessage(), e);
			return null;
		}
	}
	return expr;
}
 
开发者ID:DataAgg,项目名称:DAFramework,代码行数:17,代码来源:XPathEvaluator.java

示例7: getNodeList

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
public static Iterator<Node> getNodeList(String exp, Element dom) throws XPathExpressionException {
	XPath xpath = XPathFactory.newInstance().newXPath();
	XPathExpression expUserTask = xpath.compile(exp);
	final NodeList nodeList = (NodeList) expUserTask.evaluate(dom, XPathConstants.NODESET);

	return new Iterator<Node>() {
		private int index = 0;

		@Override
		public Node next() {
			return nodeList.item(index++);
		}

		@Override
		public boolean hasNext() {
			return (nodeList.getLength() - index) > 0;
		}
	};
}
 
开发者ID:DataAgg,项目名称:DAFramework,代码行数:20,代码来源:DomXmlUtils.java

示例8: buildXpath

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
private XPathExpression buildXpath(String... path) {
	StringBuilder builder = new StringBuilder();
	for (String pathSegment : path) {
		if (builder.length() > 0) {
			builder.append("/");
		}
		builder.append(pathSegment);
	}

	try {
		return XPATH.newXPath().compile(builder.toString());
	} catch (XPathExpressionException e) {
		LOGGER.error("Unable to compile xpath '{}'", builder);
		throw new RuntimeException("Unable to compile xpath");
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:17,代码来源:MavenProject.java

示例9: getAttrNames

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
private static Iterable<String> getAttrNames(InputStream is, XPathExpression expr) {
    Set<String> names = Sets.newHashSet();
    if (expr != null) {
        try {
            Document doc = parseStream(is);
            if (doc != null) {
                NodeList nodelist = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
                for (int i = 0; i < nodelist.getLength(); i++) {
                    String name = nodelist.item(i).getNodeValue();
                    names.add(name);
                }
            }
        } catch (XPathExpressionException ex) {
            LOG.log(Level.WARNING, null, ex);
        }
    }
    return names;
}
 
开发者ID:NBANDROIDTEAM,项目名称:NBANDROID-V2,代码行数:19,代码来源:ManifestParser.java

示例10: compile

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
/**
 * <p>Compile an XPath expression for later evaluation.</p>
 *
 * <p>If <code>expression</code> contains any {@link XPathFunction}s,
 * they must be available via the {@link XPathFunctionResolver}.
 * An {@link XPathExpressionException} will be thrown if the <code>XPathFunction</code>
 * cannot be resovled with the <code>XPathFunctionResolver</code>.</p>
 *
 * <p>If <code>expression</code> is <code>null</code>, a <code>NullPointerException</code> is thrown.</p>
 *
 * @param expression The XPath expression.
 *
 * @return Compiled XPath expression.

 * @throws XPathExpressionException If <code>expression</code> cannot be compiled.
 * @throws NullPointerException If <code>expression</code> is <code>null</code>.
 */
public XPathExpression compile(String expression)
    throws XPathExpressionException {
    if ( expression == null ) {
        String fmsg = XSLMessages.createXPATHMessage(
                XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
                new Object[] {"XPath expression"} );
        throw new NullPointerException ( fmsg );
    }
    try {
        com.sun.org.apache.xpath.internal.XPath xpath = new XPath (expression, null,
                prefixResolver, com.sun.org.apache.xpath.internal.XPath.SELECT );
        // Can have errorListener
        XPathExpressionImpl ximpl = new XPathExpressionImpl (xpath,
                prefixResolver, functionResolver, variableResolver,
                featureSecureProcessing, useServiceMechanism, featureManager );
        return ximpl;
    } catch ( javax.xml.transform.TransformerException te ) {
        throw new XPathExpressionException ( te ) ;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:XPathImpl.java

示例11: findFunction

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
/**
 * @param xmlString
 * @return
 * @throws Exception
 */
public static String findFunction(String xmlString) throws Exception {

    DocumentBuilder document = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Element node = document.parse(new ByteArrayInputStream(xmlString.getBytes())).getDocumentElement();

    //Xpath
    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression expr = xpath.compile("//*[local-name()='Envelope']/*[local-name()='Body']/*");

    Object result = expr.evaluate(node, XPathConstants.NODESET);
    NodeList nodes = (NodeList) result;

    if (log.isDebugEnabled()) {
        log.debug("nodes.item(0).getNodeName():" + nodes.item(0).getNodeName());
    }

    if (nodes.item(0).getNodeName().contains("query")) {
        return "query";
    } else if (nodes.item(0).getNodeName().contains("update")) {
        return "update";
    } else {
        return null;
    }
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:30,代码来源:TransformationHelper.java

示例12: getValueFromStatus

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
/**
 * Get value from status XML doc.
 *
 * @param doc         Doc to get value from
 * @param elementName Element name to search
 * @param attribute   Attribute to search
 * @return The value found
 * @throws XPathExpressionException Error in XPath expression
 */
public static String getValueFromStatus(final Document doc,
                                        final String elementName,
                                        final String attribute)
        throws XPathExpressionException {

    // Create XPath
    XPathFactory xPathFactory = XPathFactory.newInstance();
    XPath xPath = xPathFactory.newXPath();
    StringBuilder expression = new StringBuilder();

    // Build XPath from element name and attribute value (if exists)
    expression.append("//").append(elementName);
    if (attribute != null) {
        expression.append("[@name=\'").append(attribute).append("\']");
    }
    expression.append("/text()");
    XPathExpression xPathExpression = xPath.compile(expression.toString());

    // Return result from XPath expression
    return xPathExpression.evaluate(doc);
}
 
开发者ID:Alkisum,项目名称:SofaTime,代码行数:31,代码来源:Xml.java

示例13: getMaxRId

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
private int getMaxRId(ByteArrayOutputStream xmlStream) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {

		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = factory.newDocumentBuilder();
		Document doc = builder.parse(new ByteArrayInputStream(xmlStream.toByteArray()));
		XPathFactory xPathfactory = XPathFactory.newInstance();
		XPath xpath = xPathfactory.newXPath();
		XPathExpression expr = xpath.compile("Relationships/*");
		NodeList nodeList = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
		for (int i = 0; i < nodeList.getLength(); i++) {
			String id = nodeList.item(i).getAttributes().getNamedItem("Id").getTextContent();
			int idNum = Integer.parseInt(id.substring("rId".length()));
			this.maxRId = idNum > this.maxRId ? idNum : this.maxRId;
		}
		return this.maxRId;
	}
 
开发者ID:dvbern,项目名称:doctemplate,代码行数:17,代码来源:DOCXMergeEngine.java

示例14: parse

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
@Override
public void parse(Consumer<MnoInfo> consumer) throws Exception {
    File fXmlFile = config.toFile();

    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);
    doc.getDocumentElement().normalize();
    XPathExpression xpathMno = XPathFactory.newInstance().newXPath().compile("//*[local-name()='mno']");
    XPathExpression xpathMasksMno = XPathFactory.newInstance().newXPath().compile("//*[local-name()='mask']");
    NodeList mnoNodes = (NodeList) xpathMno.evaluate(doc, XPathConstants.NODESET);
    for (int i=0; i<mnoNodes.getLength(); i++) {
        Node node = mnoNodes.item(i);
        NamedNodeMap attributes = node.getAttributes();
        String country = getValue(attributes.getNamedItem("country"));
        String title = getValue(attributes.getNamedItem("title"));
        String area = getValue(attributes.getNamedItem("area"));
        Set<Mask> masks = new HashSet<>();
        NodeList maskNodes = (NodeList) xpathMasksMno.evaluate(doc, XPathConstants.NODESET);
        for (int j=0; j<maskNodes.getLength(); j++) {
            masks.add(Mask.parse(getValue(maskNodes.item(j))));
        }
        consumer.accept(new MnoInfo(title, area, country, masks));
    }
}
 
开发者ID:chukanov,项目名称:mnp,代码行数:26,代码来源:CustomMasksParser.java

示例15: detectEntityIds

import javax.xml.xpath.XPathExpression; //导入依赖的package包/类
private List<String> detectEntityIds(Document metsDoc, EntityType entityType) throws InvalidXPathExpressionException, XPathExpressionException {
    XPathExpression xPathExpression = engine.buildXpath("/mets:mets/mets:dmdSec[contains(@ID, \"" + entityType.getDmdSecCode() + "\")]/@ID");
    NodeList idAttrs = (NodeList) xPathExpression.evaluate(metsDoc, XPathConstants.NODESET);
    Set<String> set = new HashSet<>(idAttrs.getLength());
    for (int i = 0; i < idAttrs.getLength(); i++) {
        Attr attr = (Attr) idAttrs.item(i);
        String id = attr.getValue();
        if (id.startsWith("MODSMD_")) {
            id = id.substring("MODSMD_".length());
        } else if (id.startsWith("DCMD_")) {
            id = id.substring("DCMD_".length());
        }
        String typePrefix = entityType.getDmdSecCode() + '_';
        id = id.substring(typePrefix.length());
        set.add(id);
    }
    return new ArrayList<>(set);
}
 
开发者ID:NLCR,项目名称:komplexni-validator,代码行数:19,代码来源:VfCheckBibliographicMetadataMatchProfile.java


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