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


Java XPath类代码示例

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


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

示例1: unmarshall

import javax.xml.xpath.XPath; //导入依赖的package包/类
@Override
public SdkServiceException unmarshall(Node in) throws Exception {

    XPath xpath = xpath();

    String error = asString("Error/Code", in, xpath);
    String requestId = asString("Error/RequestId", in, xpath);
    String message = asString("Error/Message", in, xpath);

    if (!StringUtils.equals(error, this.errorCode)) {
        return null;
    }

    SdkServiceException exception = newException(message);
    exception.errorCode(errorCode);
    exception.requestId(requestId);

    return exception;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:20,代码来源:S3ExceptionUnmarshaller.java

示例2: testAddRoots

import javax.xml.xpath.XPath; //导入依赖的package包/类
public void testAddRoots() throws Exception {
    NbModuleProject prj = TestBase.generateStandaloneModule(getWorkDir(), "module");
    FileObject src = prj.getSourceDirectory();
    FileObject jar = TestFileUtils.writeZipFile(FileUtil.toFileObject(getWorkDir()), "a.jar", "entry:contents");
    URL root = FileUtil.getArchiveRoot(jar.toURL());
    assertTrue(ProjectClassPathModifier.addRoots(new URL[] {root}, src, ClassPath.COMPILE));
    assertFalse(ProjectClassPathModifier.addRoots(new URL[] {root}, src, ClassPath.COMPILE));
    FileObject releaseModulesExt = prj.getProjectDirectory().getFileObject("release/modules/ext");
    assertNotNull(releaseModulesExt);
    assertNotNull(releaseModulesExt.getFileObject("a.jar"));
    jar = TestFileUtils.writeZipFile(releaseModulesExt, "b.jar", "entry2:contents");
    root = FileUtil.getArchiveRoot(jar.toURL());
    assertTrue(ProjectClassPathModifier.addRoots(new URL[] {root}, src, ClassPath.COMPILE));
    assertFalse(ProjectClassPathModifier.addRoots(new URL[] {root}, src, ClassPath.COMPILE));
    assertEquals(2, releaseModulesExt.getChildren().length);
    String projectXml = prj.getProjectDirectory().getFileObject("nbproject/project.xml").toURL().toString();
    InputSource input = new InputSource(projectXml);
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(nbmNamespaceContext());
    assertEquals(projectXml, "ext/a.jar", xpath.evaluate("//nbm:class-path-extension[1]/nbm:runtime-relative-path", input));
    assertEquals(projectXml, "release/modules/ext/a.jar", xpath.evaluate("//nbm:class-path-extension[1]/nbm:binary-origin", input));
    assertEquals(projectXml, "ext/b.jar", xpath.evaluate("//nbm:class-path-extension[2]/nbm:runtime-relative-path", input));
    assertEquals(projectXml, "release/modules/ext/b.jar", xpath.evaluate("//nbm:class-path-extension[2]/nbm:binary-origin", input));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ModuleProjectClassPathExtenderTest.java

示例3: unmarshall

import javax.xml.xpath.XPath; //导入依赖的package包/类
@Override
public SdkServiceException unmarshall(Node in) throws Exception {
    XPath xpath = XpathUtils.xpath();
    String errorCode = parseErrorCode(in, xpath);
    String message = XpathUtils.asString("Response/Errors/Error/Message", in, xpath);
    String requestId = XpathUtils.asString("Response/RequestID", in, xpath);
    String errorType = XpathUtils.asString("Response/Errors/Error/Type", in, xpath);

    SdkServiceException exception = newException(message);
    exception.errorCode(errorCode);
    exception.requestId(requestId);

    if ("Client".equalsIgnoreCase(errorType)) {
        exception.errorType(ErrorType.CLIENT);
    } else if ("Server".equalsIgnoreCase(errorType)) {
        exception.errorType(ErrorType.SERVICE);
    } else {
        exception.errorType(ErrorType.fromValue(errorType));
    }

    return exception;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:23,代码来源:LegacyErrorUnmarshaller.java

示例4: vulStuurgegevens

import javax.xml.xpath.XPath; //导入依赖的package包/类
@Override
public final void vulStuurgegevens(final T verzoek, final Node node, final XPath xPath) throws ParseException {
    verzoek.getStuurgegevens().setCommunicatieId(
            getNodeTextContent(getPrefix() + "/brp:stuurgegevens/@brp:communicatieID", xPath, node));
    verzoek.getStuurgegevens()
            .setZendendePartijCode(getNodeTextContent(getPrefix() + "/brp:stuurgegevens/brp:zendendePartij", xPath, node));
    verzoek.getStuurgegevens().setZendendSysteem(
            getNodeTextContent(getPrefix() + "/brp:stuurgegevens/brp:zendendeSysteem", xPath, node));
    verzoek.getStuurgegevens()
            .setReferentieNummer(getNodeTextContent(getPrefix() + "/brp:stuurgegevens/brp:referentienummer", xPath, node));
    final String tijdstipVerzendingString = getNodeTextContent(getPrefix() + "/brp:stuurgegevens/brp:tijdstipVerzending", xPath, node);
    if (tijdstipVerzendingString != null) {
        final ZonedDateTime tijdstipVerzending = DatumUtil.vanXsdDatumTijdNaarZonedDateTime(tijdstipVerzendingString);
        verzoek.getStuurgegevens().setTijdstipVerzending(tijdstipVerzending);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:17,代码来源:AbstractDienstVerzoekParser.java

示例5: unwrapSoapMessage

import javax.xml.xpath.XPath; //导入依赖的package包/类
public Element unwrapSoapMessage(Element soapElement) {
    XPath xpath = XPathFactory.newInstance().newXPath();
    NamespaceContextImpl context = new NamespaceContextImpl();
    context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
    context.startPrefixMapping("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
    context.startPrefixMapping("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
    context.startPrefixMapping("ds", "http://www.w3.org/2000/09/xmldsig#");
    xpath.setNamespaceContext(context);
    try {
        final String expression = "/soapenv:Envelope/soapenv:Body/samlp:Response";
        Element element = (Element) xpath.evaluate(expression, soapElement, XPathConstants.NODE);

        if (element == null) {
            String errorMessage = format("Document{0}{1}{0}does not have element {2} inside it.", NEW_LINE,
                    writeToString(soapElement), expression);
            LOG.error(errorMessage);
            throw new IllegalArgumentException(errorMessage);
        }

        return element;
    } catch (XPathExpressionException e) {
        throw propagate(e);
    }
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:25,代码来源:SoapMessageManager.java

示例6: findElementValue

import javax.xml.xpath.XPath; //导入依赖的package包/类
/**
 * Find the element reference for the selected element. The selected element
 * is an XPATH expression relation to the element reference given as a
 * parameter.
 *
 * @param pev the element reference from which the XPATH expression is
 * evaluated.
 * @param path the XPATH expression
 * @return the resulting element reference
 */
public final ElementValue findElementValue(ElementValue pev, String path) {
    XPath xpath = XPathFactory.newInstance().newXPath();
    try {
        Element el = (Element) xpath.evaluate(path, pev.getElement(), XPathConstants.NODE);
        return pev.isInHerited()
                ? (el == null
                        ? new ElementValue(Type.INHERITED_MISSING)
                        : new ElementValue(el, Type.INHERITED))
                : (el == null
                        ? new ElementValue(pev, path)
                        : new ElementValue(el, Type.OK));
    } catch (XPathExpressionException ex) {
        return new ElementValue(pev, path);
    }
}
 
开发者ID:The-Retired-Programmer,项目名称:nbreleaseplugin,代码行数:26,代码来源:Pom.java

示例7: countColumns

import javax.xml.xpath.XPath; //导入依赖的package包/类
protected static void countColumns(XPath xPath, Table table, Node tableHead)
		throws XPathExpressionException, DOMException, NumberFormatException {
	if (tableHead != null) {
		Node firstRow = (Node) xPath.compile("*[1]").evaluate(tableHead, XPathConstants.NODE);
		NodeList childFirstRows = firstRow.getChildNodes();
		int columnNumber = 0;
		for (int w = 0; w < childFirstRows.getLength(); w++) {
			Node childFirstRow = childFirstRows.item(w);
			if (childFirstRow.getNodeValue() == null && (childFirstRow.getNodeName() == "th" || childFirstRow.getNodeName() == "td")) {
				int number = 1;
				if (childFirstRow.getAttributes().getNamedItem("colspan") != null) {
					number = Integer.parseInt(childFirstRow.getAttributes().getNamedItem("colspan").getNodeValue());
				} 
				columnNumber = columnNumber + number;
			}
		}
		table.setColumnNumber(columnNumber);
	}
}
 
开发者ID:Vitaliy-1,项目名称:JATS2LaTeX,代码行数:20,代码来源:TableFunctions.java

示例8: eval

import javax.xml.xpath.XPath; //导入依赖的package包/类
public boolean eval() throws BuildException {
    if (nullOrEmpty(fileName)) {
        throw new BuildException("No file set");
    }
    File file = new File(fileName);
    if (!file.exists() || file.isDirectory()) {
        throw new BuildException(
                "The specified file does not exist or is a directory");
    }
    if (nullOrEmpty(path)) {
        throw new BuildException("No XPath expression set");
    }
    XPath xpath = XPathFactory.newInstance().newXPath();
    InputSource inputSource = new InputSource(fileName);
    Boolean result = Boolean.FALSE;
    try {
        result = (Boolean) xpath.evaluate(path, inputSource,
                XPathConstants.BOOLEAN);
    } catch (XPathExpressionException e) {
        throw new BuildException("XPath expression fails", e);
    }
    return result.booleanValue();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:24,代码来源:XPathCondition.java

示例9: getNodeList

import javax.xml.xpath.XPath; //导入依赖的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,项目名称:DaUtil,代码行数:20,代码来源:DomXmlUtils.java

示例10: performFileExistenceChecks

import javax.xml.xpath.XPath; //导入依赖的package包/类
/**
 * Performs all file existence checks contained in the validation profile. If the validation has failed (some of the files specified
 * in the validation profile do not exist), {@link MissingFile} exception is thrown.
 *
 * @param sipPath path to the SIP
 * @param validationProfileDoc document with the validation profile
 * @param validationProfileId id of the validation profile
 * @throws XPathExpressionException if there is an error in the XPath expression
 */
private void performFileExistenceChecks(String sipPath, Document validationProfileDoc, String validationProfileId) throws
        XPathExpressionException {
    XPath xPath =  XPathFactory.newInstance().newXPath();

    NodeList nodes = (NodeList) xPath.compile("/profile/rule/fileExistenceCheck")
            .evaluate(validationProfileDoc, XPathConstants.NODESET);
    for (int i = 0; i< nodes.getLength(); i++) {

        Element element = (Element) nodes.item(i);
        String relativePath = element.getElementsByTagName("filePath").item(0).getTextContent();
        String absolutePath = sipPath + relativePath;
        if (!ValidationChecker.fileExists(absolutePath)) {
            log.info("Validation of SIP with profile " + validationProfileId + " failed. File at \"" + relativePath + "\" is missing.");
            throw new MissingFile(relativePath, validationProfileId);
        }
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:27,代码来源:ValidationService.java

示例11: performValidationSchemaChecks

import javax.xml.xpath.XPath; //导入依赖的package包/类
/**
 * Performs all validation schema checks contained in the validation profile. If the validation has failed (some of the XMLs
 * specified in the validation profile do not match their respective validation schemas) {@link SchemaValidationError} is thrown.
 *
 * @param sipPath path to the SIP
 * @param validationProfileDoc document with the validation profile
 * @param validationProfileId id of the validation profile
 * @throws IOException if some of the XMLs address from the validation profile does not exist
 * @throws XPathExpressionException if there is an error in the XPath expression
 * @throws SAXException if the XSD schema is invalid
 */
private void performValidationSchemaChecks(String sipPath, Document validationProfileDoc, String validationProfileId) throws
        XPathExpressionException, IOException, SAXException {
    XPath xPath =  XPathFactory.newInstance().newXPath();

    NodeList nodes = (NodeList) xPath.compile("/profile/rule/validationSchemaCheck")
            .evaluate(validationProfileDoc,
                    XPathConstants.NODESET);
    for (int i = 0; i< nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        String filePath = element.getElementsByTagName("filePath").item(0).getTextContent();
        String schema = element.getElementsByTagName("schema").item(0).getTextContent();

        String absoluteFilePath = sipPath + filePath;

        try {
            ValidationChecker.validateWithXMLSchema(new FileInputStream(absoluteFilePath), new InputStream[] {
                    new ByteArrayInputStream(schema.getBytes(StandardCharsets.UTF_8.name()))});
        } catch (GeneralException e) {
            log.info("Validation of SIP with profile " + validationProfileId + " failed. File at \"" + filePath + "\" is not " +
                    "valid against its corresponding schema.");
            throw new SchemaValidationError(filePath, schema, e.getMessage());
        }
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:36,代码来源:ValidationService.java

示例12: getValueFromStatus

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

import javax.xml.xpath.XPath; //导入依赖的package包/类
/**
 * Searches XML element with XPath and returns list of nodes found
 *
 * @param xml        input stream with the XML in which the element is being searched
 * @param expression XPath expression used in search
 * @return {@link NodeList} of elements matching the XPath in the XML
 * @throws XPathExpressionException     if there is an error in the XPath expression
 * @throws IOException                  if the XML at the specified path is missing
 * @throws SAXException                 if the XML cannot be parsed
 * @throws ParserConfigurationException
 */
public static NodeList findWithXPath(InputStream xml, String expression)
        throws IOException, SAXException, ParserConfigurationException {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder;

    dBuilder = dbFactory.newDocumentBuilder();

    Document doc = dBuilder.parse(xml);
    doc.getDocumentElement().normalize();

    XPath xPath = XPathFactory.newInstance().newXPath();

    try {
        return (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET);
    } catch (XPathExpressionException e) {
        throw new InvalidXPathException(expression, e);
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:30,代码来源:XPathUtils.java

示例14: getStringValue

import javax.xml.xpath.XPath; //导入依赖的package包/类
private static String getStringValue(@NonNull IAbstractFile file, @NonNull String xPath)
        throws StreamException, XPathExpressionException {
    XPath xpath = AndroidXPathFactory.newXPath();

    InputStream is = null;
    try {
        is = file.getContents();
        return xpath.evaluate(xPath, new InputSource(is));
    } finally {
        try {
            Closeables.close(is, true /* swallowIOException */);
        } catch (IOException e) {
            // cannot happen
        }
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:17,代码来源:AndroidManifest.java

示例15: getAfnemerIndicatie

import javax.xml.xpath.XPath; //导入依赖的package包/类
private Afnemerindicatie getAfnemerIndicatie(final XPath xPath, final Node node) {
    final Afnemerindicatie afnemerindicatie = new Afnemerindicatie();
    afnemerindicatie
            .setBsn(getNodeTextContent(getActieSpecifiekePrefix() + "/brp:persoon/brp:identificatienummers/brp:burgerservicenummer", xPath, node));
    afnemerindicatie.setPartijCode(
            getNodeTextContent(getActieSpecifiekePrefix() + "/brp:persoon/brp:afnemerindicaties/brp:afnemerindicatie/brp:partijCode", xPath, node));
    final String datumAanvangMaterielePeriode =
            getNodeTextContent(
                    getActieSpecifiekePrefix() + "/brp:persoon/brp:afnemerindicaties/brp:afnemerindicatie/brp:datumAanvangMaterielePeriode", xPath, node);
    if (datumAanvangMaterielePeriode != null) {
        afnemerindicatie
                .setDatumAanvangMaterielePeriode(datumAanvangMaterielePeriode);
    }
    final String datumEindeVolgen = getNodeTextContent(
            getActieSpecifiekePrefix() + "/brp:persoon/brp:afnemerindicaties/brp:afnemerindicatie/brp:datumEindeVolgen", xPath, node);
    if (datumEindeVolgen != null) {
        afnemerindicatie.setDatumEindeVolgen(datumEindeVolgen);
    }
    return afnemerindicatie;
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:21,代码来源:AbstractAfnemerindicatieVerzoekParser.java


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