Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URLConnection returning html output instead of XML

 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic