[jdom-interest] SAXBuilder: Build document from url fails

Jason Hunter jhunter at xquery.com
Thu Nov 11 00:08:29 PST 2004


Any issue wouldn't be exactly in JDOM, because it's the underlying 
parser's job to pull from the content from the URL.  You don't say which 
parser you're using.

The FAQ addresses some issues you get when loading content from a socket.

If I were you, I'd print the document that was built and see if it looks 
complete.  Odds are it's not.  Isolate the exact delta between the two 
code paths, which is easier to do if you remove the Amazon specific 
processing code from the mix.

-jh-

Matthias Klein wrote:

> I try to use the REST inteface of Amazon.com to perform ItemSearchRequests.
> That interface returns a standard XML file containing the results of the
> query.
> 
> But when I try to build a Document from the result by
> 
>                 Document doc = builder.build(url);
>                 Element root = doc.getRootElement();
>                 Element items = root.getChild("Items");
> 
> I keep getting a NullPointerException. (The url represents the target
> endpoint of the Amazon Interface and contains the query parameters)
> 
> When I save the XML into a file first and do
> 
>                 Document doc = builder.build(file);
>                 Element root = doc.getRootElement();
>                 Element items = root.getChild("Items");
> 
> it works fine.
> 
> Why can I not build a Document from a url using the SAXBuilder? (Why do I
> have to use the detour via a file?)
> 
> The only parameter of the SAXBuilder build() method that works here is the
> file. When I try any of the other parameters (such as a Reader or
> InputStream) I keep getting the NullPointerException below.
> The Exception occurs in the last line: Element items =
> root.getChild("Items"); Which looks to me as if the data returned by Amazon
> did not make it into the Document.
> Why is that?
> 
> Thanks
> 
> Matt
> 
> 
> P.S. Here is the exception: (line 107 is the one mentioned above: Element
> items = ...)
> 
> java.lang.NullPointerException
>         at AmazonConnector.doItemSearch(AmazonConnector.java:107)
>         at MidTermProjectMain.main(ProjectMain.java:41)
> java.lang.NullPointerException
>         at AmazonConnector.doItemSearch(AmazonConnector.java:107)
>         at MidTermProjectMain.main(ProjectMain.java:41)
> 
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> 


More information about the jdom-interest mailing list