Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Total N00b question

Reply
Thread Tools

Total N00b question

 
 
Matt Fuerst
Guest
Posts: n/a
 
      01-27-2006
Hi all,

I pre-apologize for the level of stupidity that this message will
contain. I nearly guarantee that your IQ will be lowered by the end of
this message.

Me and a co-worker (I only bring him into this to try to divide the
stupidity in half, thus making us each appear only half as dumb as we
could, oh wait, will we come off twice as dumb since there are two of
us, maybe this plan is backfiring on me)...

We are working a very simple AJAX example that we downloaded from the
Mozilla Dev Center
(http://developer.mozilla.org/en/docs...tting_Started). Using the
presented example everything comes out dandy. However the example loads
a static XML file called test.xml.

Obviously a static XML file isn't too dynamic, so we wanted, nice and
easy to start to make the example more dynamic and dynamically generate
the XML data...

We converted the test.xml file to an ASP file...

Flat test.xml file:
<?xml version="1.0" ?>
<root>
I'm a test.
</root>

We created a test.asp file with the following:
<%
response.write( "<?xml version=""1.0"" ?>" )
response.write( "<root>" )
response.write( "Im a test" )
response.write( "</root>" )
%>

Which we imagined would have the same result. We can load test.xml or
test.asp in our browser directly and both look the same in our browser.
However when we load our Ajax HTML page and click the button to load
our XML file, it refuses to parse the XML with the ASP generated XML.

As a sidenote, this all works fine in Firefox.

Many hours later we figured it must have had something to do with the
headers that IIS and ASP were passing to the browser. So we loaded
Apache + PHP 5. We created a test.php file which outputs our simple XML
document. Again loading up test.php directly is fine, but within the
Ajax app it refuses to parse (in Internet Explorer, again Firefox
handles it fine). We also added header() php function calls before we
pass the XML data to force it to be text/xml data type, still no go. I
changed Apache to pass .xml files into PHP and pass along to the
client, in case the Ajax was not accepting of a .php file passing an
XML file... still no go..

Ok.. so there's a day in the bank.. the longest time ever to create a
"Hello World" application (I hope my boss isn't reading this since I am
going to be pink slipped for being so unproductive).

We decided it must be some problem with the Types, Mime Types, all that
stuff that IE still was refusing to see our "dynamically generated" XML
file...

We rewrote our dynamic XML output using the XML DOM model... I create
a very simple document named test2.php as follows:

<?php
$doc = new DOMDocument();
$doc->formatOutput = true;

$now = time();
$developers = $doc->createElement( "time" );
$doc->appendChild( $developers );
$developers->appendChild( $doc->createTextNode($now) );

echo $doc->saveXML();
?>

My JavaScript to parse out the data looks like:

function alertContents()
{
if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
alert(http_request.responseText);
var xmldoc = http_request.responseXML;
var root_node = xmldoc.getElementsByTagName('time').item(0);
if( root_node )
alert(root_node.firstChild.data);
else
{
alert( 'Poop the bed' );
}
}
else
{
alert('There was a problem with the request.');
}
}
}

We always see "Poop the Bed" in IE and it works fine in Firefox.

That's officially the end of the rope... We're going to go home now and
drown ourselves in our mediocrity and hope to return to work Monday and
read the mockings of our fellow developers here in this public forum,
and maybe an idea or two on what the heck we are doing wrong...

Thanks!

Matt

 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      01-28-2006
Matt Fuerst wrote:
> We are working a very simple AJAX example that we downloaded from the
> Mozilla Dev Center


No AJAX application is simple

[...]
> We created a test.asp file with the following:
> <%
> response.write( "<?xml version=""1.0"" ?>" )
> response.write( "<root>" )
> response.write( "Im a test" )
> response.write( "</root>" )
> %>
>
> Which we imagined would have the same result. We can load test.xml or
> test.asp in our browser directly and both look the same in our browser.
> However when we load our Ajax HTML page and click the button to load
> our XML file, it refuses to parse the XML with the ASP generated XML.
>
> As a sidenote, this all works fine in Firefox.


Yep. As per usual.

[...]
> We decided it must be some problem with the Types, Mime Types, all that
> stuff that IE still was refusing to see our "dynamically generated" XML
> file...


Could be. FAQ. http://xml.silmaril.ie/developers/serversoftware/

///Peter
 
Reply With Quote
 
 
 
 
dtrobinson
Guest
Posts: n/a
 
      02-07-2006

You're not alone Matt. I've been programming for 10+ years in severa
different languages and just attempted to do exactly what you wer
trying to do and came across a little frustration of my own. Thi
should work for IE. Load these files in the same directory and yo
should get alerted when you go to test.asp. Hope this helps.

D.


file: test2.asp
-------------------------------------------
<%
response.buffer=true
response.contentType = "text/xml"
%>
<root>
<value>
<nm>I'm a test.</nm>
<party>Darrell</party>
</value>
<value>
<nm>test 2</nm>
<party>Robinson </party>
</value>
</root>
--------------------------------------------

file: test.asp
--------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY onload="makeRequest('test2.asp');">
<script type="text/javascript" language="javascript">

var http_request = false;

function makeRequest(url) {

http_request = false;

if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
// See note below about this line
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = ne
ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!http_request) {
alert('Giving up Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url, true);
http_request.send(null);

}

function alertContents() {

if (http_request.readyState == 4) {
if (http_request.status == 200) {
var xmldoc = http_request.responseXML;
//var root_node = xmldoc.getElementsByTagName('root').item(0);
//alert(root_node.firstChild.data);
err = xmldoc.parseError;
if (err.errorCode != 0) {
alert("Error: " + err.reason);
} else{
var xml = xmldoc.getElementsByTagName('root').item(0);
var y
xmldoc.getElementsByTagName('root').item(0).getEle mentsByTagName('value').length-1;
for(var x=0;x<=y;x++){
alert(xml.getElementsByTagName('value').item(x).ge tElementsByTagName('nm').item(0).firstChild.data)
alert(xml.getElementsByTagName('value').item(x).ge tElementsByTagName('party').item(0).firstChild.dat a)
} }


} else {
alert('There was a problem with the request.');
}
}

}
</script>
<span
style="cursor: pointer; text-decoration: underline"
onclick="makeRequest('test2.asp')">
Make a request
</span>

</BODY>
</HTML>
--------------------------------------------------

--
dtrobinso
-----------------------------------------------------------------------
dtrobinson's Profile: http://techiegroups.com/member.php?userid=6
View this thread: http://www.techiegroups.com/showthread.php?t=10059

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BT Total Broadband vs BT Business Total John Y UK VOIP 2 02-02-2007 09:27 AM
access denied... n00b question Grant Merwitz ASP .Net 1 08-08-2005 09:20 AM
n00b Question Ambush ASP .Net 1 12-19-2004 03:48 PM
n00b Question re: MSDE SQL 2000 Set-up newgenre ASP .Net 2 04-19-2004 06:16 PM
ultimate n00b question re: my / our Koncept Perl 3 12-06-2003 10:58 PM



Advertisments