Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problems using responseXML with XML file created by JSP

807580Jun 13 2010 — edited Jun 15 2010
Hi. I am trying to process dynamic XML files (created using JSP) on the client side using JavaScript and xml http requests. However the responseXML property does not produce a valid XML DOM. When I test it xmlDocument.documentElement is null (see below). Can anyone tell me how to do this (or what I am doing wrong)? I did up some sample code (see below). A straight XML file gets processed properly. A XML document created via a JSP page does not get processed properly, but if I create a DOM parser and parse the responseText object it works.

File 1) XMLFile.xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <gameState>Running</gameState>
    <gameTime>11:02</gameTime>
</root>
File 2) XMLbyJSP.jsp
<%@page contentType="text/xml"%>
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <gameState>Paused</gameState>
    <gameTime>10:24</gameTime>
</root>
File 3) index.jsp - processes the file.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Test XML HTTP request</title>
        <script type="text/javascript">

            /* Requests desired xml files and displays them. */
            function TestXMLHTTPRequest() {

                ...Code in following post as it was too long to hold in this post.

            }

        </script>
    </head>
    <body>
        <table border="1">
            <tr>
                <td style="font-weight:bold">XML file displayed using responseText.</td>
                <td colspan="2" style="font-weight:bold">JSP XML file displayed using responseText.</td>
            </tr>
            <tr>
                <td id="xmlFile">XML displayed here.</td>
                <td colspan="2" id="jspXmlFile">JSP XML displayed here.</td>
            </tr>
            <tr>
                <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
                <td style="font-weight:bold">XML file using responseXML below.</td>
                <td style="font-weight:bold">JSP XML file using responseXML below.</td>
                <td style="font-weight:bold">JSP XML file parsed by DOM parser below.</td>
            </tr>
            <tr>
                <td id="responseXml">XML request responseXML displayed here.</td>
                <td id="jspXmlResponseXml">JSP XML request responseXML displayed here.</td>
                <td id="jspXmlParsedXml">Parsed XML from JSP XML request displayed here.</td>
            </tr>
            <tr>
                <td colspan="3">&nbsp;</td>
            </tr>
            <tr>
                <td colspan="3">
                    Click here to perform test.
                    <input id="testButton" type="button" value="Test XML HTTP request"onclick="TestXMLHTTPRequest()" />
                </td>
            </tr>
        </table>
    </body>
</html>
Edited by: Furrage on Jun 13, 2010 6:25 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 13 2010
Added on Jun 13 2010
6 comments
821 views