List of usage examples for javax.xml.xpath XPathConstants STRING
QName STRING
To view the source code for javax.xml.xpath XPathConstants STRING.
Click Source Link
The XPath 1.0 string data type.
Maps to Java String .
From source file:net.ymate.framework.commons.XPathHelper.java
public String getStringValue(String expression) throws XPathExpressionException { return (String) __doEvaluate(expression, null, XPathConstants.STRING); }
From source file:net.ymate.framework.commons.XPathHelper.java
public String getStringValue(Object item, String expression) throws XPathExpressionException { return (String) __doEvaluate(expression, item, XPathConstants.STRING); }
From source file:nl.b3p.viewer.admin.stripes.ServiceUsageMatrixActionBean.java
public static XSSFWorkbook createWorkBook(String theXml) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException, XPathFactoryConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new InputSource(new StringReader(theXml))); XSSFWorkbook workbook = new XSSFWorkbook(); String tempProperty = null;/* www.j a v a2 s. c om*/ try { Element root = doc.getDocumentElement(); /* JSTL XML is setting the system property to use the jstl xpath facotry. * Remove the setting temporary: * see: https://java.net/jira/browse/JSTL-1 */ tempProperty = System .getProperty(XPathFactory.DEFAULT_PROPERTY_NAME + ":" + XPathFactory.DEFAULT_OBJECT_MODEL_URI); if (tempProperty != null) { System.clearProperty( XPathFactory.DEFAULT_PROPERTY_NAME + ":" + XPathFactory.DEFAULT_OBJECT_MODEL_URI); } XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); XPathExpression exprFeatureSource = xpath.compile("//featureSource"); XPathExpression exprFeatureType = xpath.compile("featureType"); XPathExpression exprApplication = xpath.compile("applications/application"); XPathExpression exprLayer = xpath.compile("layers/layer"); XPathExpression exprAppLayer = xpath.compile("applayers/applayer"); XPathExpression exprId = xpath.compile("id/text()"); XPathExpression exprAlias = xpath.compile("alias/text()"); XPathExpression exprName = xpath.compile("name/text()"); XPathExpression exprVersion = xpath.compile("version/text()"); XPathExpression exprProtocol = xpath.compile("protocol/text()"); XPathExpression exprUrl = xpath.compile("url/text()"); XSSFSheet sheet = workbook.createSheet("Sheet 1"); int rowNum = 0; Row head = sheet.createRow(rowNum++); String[] headValues = { "Bron", "Featuretype", "Applicatie", "Layernaam van service", "Application layer (kaart)" }; for (int c = 0; c < headValues.length; c++) { Cell cell = head.createCell(c); cell.setCellValue(headValues[c]); } List<String> columns = new ArrayList<String>(); for (int i = 0; i < headValues.length; i++) { columns.add(""); } NodeList featureSources = (NodeList) exprFeatureSource.evaluate(root, XPathConstants.NODESET); for (int fs = 0; fs < featureSources.getLength(); fs++) { Node featureSource = featureSources.item(fs); String fsString = (String) exprName.evaluate(featureSource, XPathConstants.STRING); fsString += " (" + (String) exprProtocol.evaluate(featureSource, XPathConstants.STRING); fsString += ":: " + (String) exprUrl.evaluate(featureSource, XPathConstants.STRING); fsString += " id: " + (String) exprId.evaluate(featureSource, XPathConstants.STRING); fsString += ")"; columns.set(0, fsString); NodeList featureTypes = (NodeList) exprFeatureType.evaluate(featureSource, XPathConstants.NODESET); for (int ft = 0; ft < featureTypes.getLength(); ft++) { Node featureType = featureTypes.item(ft); //String ftId = (String) exprId.evaluate(featureType,XPathConstants.STRING); String ftName = (String) exprName.evaluate(featureType, XPathConstants.STRING); //String ftString = ""+ftName; columns.set(1, ftName); NodeList applications = (NodeList) exprApplication.evaluate(featureType, XPathConstants.NODESET); for (int app = 0; app < applications.getLength(); app++) { Node application = applications.item(app); String appVersion = (String) exprVersion.evaluate(application, XPathConstants.STRING); String appString = (String) exprName.evaluate(application, XPathConstants.STRING); if (appVersion != null) { appString += ", version: " + appVersion; } appString += " (" + (String) exprId.evaluate(application, XPathConstants.STRING) + ")"; columns.set(2, appString); NodeList layers = (NodeList) exprLayer.evaluate(application, XPathConstants.NODESET); for (int lay = 0; lay < layers.getLength(); lay++) { Node layer = layers.item(lay); String layerString = ""; layerString += (String) exprName.evaluate(layer, XPathConstants.STRING); columns.set(3, layerString); NodeList appLayers = (NodeList) exprAppLayer.evaluate(layer, XPathConstants.NODESET); for (int al = 0; al < appLayers.getLength(); al++) { Node appLayer = appLayers.item(al); String alString = (String) exprAlias.evaluate(appLayer, XPathConstants.STRING); alString += " (" + (String) exprId.evaluate(appLayer, XPathConstants.STRING) + ")"; columns.set(4, alString); Row row = sheet.createRow(rowNum++); for (int c = 0; c < columns.size(); c++) { Cell cell = row.createCell(c); cell.setCellValue(columns.get(c)); } } } } } } } finally { if (tempProperty != null) { System.setProperty(XPathFactory.DEFAULT_PROPERTY_NAME + ":" + XPathFactory.DEFAULT_OBJECT_MODEL_URI, tempProperty); } } return workbook; }
From source file:nl.imvertor.common.file.XmlFile.java
/** * Benader de inhoud dmv. een Xpath expressie. Geef het laatste item die aan het criterium voldoet af als String. * /*from ww w . j a v a2 s . co m*/ * @param outfile * @param xslFilePath * @throws Exception */ public String xpath(String expression, HashMap<String, String> parms) throws Exception { return (String) xpathToObject(expression, parms, XPathConstants.STRING); }
From source file:nl.nn.adapterframework.util.XmlUtils.java
public static Collection<String> evaluateXPathNodeSet(String input, String xpathExpr, String xpathExpr2) throws DomBuilderException, XPathExpressionException { String msg = XmlUtils.removeNamespaces(input); Collection<String> c = new LinkedList<String>(); Document doc = buildDomDocument(msg, true, true); XPath xPath = XPathFactory.newInstance().newXPath(); XPathExpression xPathExpression = xPath.compile(xpathExpr); Object result = xPathExpression.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; XPathExpression xPathExpression2 = xPath.compile(xpathExpr2); Object result2 = xPathExpression2.evaluate(element, XPathConstants.STRING); c.add((String) result2); }/* ww w .j a v a 2 s. c om*/ } if (c != null && c.size() > 0) { return c; } return null; }
From source file:nz.co.testamation.core.matcher.HasXPathMatcher.java
public boolean matchesSafely(Node item) { String xPathResult;// w ww .j a va 2 s.c o m boolean matched; try { if (hasMatchers()) { xPathResult = (String) compiledXPath.evaluate(item, XPathConstants.STRING); matched = getMatcher().matches(xPathResult); } else { matched = (Boolean) compiledXPath.evaluate(item, XPathConstants.BOOLEAN); xPathResult = Boolean.toString(matched); } } catch (XPathExpressionException e) { xPathResult = "Failed to execute xpath: " + xpathString; matched = false; } if (!matched) { String matcherDescription = null; if (getMatcher() != null) { Description description = new StringDescription(); getMatcher().describeTo(description); matcherDescription = description.toString(); } logger.info(String.format("XPath failed: %s%s", xpathString, matcherDescription != null ? ", actual: '" + xPathResult + "', expected: " + matcherDescription : "")); } return matched; }
From source file:nz.govt.natlib.adapter.arc.ArcAdapter.java
private ArcMetadata parseArcMetadataRecord(ArcVersionBlock arcMetadataRecord) { if (arcMetadataRecord == null) return null; ArcMetadata metadata = new ArcMetadata(); ByteArrayOutputStream bos = null; try {//w w w . j av a2 s . c o m Document doc = createXmlDocumentFrom(arcMetadataRecord.getPayloadContent()); XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xpath = xPathFactory.newXPath(); xpath.setNamespaceContext(new ArcMetadataNamespaceContext()); metadata.software = (String) xpath.evaluate("//arc:arcmetadata/arc:software", doc, XPathConstants.STRING); metadata.hostname = (String) xpath.evaluate("//arc:arcmetadata/arc:hostname", doc, XPathConstants.STRING); metadata.ip = (String) xpath.evaluate("//arc:arcmetadata/arc:ip", doc, XPathConstants.STRING); metadata.operator = (String) xpath.evaluate("//arc:arcmetadata/arc:operator", doc, XPathConstants.STRING); metadata.createdDate = (String) xpath.evaluate("//arc:arcmetadata/dc:date", doc, XPathConstants.STRING); metadata.robotPolicy = (String) xpath.evaluate("//arc:arcmetadata/arc:robots", doc, XPathConstants.STRING); metadata.arcFormat = (String) xpath.evaluate("//arc:arcmetadata/dc:format", doc, XPathConstants.STRING); metadata.conformsTo = (String) xpath.evaluate("//arc:arcmetadata/dcterms:conformsTo", doc, XPathConstants.STRING); return metadata; } catch (Exception e) { } finally { if (bos != null) { try { bos.close(); } catch (IOException e) { } } } return null; }
From source file:nz.govt.natlib.ndha.wctdpsdepositor.extractor.XPathWctMetsExtractor.java
private void popualteHarvestDate(Document doc, XPath xpath) throws XPathExpressionException { harvestDate = (String) xpath.evaluate(harvestDateQuery, doc, XPathConstants.STRING); }
From source file:nz.govt.natlib.ndha.wctdpsdepositor.extractor.XPathWctMetsExtractor.java
private void populateTargetName(Document doc, XPath xpath) throws XPathExpressionException { targetName = (String) xpath.evaluate(targetNameQuery, doc, XPathConstants.STRING); }
From source file:nz.govt.natlib.ndha.wctdpsdepositor.extractor.XPathWctMetsExtractor.java
private void populateCreatedBy(Document doc, XPath xpath) throws XPathExpressionException { createdBy = (String) xpath.evaluate(createdByQuery, doc, XPathConstants.STRING); }