Created
February 25, 2011 22:11
-
-
Save seungjin/844600 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.net.*; | |
| import java.io.*; | |
| import java.io.File; | |
| import javax.xml.parsers.DocumentBuilder; | |
| import javax.xml.parsers.DocumentBuilderFactory; | |
| import org.w3c.dom.Document; | |
| import org.w3c.dom.Element; | |
| import org.w3c.dom.Node; | |
| import org.w3c.dom.NodeList; | |
| public class a { | |
| public static void main(String argv[]) { | |
| try { | |
| /* | |
| File fXmlFile = new File("/Users/seungjin/Desktop/b.xml"); | |
| DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); | |
| DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); | |
| Document doc = dBuilder.parse(fXmlFile); | |
| */ | |
| URL url = new URL("http://seungjin.commondatastorage.googleapis.com/b.xml"); | |
| InputStream is = url.openStream(); | |
| DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); | |
| DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); | |
| Document doc = dBuilder.parse(is); | |
| is.close(); | |
| doc.getDocumentElement().normalize(); | |
| NodeList nList = doc.getElementsByTagName("node"); | |
| for (int temp = 0; temp < nList.getLength(); temp++) { | |
| Node nNode = nList.item(temp); | |
| if (nNode.getNodeType() == Node.ELEMENT_NODE) { | |
| Element eElement = (Element) nNode; | |
| NodeList nlList = eElement.getElementsByTagName("Destination").item(0).getChildNodes(); | |
| Node nValue = (Node) nlList.item(0); | |
| System.out.println(nValue.getNodeValue()); | |
| } | |
| } | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment