<HTML><FONT FACE=arial,helvetica><FONT SIZE=2 FAMILY="SANSSERIF" FACE="Arial" LANG="0">Hi all,<BR>
<BR>
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.<BR>
<BR>
D:\sjsu\cs296>java WeblogsJDOM weblog.xml<BR>
org.jdom.JDOMException: Error in building: msdn.microsoft.com<BR>
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:373)<BR>
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:772)<BR>
at WeblogsJDOM.listChannels(WeblogsJDOM.java:25)<BR>
at WeblogsJDOM.main(WeblogsJDOM.java:62)<BR>
Caused by: java.net.UnknownHostException: msdn.microsoft.com<BR>
at java.net.InetAddress.getAllByName0(InetAddress.java:571)<BR>
at java.net.InetAddress.getAllByName0(InetAddress.java:540)<BR>
at java.net.InetAddress.getByName(InetAddress.java:449)<BR>
at java.net.Socket.<init>(Socket.java:100)<BR>
at sun.net.NetworkClient.doConnect(NetworkClient.java:50)<BR>
at sun.net.www.http.HttpClient.openServer(HttpClient.java:331)<BR>
at sun.net.www.http.HttpClient.openServer(HttpClient.java:517)<BR>
at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)<BR>
at sun.net.www.http.HttpClient.<init>(HttpClient.java:277)<BR>
at sun.net.www.http.HttpClient.New(HttpClient.java:289)<BR>
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection<BR>
.java:408)<BR>
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon<BR>
nection.java:501)<BR>
at java.net.URL.openStream(URL.java:798)<BR>
at org.apache.xerces.readers.DefaultReaderFactory.createReader(DefaultRe<BR>
aderFactory.java:149)<BR>
at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromExtern<BR>
alEntity(DefaultEntityHandler.java:772)<BR>
at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromExtern<BR>
alSubset(DefaultEntityHandler.java:571)<BR>
at org.apache.xerces.framework.XMLDTDScanner.scanDoctypeDecl(XMLDTDScann<BR>
er.java:1139)<BR>
at org.apache.xerces.framework.XMLDocumentScanner.scanDoctypeDecl(XMLDoc<BR>
umentScanner.java:2145)<BR>
at org.apache.xerces.framework.XMLDocumentScanner.access$0(XMLDocumentSc<BR>
anner.java:2100)<BR>
at org.apache.xerces.framework.XMLDocumentScanner$PrologDispatcher.dispa<BR>
tch(XMLDocumentScanner.java:831)<BR>
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentS<BR>
canner.java:381)<BR>
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)<BR>
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)<BR>
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:772)<BR>
at WeblogsJDOM.listChannels(WeblogsJDOM.java:25)<BR>
at WeblogsJDOM.main(WeblogsJDOM.java:62)<BR>
<BR>
<BR>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR>
<BR>
import org.jdom.*;<BR>
import org.jdom.input.SAXBuilder;<BR>
import java.util.*;<BR>
import java.net.*;<BR>
<BR>
public class WeblogsJDOM<BR>
{<BR>
public static String DEFAULT_SYSTEM_ID = "d:\\sjsu\\cs296\\weblog.txt";<BR>
<BR>
public static List listChannels() throws JDOMException<BR>
{<BR>
return listChannels(DEFAULT_SYSTEM_ID);<BR>
}<BR>
<BR>
public static List listChannels(String systemID) throws JDOMException, NullPointerException<BR>
{<BR>
if(systemID == null)<BR>
{<BR>
throw new NullPointerException("URL must be non-null");<BR>
}<BR>
<BR>
SAXBuilder builder = new SAXBuilder();<BR>
//Load the entire document into memory<BR>
//from the network or file system<BR>
Document doc = builder.build(systemID);<BR>
<BR>
//Descend the tree and find the URLs. It helps that<BR>
//the document has a very regular structure.<BR>
Element weblogs = doc.getRootElement();<BR>
List logs = weblogs.getChildren("log");<BR>
Vector urls = new Vector(logs.size());<BR>
Iterator iterator = logs.iterator();<BR>
while(iterator.hasNext())<BR>
{<BR>
Object o = iterator.next();<BR>
Element log = (Element) o;<BR>
try<BR>
{<BR>
//This will probably be changed to getElement() or getChildElement()<BR>
Element url = log.getChild("url");<BR>
if(url == null)<BR>
continue;<BR>
String content = url.getTextTrim();<BR>
URL u = new URL(content);<BR>
urls.addElement(u);<BR>
}<BR>
catch(MalformedURLException e)<BR>
{<BR>
//bad input data from on third party; just ignore it<BR>
}<BR>
}<BR>
return urls;<BR>
}<BR>
<BR>
public static void main(String[] args)<BR>
{<BR>
try<BR>
{<BR>
List urls;<BR>
if(args.length > 0)<BR>
{<BR>
urls = listChannels(args[0]);<BR>
}<BR>
else<BR>
{<BR>
urls = listChannels();<BR>
}<BR>
Iterator iterator = urls.iterator();<BR>
while(iterator.hasNext())<BR>
{<BR>
System.out.println(iterator.next());<BR>
}<BR>
}<BR>
catch(Exception e)<BR>
{<BR>
e.printStackTrace();<BR>
}<BR>
}<BR>
}</FONT></HTML>