aspose file tools*
The moose likes Java in General and the fly likes URLConnection returning html output instead of XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "URLConnection returning html output instead of XML" Watch "URLConnection returning html output instead of XML" New topic
Author

URLConnection returning html output instead of XML

Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi all,

I have a url where the content is XML and it has XSL file specified. Now, when I go to that url from the browser and do view source I see the XML data BUT from the java program when I make connection and read the data via BufferedReader I get HTML (that means somewhere its making XSL applied).

I tried to set property "content-type" as "text/xml" on the URLConnection but it still gives me the HTML output.

Here is the code,


How can I get the XML output?

Regards
Maulin
Rajesh Tarigopula
Greenhorn

Joined: Oct 19, 2004
Posts: 8
If you want only XML check your XML file for the code

<?xml-stylesheet type="text/xsl" href="some xsl file name"?>

delete this line from xml file.

This may resolve ur problem.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi Pandoo,

Deleting the xsl declaration is not possible for me as I can't control xml generation

Will keep looking for ways...and of course keep JR updated..

Regards
Maulin
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
oh btw,

I just realized that it was so stupid to set content type to be xml. I am reading data, not writing it so its wrong to set content type

At this point, I am having a question. I always thought that when we have this XSL applied to the XML , browser downloads the XML and then applies the XSL over it to display data in whatever format. Hence I thought if I make a URLConnection it would just give me the XML data as I don't have transformation applied but when I print ContentType from the URLConnection it gives me text/html which means the data is converted to html already...

Can anybody explain what exactly happens here?

Regards
Maulin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URLConnection returning html output instead of XML
 
Similar Threads
Make a Servlet or JSP relinquish control
string getting converted to ASCII
help: need help for post
Reading uploaded file in jsp
Need to see how HTTP Works