Grab HeadLines

import org.apache.xerces.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import java.io.*;


public class HeadlineGrabber  {

  public static void main(String[] args) {
     
    DOMParser parser = new DOMParser();
    
    try {
      // Read the entire document into memory
      parser.parse("http://static.userland.com/myUserLandMisc/currentStories.xml"); 
     
      Document d = parser.getDocument();
      NodeList headlines = d.getElementsByTagName("storyText");
      for (int i = 0; i < headlines.getLength(); i++) {
        NodeList storyText = headlines.item(i).getChildNodes();
        for (int j = 0; j < storyText.getLength(); j++) {
          Node textContent = storyText.item(j);
          System.out.print(textContent.getNodeValue());
        }
        System.out.println();
        System.out.println();
        System.out.flush();
      }
    }
    catch (SAXException e) {
      System.err.println(e); 
    }
    catch (IOException e) {
      System.err.println(e); 
    }
  
  } // end main

}
View Output in Browser
Previous | Next | Top | Cafe con Leche

Copyright 2000 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified March 16, 2000