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


Java XPath类代码示例

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


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

示例1: apply

import play.libs.XPath; //导入依赖的package包/类
@Override
public List<String> apply(WSResponse response) {
	List<String> timestamps = new ArrayList<>();
	try {
		org.w3c.dom.Document xml = response.asXml();
		if (xml != null) {
			NodeList nodes = XPath.selectNodes("/wayback/results/result/capturedate", xml);
			for (int i=0; i < nodes.getLength(); i++) {
				Node node = nodes.item(i);
				if (waybackTimestamp == null || node.getTextContent().compareTo(waybackTimestamp) > 0)
					timestamps.add(node.getTextContent());
			}
		}
	} catch (Exception e) {
		Logger.error("Can't get timestamps via the Wayback API: " + e.getMessage());
	}
	return timestamps;
}
 
开发者ID:ukwa,项目名称:w3act,代码行数:19,代码来源:Crawler.java

示例2: getLocationByURL

import play.libs.XPath; //导入依赖的package包/类
/**
 * Retrieve location by URL
 * @param sURL
 * @return
 */
private static Promise<Location> getLocationByURL(String sURL){
	// Create a promise (ASYNC!)
	return WS.url(sURL).get().map(response -> {
		// Parse as XML
		Document doc = response.asXml();
		
		// use XPATH to determine required information
		Node nodeSimpleName = XPath.selectNode("/GeocodeResponse/result/address_component[type=\"locality\"]/long_name", doc);
		Node nodeAdd = XPath.selectNode("/GeocodeResponse/result/formatted_address", doc);
		Node nodeLat = XPath.selectNode("/GeocodeResponse/result/geometry/location/lat", doc);
		Node nodeLng = XPath.selectNode("/GeocodeResponse/result/geometry/location/lng", doc);
		
		// Get Content as String
		String sSimpleName = nodeSimpleName.getTextContent();
		String sAdd = nodeAdd.getTextContent();
		String sLat = nodeLat.getTextContent();
		String sLng = nodeLng.getTextContent();
		
		// Create a Location
		Location loc = new Location();
		loc.setName(sAdd);
		loc.setSimpleName(sSimpleName);
		loc.setLat(Double.parseDouble(sLat));
		loc.setLng(Double.parseDouble(sLng));
		
		logger.info(loc.getName()+" liegt in LAT "+loc.getLat()+", LNG "+loc.getLng());

		return loc;
	});
}
 
开发者ID:Localizr,项目名称:Localizr,代码行数:36,代码来源:GoogleAPI.java

示例3: observations

import play.libs.XPath; //导入依赖的package包/类
public static Result observations(final String country,
                                  final String county,
                                  final String municipality,
                                  final String place) {
    if(Strings.isNullOrEmpty(country)
            || Strings.isNullOrEmpty(county)
            || Strings.isNullOrEmpty(municipality)
            || Strings.isNullOrEmpty(place)) {
        return badRequest("Empty or illegal values provided");
    }

    final F.Promise<JsonNode> weatherObservationPromise = WS.url(String.format(YR_FORECAST_URL, country, county, municipality, place))
            .get()
            .map(new F.Function<WS.Response, JsonNode>() {
                @Override
                public JsonNode apply(WS.Response response) throws Throwable {
                    final NodeList weatherStations = XPath.selectNodes("//weatherstation", response.asXml());
                    final Node stationXmlNode = weatherStations.item(0);
                    final JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance;
                    final ObjectNode stationJsonNode = jsonNodeFactory.objectNode();
                    stationJsonNode.put("id", stationXmlNode.getAttributes().getNamedItem("stno").getNodeValue());
                    stationJsonNode.put("name", stationXmlNode.getAttributes().getNamedItem("name").getNodeValue());

                    final ObjectNode positionNode = jsonNodeFactory.objectNode();
                    positionNode.put("longitude", Float.valueOf(XPath.selectText("//weatherstation/@lon", stationXmlNode)).floatValue());
                    positionNode.put("latitude", Float.valueOf(XPath.selectText("//weatherstation/@lat", stationXmlNode)).floatValue());
                    stationJsonNode.put("position", positionNode);

                    final ObjectNode observationNode = jsonNodeFactory.objectNode();
                    observationNode.put("description", XPath.selectText("//symbol/@name", stationXmlNode));
                    observationNode.put("timestamp", XPath.selectText("//symbol/@time", stationXmlNode));
                    stationJsonNode.put("observation", observationNode);
                    final ObjectNode temperatureNode = jsonNodeFactory.objectNode();
                    final NamedNodeMap temperatureElementAttributes = XPath.selectNode("//temperature", stationXmlNode).getAttributes();

                    temperatureNode.put("value", temperatureElementAttributes.getNamedItem("value").getNodeValue());
                    temperatureNode.put("unit", temperatureElementAttributes.getNamedItem("unit").getNodeValue());
                    temperatureNode.put("timestamp", XPath.selectText("//temperature/@time", stationXmlNode));
                    stationJsonNode.put("temperature", temperatureNode);

                    return stationJsonNode;

                }
            });
    return async(weatherObservationPromise.map(new F.Function<JsonNode, Result>() {
        @Override
        public Result apply(JsonNode jsonNode) throws Throwable {
            return ok(jsonNode);
        }
    }));
}
 
开发者ID:Sonat-Consulting,项目名称:javabin-play-public,代码行数:52,代码来源:Yr.java


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