:: Forum >>

Problem retrieving XML data from servlet

Great work, I am amazed by this whole project.

I am having a problem rendering a grid using a servlet that renders xml.
I know this is possible, eg the xml ignite news example. Is anything wrong with the following script.
If I save the generated xml to a file and then use that files URL path,
then the data displays in the grid as expected, but I need the display to be dynamic. I've only been playing with this for about a week, so I hope I didn't miss something obvious

Thoughts, advice, are greatly appreciated. Thanks for the great work.

Script:
var data = new Active.XML.Table;
data.setURL("http://localhost:9080/data/itemFilter.action");
data.request();

var obj = new Active.Controls.Grid;
obj.setDataModel(data);
document.write(obj);


which causes a script error
obj._data is null or not an object. This does not happen when I l load the same xml data from a static file. eg itemFilter.xml

gbegley
Friday, February 20, 2004
The script looks fine. Make sure you are running the page on the same domain/port number as the data source. TRy to open the data XML in the Internet Explorer window. If nothing helps, then data._http.statusText should have the error message (see MSXML2.XMLHTTP docs).
Alex (ActiveWidgets)
Friday, February 20, 2004
Thanks for the fast reply. The server is the same. I was originally using
data.setURL("/data/itemFilter.action");
But changed it to the full URL by just trying a few different things.
Our database is on the fritz today. So I won't be able to play with it for a while. In the mean time I will review the suggested references. Thank You for the awsome project. I am very much a novice in javascript, So it is very helpful to have some well written Object Oriented javascript for study.
Thanks again
gbegley
Friday, February 20, 2004
OK, after doing some investigation

In the request.js - returnResult function, I added an alert.

if (!self._http.responseXML.xml && self._http.responseText) {
alert("XML:\n[" +self._http.responseText+"]");
self._http.responseXML.loadXML(self._http.responseText);
}

The alert is printing the XML correctly, but after table.response(xml)
is called, selectSingleNode(this._dataPath=*) seems appears to be returning null.

If I call the servlet from the IE window directly, the DHTML XML tree displays as expected.

If I use a ActiveXObject("Microsoft.XMLDOM") I am also able to get at the servlet XML data from javascript. If I access a static xml file on the server, the grid works. So it appears that my problem only occurs when accessing the a dynamic file using
new ActiveXObject("MSXML2.XMLHTTP");
(I was unable to access the XML data from hand coded javascript using this activeX control but the responseText was the expected XML.

My XML doc looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<hibernate action="com.epacube.search.ItemXmlAction" datetime="20 February 2004 00:29:56">
<IorItem id="N10004">
<itemNo>142</itemNo>
<vendCode>CAD</vendCode>
<vendPartNo>C12P2000CG-CHANGED</vendPartNo>
</IorItem>
</hibernate>

Does any one have any Ideas.
gbegley
Wednesday, February 25, 2004
By the way, this is under IE 6.0.2800
gbegley
Wednesday, February 25, 2004
Could you try to remove encoding="UTF-8" from your XML doc?
Alex (ActiveWidgets)
Wednesday, February 25, 2004
Alex,

Thanks, that worked.

Although the static XML file also contained the encoding="UTF-8" part, but I suspect that the static file was in an encoding that was actually parsable as UTF-8.

I was trying to use a general purpose XSL stylesheet to convert the DOM from memory to text. However, even after commenting the encoding specifier, the UTF was still generating. I had to resort to a less standard way to write out the XML (which prints as <t1><t2>r</t2><t2><t3>s</t3></t2><t2>t</t2></t1>)

Here is the style sheet.

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" indent="yes"/><!-- encoding="UTF-8" -->
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

Any Ideas on how to make this work?
If not the other version is working, and there is always tidy if I need the XML formatted.

Thanks you very much for your help.
This project is awsome.

Geoff
gbegley
Wednesday, February 25, 2004
Another suggestion - make sure that the web server sends correct header 'Content-Type: text/xml' with your document. Looks like XMLHTTP does not recognize the response as XML document and treats it as plain text (i.e. responseXML is empty and responseText contains your xml as just text). In this case I am trying to enforce the content being treated as xml anyway - trying to load it from string and this is where 'encoding=UTF-8' breaks.

When you use Microsoft.XMLDOM - it treats any content as XML and Content-Type header may not be necessary.
Alex (ActiveWidgets)
Wednesday, February 25, 2004
That also worked, Thank you.
I placed the JSP page directive <%@ contentType="text/xml"%>
at the top of the page that generates the XML, and now the stylesheet works again.

Thanks for all of your help Alex!
Again, your grid is awsome.

gbegley
Friday, February 27, 2004

This topic is archived.


Back to support forum

Forum search