Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.xml.parsers.*;
- import org.w3c.dom.*;
- public class Test
- {
- public static void main(String[] args) throws Exception{
- // IOMethods.convertToXML();
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- // Document doc = builder.parse("temp.xml");
- Document doc = builder.parse("http://www.pogodynka.net/api:server/weather/getCurrent.xml?city=Warszawa");
- Element root = doc.getDocumentElement();
- // NamedNodeMap
- NodeList children = root.getChildNodes();
- for (int i= 0; i < children.getLength(); i++)
- {
- Node child = children.item(i);
- if (child instanceof Element)
- {
- Element childElement = (Element)child;
- Text textNode = (Text) childElement.getFirstChild();
- String text = textNode.getData().trim();
- System.out.println(childElement.getNodeName() + ": " + text);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment