[jdom-interest] org.jdom.JDOMException

TAZ0789 at aol.com TAZ0789 at aol.com
Tue Jul 23 22:12:58 PDT 2002


Hi all,

   I'm new to xml and jdom.  I wrote a simple program that reads a simple xml 
file.  The java file compiles ok, but when I run it, it gives me the 
following error, following by the java source.  Please help.  Thanks.

D:\sjsu\cs296>java WeblogsJDOM weblog.xml
org.jdom.JDOMException: Error in building: msdn.microsoft.com
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:373)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:772)
        at WeblogsJDOM.listChannels(WeblogsJDOM.java:25)
        at WeblogsJDOM.main(WeblogsJDOM.java:62)
Caused by: java.net.UnknownHostException: msdn.microsoft.com
        at java.net.InetAddress.getAllByName0(InetAddress.java:571)
        at java.net.InetAddress.getAllByName0(InetAddress.java:540)
        at java.net.InetAddress.getByName(InetAddress.java:449)
        at java.net.Socket.<init>(Socket.java:100)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:50)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:331)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:517)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:277)
        at sun.net.www.http.HttpClient.New(HttpClient.java:289)
        at 
sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection
.java:408)
        at 
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:501)
        at java.net.URL.openStream(URL.java:798)
        at 
org.apache.xerces.readers.DefaultReaderFactory.createReader(DefaultRe
aderFactory.java:149)
        at 
org.apache.xerces.readers.DefaultEntityHandler.startReadingFromExtern
alEntity(DefaultEntityHandler.java:772)
        at 
org.apache.xerces.readers.DefaultEntityHandler.startReadingFromExtern
alSubset(DefaultEntityHandler.java:571)
        at 
org.apache.xerces.framework.XMLDTDScanner.scanDoctypeDecl(XMLDTDScann
er.java:1139)
        at 
org.apache.xerces.framework.XMLDocumentScanner.scanDoctypeDecl(XMLDoc
umentScanner.java:2145)
        at 
org.apache.xerces.framework.XMLDocumentScanner.access$0(XMLDocumentSc
anner.java:2100)
        at 
org.apache.xerces.framework.XMLDocumentScanner$PrologDispatcher.dispa
tch(XMLDocumentScanner.java:831)
        at 
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentS
canner.java:381)
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:772)
        at WeblogsJDOM.listChannels(WeblogsJDOM.java:25)
        at WeblogsJDOM.main(WeblogsJDOM.java:62)


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import org.jdom.*;
import org.jdom.input.SAXBuilder;
import java.util.*;
import java.net.*;

public class WeblogsJDOM
{
   public static String DEFAULT_SYSTEM_ID = "d:\\sjsu\\cs296\\weblog.txt";
   
   public static List listChannels() throws JDOMException
   {
      return listChannels(DEFAULT_SYSTEM_ID);
   }
   
   public static List listChannels(String systemID) throws JDOMException, 
NullPointerException
   {
      if(systemID == null)
      {
         throw new NullPointerException("URL must be non-null");
      }
      
      SAXBuilder builder = new SAXBuilder();
      //Load the entire document into memory
      //from the network or file system
      Document doc = builder.build(systemID);
      
      //Descend the tree and find the URLs.  It helps that
      //the document has a very regular structure.
      Element weblogs = doc.getRootElement();
      List logs = weblogs.getChildren("log");
      Vector urls = new Vector(logs.size());
      Iterator iterator = logs.iterator();
      while(iterator.hasNext())
      {
         Object o = iterator.next();
         Element log = (Element) o;
         try
         {
            //This will probably be changed to getElement() or 
getChildElement()
            Element url = log.getChild("url");
            if(url == null)
               continue;
            String content = url.getTextTrim();
            URL u = new URL(content);
            urls.addElement(u);
         }
         catch(MalformedURLException e)
         {
            //bad input data from on third party; just ignore it
         }
      }
      return urls;
   }
   
   public static void main(String[] args)
   {
      try
      {
         List urls;
         if(args.length > 0)
         {
            urls = listChannels(args[0]);
         }
         else
         {
            urls = listChannels();
         }
         Iterator iterator = urls.iterator();
         while(iterator.hasNext())
         {
            System.out.println(iterator.next());
         }
      }
      catch(Exception e)
      {
         e.printStackTrace();
      }
   }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20020724/13b33ceb/attachment.htm


More information about the jdom-interest mailing list