java类javax.xml.xpath.XPath的实例源码

AbstractZoekPersoonGeneriekVerzoekParser.java 文件源码 项目:OperatieBRP 阅读 20 收藏 0 点赞 0 评论 0
/**
 * @param bevragingVerzoek bevragingVerzoek
 * @param node node
 * @param xPath xPath
 */
final void parseZoekCriteria(final T bevragingVerzoek, final Node node, final XPath xPath) {
    final String zoekcriteriumXpath = getPrefix() + "/brp:zoekcriteria/brp:zoekcriterium";
    final NodeList zoekcriteriaNodes = getNodeList(zoekcriteriumXpath, xPath, node);
    final int nodesCount = zoekcriteriaNodes.getLength();
    for (int i = 0; i < nodesCount; i++) {
        final Node zoekCriteriumNode = zoekcriteriaNodes.item(i);
        final ZoekPersoonVerzoek.ZoekCriteria zoekCriterium = new AbstractZoekPersoonVerzoek.ZoekCriteria();
        zoekCriterium.setElementNaam(getNodeTextContent("brp:elementNaam", xPath, zoekCriteriumNode));
        zoekCriterium.setWaarde(getNodeTextContent("brp:waarde", xPath, zoekCriteriumNode));
        zoekCriterium.setZoekOptie(Zoekoptie.getByNaam(getNodeTextContent("brp:optie", xPath, zoekCriteriumNode)));
        zoekCriterium.setCommunicatieId(getNodeTextContent("@brp:communicatieID", xPath, zoekCriteriumNode));
        bevragingVerzoek.getZoekCriteriaPersoon().add(zoekCriterium);
    }
}
SoapMessageManagerTest.java 文件源码 项目:verify-hub 阅读 21 收藏 0 点赞 0 评论 0
private Element getAttributeQuery(Document document) throws XPathExpressionException {
    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");
    xpath.setNamespaceContext(context);

    return (Element) xpath.evaluate("//samlp:Response", document, XPathConstants.NODE);
}
XPathAPITest.java 文件源码 项目:openjdk-jdk10 阅读 15 收藏 0 点赞 0 评论 0
@Test
public void testXPathVariableResolver() throws Exception {
    XPath xpath = getXPath();
    xpath.setXPathVariableResolver(new MyXPathVariableResolver());
    assertEquals(xpath.evaluate("//astro:stardb/astro:star[astro:hr=$id]/astro:constellation", doc.getDocumentElement()), "Peg");

}
XpathUtilsTest.java 文件源码 项目:ibm-cos-sdk-java 阅读 20 收藏 0 点赞 0 评论 0
@Test
public void testAsInteger() throws Exception {
    Document document = documentFrom(DOCUMENT);
    XPath xpath = xpath();
    assertEquals((Integer)1, (Integer)asInteger("Foo/Count", document, xpath));
    assertEquals(null, asInteger("Foo/Empty", document, xpath));
}
MetaDataMerger.java 文件源码 项目:neoscada 阅读 19 收藏 0 点赞 0 评论 0
public MetaDataMerger ( final String label, final boolean compressed ) throws Exception
{
    this.doc = createDocument ();

    final XPathFactory xpf = XPathFactory.newInstance ();
    final XPath xp = xpf.newXPath ();
    this.isCategoryPathExpression = xp.compile ( "properties/property[@name='org.eclipse.equinox.p2.type.category']/@value" );

    final ProcessingInstruction pi = this.doc.createProcessingInstruction ( "metadataRepository", "" );
    pi.setData ( "version=\"1.1.0\"" );
    this.doc.appendChild ( pi );

    this.r = this.doc.createElement ( "repository" );
    this.doc.appendChild ( this.r );
    this.r.setAttribute ( "name", label );
    this.r.setAttribute ( "type", "org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository" );
    this.r.setAttribute ( "version", "1" );

    this.p = this.doc.createElement ( "properties" );
    this.r.appendChild ( this.p );

    addProperty ( this.p, "p2.compressed", "" + compressed );
    addProperty ( this.p, "p2.timestamp", "" + System.currentTimeMillis () );

    this.u = this.doc.createElement ( "units" );
    this.r.appendChild ( this.u );
}
ResXmlPatcher.java 文件源码 项目:AndroidApktool 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Any @string reference in a <provider> value in AndroidManifest.xml will break on
 * build, thus preventing the application from installing. This is from a bug/error
 * in AOSP where public resources cannot be part of an authorities attribute within
 * a <provider> tag.
 *
 * This finds any reference and replaces it with the literal value found in the
 * res/values/strings.xml file.
 *
 * @param file File for AndroidManifest.xml
 * @throws AndrolibException
 */
public static void fixingPublicAttrsInProviderAttributes(File file) throws AndrolibException {
    if (file.exists()) {
        try {
            Document doc = loadDocument(file);
            XPath xPath = XPathFactory.newInstance().newXPath();
            XPathExpression expression = xPath.compile("/manifest/application/provider");

            Object result = expression.evaluate(doc, XPathConstants.NODESET);
            NodeList nodes = (NodeList) result;

            for (int i = 0; i < nodes.getLength(); i++) {
                Node node = nodes.item(i);
                NamedNodeMap attrs = node.getAttributes();

                if (attrs != null) {
                    Node provider = attrs.getNamedItem("android:authorities");

                    if (provider != null) {
                        String reference = provider.getNodeValue();
                        String replacement = pullValueFromStrings(file.getParentFile(), reference);

                        if (replacement != null) {
                            provider.setNodeValue(replacement);
                            saveDocument(file, doc);
                        }
                    }
                }
            }

        }  catch (SAXException | ParserConfigurationException | IOException |
                XPathExpressionException | TransformerException ignored) {
        }
    }
}
ResXmlPatcher.java 文件源码 项目:AndroidApktool 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Finds key in strings.xml file and returns text value
 *
 * @param directory Root directory of apk
 * @param key String reference (ie @string/foo)
 * @return String|null
 * @throws AndrolibException
 */
public static String pullValueFromStrings(File directory, String key) throws AndrolibException {
    if (! key.contains("@")) {
        return null;
    }

    File file = new File(directory, "/res/values/strings.xml");
    key = key.replace("@string/", "");

    if (file.exists()) {
        try {
            Document doc = loadDocument(file);
            XPath xPath = XPathFactory.newInstance().newXPath();
            XPathExpression expression = xPath.compile("/resources/string[@name=" + '"' + key + "\"]/text()");

            Object result = expression.evaluate(doc, XPathConstants.STRING);

            if (result != null) {
                return (String) result;
            }

        }  catch (SAXException | ParserConfigurationException | IOException | XPathExpressionException ignored) {
        }
    }

    return null;
}
GeefStufBerichtParser.java 文件源码 项目:OperatieBRP 阅读 16 收藏 0 点赞 0 评论 0
@Override
public void vulDienstSpecifiekeGegevens(StufBerichtVerzoek verzoek, Node node, XPath xPath) {
    final String inhoud = getXmlFragment(getPrefix() + "/brp:berichtVertaling/brp:teVertalenBericht/brp:lvg_synVerwerkPersoon", xPath, node);
    final String
            soortSynchronisatie =
            getNodeTextContent(getPrefix() + "/brp:berichtVertaling/brp:teVertalenBericht/brp:lvg_synVerwerkPersoon/brp:parameters/brp:soortSynchronisatie",
                    xPath, node);
    verzoek.setStufBericht(new StufBericht(inhoud, soortSynchronisatie));
    verzoek.setSoortDienst(SoortDienst.GEEF_STUF_BG_BERICHT);
}
XpathUtils.java 文件源码 项目:aws-sdk-java-v2 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Evaluates the specified expression on the specified node and returns the
 * result as a String.
 *
 * @param expression
 *            The Xpath expression to evaluate.
 * @param node
 *            The node on which to evaluate the expression.
 *
 * @return The result of evaluating the specified expression, or null if the
 *         evaluation didn't return any result.
 *
 * @throws XPathExpressionException
 *             If there are any problems evaluating the Xpath expression.
 */
private static String evaluateAsString(String expression, Node node,
                                       XPath xpath) throws XPathExpressionException {
    if (isEmpty(node)) {
        return null;
    }

    if (!expression.equals(".")) {
        /*
         * If the expression being evaluated doesn't select a node, we want
         * to return null to distinguish between cases where a node isn't
         * present (which should be represented as null) and when a node is
         * present, but empty (which should be represented as the empty
         * string).
         *
         * We skip this test if the expression is "." since we've already
         * checked that the node exists.
         */
        if (asNode(expression, node, xpath) == null) {
            return null;
        }
    }

    String s = xpath.evaluate(expression, node);

    return s.trim();
}
XmlUtils.java 文件源码 项目:fritz-home-skill 阅读 23 收藏 0 点赞 0 评论 0
public static Node getChildNode(Document doc, String parentTag, String childnode) {
  try {
    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression expr = xpath.compile("//" + parentTag + "/" + childnode);
    Object obj = expr.evaluate(doc, XPathConstants.NODE);
    return obj != null ? (Node) obj : null;
  } catch (Exception ex) {
    ex.printStackTrace();
  }
  return null;
}


问题


面经


文章

微信
公众号

扫码关注公众号