| 1 | /**
|
|---|
| 2 | *
|
|---|
| 3 | */
|
|---|
| 4 | import java.io.InputStream;
|
|---|
| 5 | import java.net.URL;
|
|---|
| 6 | import java.net.URLConnection;
|
|---|
| 7 |
|
|---|
| 8 | import javax.xml.parsers.DocumentBuilder;
|
|---|
| 9 | import javax.xml.parsers.DocumentBuilderFactory;
|
|---|
| 10 | import javax.xml.xpath.XPath;
|
|---|
| 11 | import javax.xml.xpath.XPathFactory;
|
|---|
| 12 |
|
|---|
| 13 | import org.w3c.dom.Document;
|
|---|
| 14 |
|
|---|
| 15 | /**
|
|---|
| 16 | * @author Jason Huntley
|
|---|
| 17 | *
|
|---|
| 18 | */
|
|---|
| 19 | public class TestXPath {
|
|---|
| 20 | private static String API_KEY = "Arzdiw4nlOJzRwOz__qailc8NiR31Tt51dN2D7cm57NrnceZnCpgOkmJhNpGoppU";
|
|---|
| 21 | private static String imageUrlTemplate;
|
|---|
| 22 | /**
|
|---|
| 23 | * @param args
|
|---|
| 24 | */
|
|---|
| 25 | public static void main(String[] args) {
|
|---|
| 26 | try {
|
|---|
| 27 | URL u = new URL("http://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial?include=ImageryProviders&output=xml&key="
|
|---|
| 28 | + API_KEY);
|
|---|
| 29 | URLConnection conn = u.openConnection();
|
|---|
| 30 |
|
|---|
| 31 | InputStream stream = conn.getInputStream();
|
|---|
| 32 |
|
|---|
| 33 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|---|
| 34 | DocumentBuilder builder = factory.newDocumentBuilder();
|
|---|
| 35 | Document document = builder.parse(stream);
|
|---|
| 36 |
|
|---|
| 37 | XPathFactory xPathFactory = XPathFactory.newInstance();
|
|---|
| 38 | XPath xpath = xPathFactory.newXPath();
|
|---|
| 39 | imageUrlTemplate = xpath.compile("//ImageryMetadata/ImageUrl/text()").evaluate(document);
|
|---|
| 40 | System.out.println(imageUrlTemplate);
|
|---|
| 41 | } catch(Exception e) {
|
|---|
| 42 | System.out.println(e.getMessage());
|
|---|
| 43 | e.printStackTrace();
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | }
|
|---|