[jdom-interest] XML file in a servlet

Alastair Rodgers alastair.rodgers at PHOCIS.COM
Mon Nov 5 02:20:40 PST 2001


I just did the following quick experiment which might shed some light on this. I created a file called "test.xml" with the following contents: 

<?xml version="1.0" encoding="UTF-8"?>
<test/>

When I open this in IE 5 it displays fine. However, if I rename the file to "test.html" I don't see anything in IE 5 (though I can View Source), because the tags are not valid HTML tags, so the browser just ignores them. This seems to suggest that you need to set the response content type to "text/xml". Alternatively (but more arduously), set the content type to "text/html" and ensure that you construct a valid HTML document by putting the appropriate HTML tags around your doc and escaping any XML reserved chars; for example, the above document could be output as: 

<html>
<body>
<pre>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;test/&gt;
</pre>
</body>
</html>



-----Original Message-----
From: Zach Hollandsworth [mailto:zholland at quarem.com]
Sent: 04 November 2001 22:33
To: 'JDOM'
Subject: RE: [jdom-interest] XML file in a servlet


It performs as normal, when I go to view source in the browser, it is all
there.  But the browser is blank.  Which leads me to believe it is content
type or encoding related.

-----Original Message-----
From: jdom-interest-admin at jdom.org
[mailto:jdom-interest-admin at jdom.org]On Behalf Of Matthew MacKenzie
Sent: Sunday, November 04, 2001 4:29 PM
To: 'JDOM'
Subject: RE: [jdom-interest] XML file in a servlet


...and what is the sporadic behaviour?  Do you get an exception?

-----Original Message-----
From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]
On Behalf Of Zach Hollandsworth
Sent: November 4, 2001 2:16 PM
To: 'JDOM'
Subject: RE: [jdom-interest] XML file in a servlet


Very simply, trying to get XmlFile.xml (well formed HTML as XML) out to
the browser.  I have try quite possibly hundreds of combinations of
charsets, and encoding types.  The file is quite large and has been run
through tidy. If I load the file straight through the browser, it works
fine.  But when run through this servlet, it does not.  In IE, it runs
and you can see it in the "view source", and it work more often in NN,
but I can't nail anything down for sure.

-------------------------------------------------
public void doGet(...
{
 try
 {
  response.setContentType("text/html; charset=UTF-8");
  PrintWriter writer = response.getWriter();

  org.jdom.input.SAXBuilder sb = new org.jdom.input.SAXBuilder();
  org.jdom.Document d = sb.build(new java.io.File("XmlFile.xml"));
  org.jdom.output.XMLOutputter xo = new org.jdom.output.XMLOutputter("",
false, "UTF-8");
  xo.setEncoding("UTF-8");
  xo.output(d, writer);
 }
 catch (org.jdom.JDOMException jde)
 {
  jde.printStackTrace(response.getWriter());
 }
}
-------------------------------------------------

Thanks in advance.
Zach Hollandsworth


-----Original Message-----
From: jdom-interest-admin at jdom.org
[mailto:jdom-interest-admin at jdom.org]On Behalf Of Matthew MacKenzie
Sent: Sunday, November 04, 2001 4:04 PM
To: 'JDOM'
Subject: RE: [jdom-interest] XML file in a servlet


You need to elaborate upon this sporadic behaviour, maybe by including
your code and/or exceptions.

Regards,

Matt

-----Original Message-----
From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]
On Behalf Of Zach Hollandsworth
Sent: November 4, 2001 11:54 AM
To: 'JDOM'
Subject: [jdom-interest] XML file in a servlet


I realize that this is not fully a JDOM question, but it is close.  I
have been working on this for quite some time with no success.  I have a
strong feeling that it is some type of encoding issue.

What I am trying to do is simple,  Load an XML file from a file, and
display it via a servlet to the browser.

The behavior that I get is very sporadic.

Any suggestions?


Thanks

Zach Hollandsworth


_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@you
rhost.com

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@you
rhos
t.com


_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@you
rhost.com

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com





More information about the jdom-interest mailing list