I try what you suggest me but still i found same result.
Thanks...
>I try what you suggest me but still i found same result.
I tried your original code and got the same confusing
result you got. The data of the XML is definitely in the
string, it can seen when printed out. If you take the
string and check it for well-formedness, it checks OK
as well. Yet the call to docBuilder.parse not only
throws no exceptions (as I might expect if the XML
were not well-formed) but returns a 'null' Document.
By my understanding of the JavaDocs for the parse
method, it should either return a valid Document object,
or throw parsing related Exceptions (before the NPE
in the code shown).
As another note, try to get in the habit of dumping
the stack trace of the Exception - it contains more
and better information. E.G. ..
}catch (Exception ex){
System.out.println("exception:-> "+ex);
ex.printStackTrace();
}
[ And as an aside, Daniel's short-hand makes a lot of
sense for working code, but for debugging, I think it is
best to give the code as many failure 'points' (on lines
of code) as possible - to help pin down which part
breaks. Stack traces are a lot more useful for the type
of 'step by step' code you first posted, than for the
'short-hand' way of writing the code. ]

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Manfred Rosenboom - 03 Aug 2007 11:56 GMT
I have used the following code:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc =
db.parse("http://xml.weather.yahoo.com/forecastrss?p=INXX0038&u=f");
System.out.println("doc : " + doc);
With the above code I get the following output:
Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
set, which is probably not what is desired. Parser will use a default
ErrorHandler to print the first 10 errors. Please call
the 'setErrorHandler' method to fix this.
Error: URI=http://xml.weather.yahoo.com/forecastrss?p=INXX0038&u=f
Line=2: Element type "rss" must be declared.
Error: URI=http://xml.weather.yahoo.com/forecastrss?p=INXX0038&u=f
Line=3: Element type "channel" must be declared.
Error: URI=http://xml.weather.yahoo.com/forecastrss?p=INXX0038&u=f
Line=4: Element type "title" must be declared.
Error: URI=http://xml.weather.yahoo.com/forecastrss?p=INXX0038&u=f
Line=5: Element type "link" must be declared.
Error: URI=http://xml.weather.yahoo.com/forecastrss?p=INXX0038&u=f
Line=6: Element type "description" must be declared.
Error: URI=http://xml.weather.yahoo.com/forecastrss?p=INXX0038&u=f
Line=7: Element type "language" must be declared.
Error: URI=http://xml.weather.yahoo.com/forecastrss?p=INXX0038&u=f
Line=8: Element type "lastBuildDate" must be declared.
Error: URI=http://xml.weather.yahoo.com/forecastrss?p=INXX0038&u=f
Line=9: Element type "ttl" must be declared.
Error: URI=http://xml.weather.yahoo.com/forecastrss?p=INXX0038&u=f
Line=10: Element type "yweather:location" must be declared.
Error: URI=http://xml.weather.yahoo.com/forecastrss?p=INXX0038&u=f
Line=11: Element type "yweather:units" must be declared.
doc : [#document: null]
Best,
Manfred