當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。