473,659 Members | 2,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to read dynamically generated XML with Javascript and ActiveX XMLHTTP object?

Ive been banging my head on the wall for hours with this one, hopefully
someone will know what Im doing wrong here :\

The Goal:
I have an xml file that is generated on the fly via JSP which I want to
load into a Microsoft.XMLHT TP ActiveX object and manipulate via
javascript on the client side. Data is retreived from the server at the
request of the javascript without having to reload the page.

The Problem:
For the JSP to dynamically output xml, the file must have the extension
JSP, which is set to the mime type of dynamo-internal/html on the
server side (as we are using ATG Dynamo). But the javascript on the
client side will not retrieve anything unless the file extension is
..xml (or the mime type is recognized as text/xml). So the only way I
can get it to work is to change the extension to .xml, which then of
course amkes it so that the server will not process any of the JSP
code.

Ive tried to override the mime type within the javascript, using the
setRequestHeade r method after opening the file, but no luck. A call to
alert the value of req.responseXML .xml after the send() turns up empty.
Ive only gotten it to work if I use a static xml file in palce of the
jsp. Sample of the javascript code is below:

if (window.XMLHttp Request) {
// branch for native XMLHttpRequest object - THIS WORKS
req = new XMLHttpRequest( );
req.overrideMim eType("text/xml");
req.onreadystat echange = processReqChang e;
req.open("GET", "models.jsp?cId =300006&mId=TAC 24", true);
req.send(null);
} else if (window.ActiveX Object) {
// branch for IE/Windows ActiveX version - NOT WORKING
req = new ActiveXObject(" Microsoft.XMLHT TP");
if (req) {
req.onreadystat echange = processReqChang e;
req.open("GET", "models.jsp?cId =300006&mId=TAC 24", true);
req.setRequestH eader("Content-Type","text/xml");
req.send();
}
}

In looking at the following example the Microsoft gives (bottom of
page):

http://support.microsoft.com/default...;EN-US;Q290591

I just dont see what could be going wrong here.
I should note that I successfully got the script to work using the
XMLHttpRequest object and the overrideMimeTyp e() method. This works
with FireFox adn I think some Mozilla clients, but not with the all
important IE5, which instead uses the XMLHTTP ActiveX control.

Thanks for any help,

Mike

Jul 20 '05 #1
5 8541
/mi**********@ya hoo.com/:
The Problem:
For the JSP to dynamically output xml, the file must have the extension
JSP, which is set to the mime type of dynamo-internal/html on the
server side (as we are using ATG Dynamo). But the javascript on the
client side will not retrieve anything unless the file extension is
.xml (or the mime type is recognized as text/xml). So the only way I
can get it to work is to change the extension to .xml, which then of
course amkes it so that the server will not process any of the JSP
code.
Probably not that XML specific, but you should set the
'Content-Type' response header in your JSP, always:

http://java.sun.com/j2ee/1.4/docs/tu...5.html#wp73360

If you further wish the request URL to end with ".xml", the
JavaServlet specification describes how conforming containers could
be configured (web.xml - mappings between request URLs and
servlets/JSPs). Consult with your Dynamo documentation to see how
it's done there.
Ive tried to override the mime type within the javascript, using the
setRequestHeade r method after opening the file, but no luck. A call to
alert the value of req.responseXML .xml after the send() turns up empty.


I have no experience with the 'XMLHttpRequest ' object but I don't
think setting a request header could change the response (generated
by the server) in any way.

--
Stanimir
Jul 20 '05 #2
It worked after I changed the response header from within the JSP page.
Cant beleive I hadnt thought of that earlier!

Jul 20 '05 #3
mi**********@ya hoo.com wrote:
The Problem:
For the JSP to dynamically output xml, the file must have the extension
JSP, [....] But the javascript on the
client side will not retrieve anything unless the file extension is
.xml (or the mime type is recognized as text/xml).


In addition to what's been suggested with regards to your specific
problem (set Content-Type response header), you may also want to have a
look at the classic "Cool URLs Don't Change"
<http://www.w3.org/Provider/Style/URI.html> on why file extensions in
URLs are a Bad Thing.

Regards,
Diego Berge.

--
e-mail address invalid, please reply to newsgroups.

Jul 20 '05 #4

mi**********@ya hoo.com Wrote:
It worked after I changed the response header from within the JSP page.
Cant beleive I hadnt thought of that earlier!

I have the same problem in reading the XML file in IE. I use exactly
the same code, but doesn't work. WHat you mean you change the response
header from within the JSP page? (is JSP refer to JavaScript, btw?)

Thanks,
--
masantra
------------------------------------------------------------------------
masantra's Profile: http://www.24help.info/member.php?userid=450
View this thread: http://www.24help.info/showthread.php?t=347535

24help.info - IT Newsgroups @ http://www.24help.info

Sep 27 '05 #5


masantra wrote:
I have the same problem in reading the XML file in IE. I use exactly
the same code, but doesn't work. WHat you mean you change the response
header from within the JSP page? (is JSP refer to JavaScript, btw?)


If you have a server side application (e.g. CGI, ASP, JSP, PHP)
dynamically generating XML then make sure you set the HTTP response
header to application/xml or some other XML MIME type so in PHP you would do
header('Content-Type: application/xml');
before sending the XML, in ASP
Response.Conten tType = "applicatio n/xml"

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 28 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5552
by: George Hester | last post by:
This location has a parasite checker using javascript. It is in a js file called parasite.js. It is freely available. http://www.doxdesk.com/parasite/ He\She is the only one I trust on the Net who has such a thing. But their js I believe cannot detect coolwebsearch parasites which are the most common such parasites on the Net today. So I'd like to incorporate a check for those parasites in the js. Any suggestions on how this can...
2
2519
by: mikeyjudkins | last post by:
Ive been banging my head on the wall for hours with this one, hopefully someone will know what Im doing wrong here :\ The Goal: I have an xml file that is generated on the fly via JSP which I want to load into a Microsoft.XMLHTTP ActiveX object and manipulate via javascript on the client side. Data is retreived from the server at the request of the javascript without having to reload the page. The Problem:
4
2064
by: Guillaume CABANAC | last post by:
Hi everybody, Does anybody know how to access a remote database (say Oracle) from JavaScript code (within a Firefox Extension) ? I know ADO via ActiveX in the IE world and think a similar thing exists in Firefox. Thanks a lots,
0
1711
by: Kunal | last post by:
Hi all, I have run into a problem that I can't quite figure out. Here is the situation: I have to capture a signature from a WebForm. (The ASP.NET application is running on a TabletPC) Currently only an ActiveX control is available for WebForms, so I embedded it using the "<object>" tag.
0
1956
by: bcox | last post by:
I would like to be able to set parameter values for an ActiveX control hosted on an ASP.NET .aspx page from a C# code behind file. The ActiveX registration code is contained in <OBJECT></OBJECT> tags hosted in the .aspx file. The control in question is a file viewer. I need to be able to set the filename <PARAM NAME="Filename" VALUE="filename.ext"> reference under the <OBJECT></OBJECT> tags dynamically.
1
3801
by: ozzy.osborn | last post by:
Hello All, I have been struggling with a cross browser solution to loading external javascript files on the fly. I have been successful using the following code in IE6: var newScr = document.createElement("SCRIPT"); newScr.src = "newScr.js"; newScr.type="text/javascript";
21
29771
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays prodcut anme have used ajax to avoid refreshing of page this works fine 2.now i have created one row with checkbox|select box|text|text|text|text| where in the select box values are fetched from table here also i have used ajax for getting the m_name...
3
3020
by: VK | last post by:
On Apr 21, 1:54 pm, joe <m...@invalid.comwrote: http://www.jibbering.com/faq/index.html#FAQ4_18
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8535
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8629
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2757
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.