PDA

View Full Version : Load Raw XML issue in IE



para
10 May 2007, 6:21 AM
This works fine in FF2.0, but in IE, global variable xmlDoc is null in processConfigurationFile.
Suggestions?



var p = new Ext.data.HttpProxy({url:'external/config.xml'});
p.on('loadexception', function(o, response, e) {
document.write('hello'); if (e) throw e;});

p.load(null, {
read: function(response) {
var doc = response.responseXML;
xmlDoc = doc.documentElement || doc;
}
}, processConfigurationFile);

tryanDLS
10 May 2007, 8:21 AM
Did you verify that you're sending the right content-type from the server? If you send it as plain text IE won't parse it as xml. There are several other threads regarding this.

para
10 May 2007, 8:28 AM
By content-type you simply mean that the file is indeed an xml document, correct?
Here's a massively stripped down version of the file. It's all on localHost right now.


<?xml version="1.0" encoding="UTF-8"?>
<config>
<menuConfigs>
...
</menuConfigs>
<treeConfigs>
...
</treeConfigs>
<nodeConfigs>
...
</nodeConfigs>
<editors>
...
</editors>
</config>

jsakalos
10 May 2007, 10:37 AM
No, Tim means Http Header "Content-Type" that server sends.

para
11 May 2007, 6:05 AM
I've read up some on the content-type of the response. It is sending application/xml.
I'm going to try to strip the code way down and try to load it.
...

para
11 May 2007, 10:23 AM
I've got it down to this. It breaks on the "var c in node.childNodes" because (I believe) the xmlDoc is null.
This page is ready to test if anyone want to copy it and try it for themselves. (my IE debugging isn't very good, I'm open to suggestions on programs to use... I've got the dev. toolbar and MS script debugger)



<html>
<head>
<title>IE XML Test</title>
<!-- LIBS -->
<script type="text/javascript" src="ext-1.0/adapter/yui/yui-utilities.js"></script>
<script type="text/javascript" src="ext-1.0/adapter/yui/ext-yui-adapter.js"></script>
<script type="text/javascript" src="ext-1.0/ext-all.js"></script>
<!-- CUSTOM LIBS -->
<script type="text/javascript">

var xmlDoc;

Ext.onReady(function(){
var p = new Ext.data.HttpProxy({url:'config.xml'});
p.on('loadexception', function(o, response, e) {if (e) throw e;});

p.load(null, {
read: function(response) {
var doc = response.responseXML;
xmlDoc = doc.documentElement || doc;
}
}, processConfigurationFile);
});

function processConfigurationFile()
{
loadMenusConfig(getChild(xmlDoc,'menuConfigs'));
}

function getChild(node, child) {
for(var c in node.childNodes) {
if(node.childNodes[c].tagName == child)
return node.childNodes[c];
}
return null;
}

function loadMenusConfig(xmlNode) {
}

</script>
</head>
<body>
<div id ="container">
</div>
</body>
</html>


Here's a sample config.xml . (stripped down from about 700 lines)

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

<config>
<treeConfigs>
<panels>
<panel id="Casebook">
<librarytree id="Casebook Library" src="external/libraryDisplay.xml" sorted="false" />
<tree id="Casebook Design" src="external/edcDemo2005Display.xml" sorted="false" />
</panel>
</panels>
</treeConfigs>


</config>

para
16 May 2007, 11:28 AM
:(( somebody's got to know whats going on...

Richard
16 May 2007, 12:08 PM
I've read up some on the content-type of the response. It is sending application/xml.
I'm going to try to strip the code way down and try to load it.
...

I use 'text/xml' for the content type, this works in IE and FF.

You can also look at the XML form example to see how it is done there.

Animal
16 May 2007, 11:44 PM
If you stop at the line



var doc = response.responseXML;


and examine the response.responseText, and it's what you expect, but responseXML is null, then there's been a parsing error. Copy the responseText into an XML editor and see what's wrong.

para
17 May 2007, 5:22 AM
Thanks Animal.

Key points:

responseXML : still null
responseText: contains XML in text format exactly as specified in xml file
Other tests: I replaced my xml with http://extjs.com/deploy/ext/examples/grid/plants.xml and got same results



Any other suggestions?

Here's all the code i'm using if anyone else wants to try it.

<html>
<head>
<title>IE XML Test</title>
<script type="text/javascript" src="ext-1.0/adapter/yui/yui-utilities.js"></script>
<script type="text/javascript" src="ext-1.0/adapter/yui/ext-yui-adapter.js"></script>
<script type="text/javascript" src="ext-1.0/ext-all.js"></script>
<script type="text/javascript">
var xmlDoc;
Ext.onReady(function(){
var p = new Ext.data.HttpProxy({url:'config.xml'});
p.on('loadexception', function(o, response, e) {if (e) throw e;});
p.load(null, {
read: function(response) {
var doc = response.responseXML;
xmlDoc = doc.documentElement || doc;
}
}, processConfigurationFile);
});

function processConfigurationFile() {
var child = getChild(xmlDoc,'menuConfigs');
}

function getChild(node, child) {
try {
for(var c in node.childNodes) {
if(node.childNodes[c].tagName == child)
return node.childNodes[c];
}
}catch (e) {
document.getElementById('errorMess').innerHTML += 'getChild threw an error<br>';
for(var a in e) {document.getElementById('errorMess').innerHTML += ' ' + a + ' = ' + e[a] + '<br>';}
}
return null;
}
</script>
</head>
<body> <div id ="container"> <div id ="errorMess"/> </div> </body>
</html>



<?xml version="1.0" encoding="ISO-8859-1"?>
<config>
<treeConfigs>
<panels>
<panel id="Casebook">
<librarytree id="Casebook Library" src="external/libraryDisplay.xml" sorted="false"></librarytree>
<tree id="Casebook Design" src="external/edcDemo2005Display.xml" sorted="false"></tree>
</panel>
</panels>
</treeConfigs>
</config>

Animal
17 May 2007, 5:26 AM
It's not an Ext issue. The browser has not parsed the text into a document.

Are you sure the Content-Type header is correct?

para
17 May 2007, 5:33 AM
Yes, content-type is application/xml.
I'll keep playing with it and see if it may be my install of IE or maybe the version...who knows...
If you think of anything else please let me know.
I'll have a hell of an example application for yall once it's done.

para
13 Jun 2007, 2:50 PM
Ok, so I've been developing in Firefox for the past few months and it's time to get this thing working in the anti-browser, IE.
I have the most simple of pages in this zip, which is ready to deploy. Can someone take a look at the code or, better yet, unzip it and try to run it yourself. I can't figure it out for the life of me.
Thanks

index.html


<html>
<head>
<title>IE XML Test</title>
<script type="text/javascript" src="ext-1.0/adapter/yui/yui-utilities.js"></script>
<script type="text/javascript" src="ext-1.0/adapter/yui/ext-yui-adapter.js"></script>
<script type="text/javascript" src="ext-1.0/ext-all.js"></script>
<script type="text/javascript">
var xmlDoc;
Ext.onReady(function(){
var p = new Ext.data.HttpProxy({url:'config.xml', method: 'POST'});
p.load(null, {
read: function(response) {
var doc = response.responseXML;
xmlDoc = doc.documentElement || doc;
}
}, processConfigurationFile);
});


function processConfigurationFile() {
var child = getChild(xmlDoc,'menuConfigs');
}

function getChild(node, child) {
try {
for(var c in node.childNodes) {
if(node.childNodes[c].tagName == child)
return node.childNodes[c];
}
}catch (e) {
document.getElementById('errorMess').innerHTML += 'getChild threw an error<br>';
for(var a in e) {document.getElementById('errorMess').innerHTML += ' ' + a + ' = ' + e[a] + '<br>';}
}
return null;
}
</script>
</head>
<body> <div id ="container"> <div id ="errorMess"/> </div> </body>
</html>


config.xml


<?xml version="1.0" encoding="ISO-8859-1"?>
<config>
<treeConfigs>
<panels>
<panel id="Designer">
<librarytree id="Library" src="whatever.xml" sorted="false"></librarytree>
<tree id="Design" src="whatever2.xml" sorted="false"></tree>
</panel>
</panels>
</treeConfigs>
</config>

PFM
13 Jun 2007, 4:31 PM
para,

I have had numerous problems with IE not being able to load the xml document to set responseXML, but it works in firefox. At first I thought it was something invalid in the XML but I would look at responseText and it look perfectly fine.... so I started to try to load the xml document with the code posted below. This would always show the reason why the XML text could not be loaded into a XML document... and they were always valid errors, but it was all due to encoding/charset issues...

What I have discoverd in my case, and to what the other posts are indicating, it is a case with charset/encoding. In my case, my application server is websphere and it's behavior is to



"first, to check if charset is set on content type header. If it is, then the product uses content type header for character encoding; if it is not, then the product uses character encoding set on server using the system property default.client.encoding. If charset is not present and the system property is not set, then the product uses ISO-8859-1."


Well, the ISO-8859-1 charset causes a problem because the default encoding for xml is UTF-8. No idea why firefox handles it fine, but IE chokes. Once I started setting specifying the response header, all my errors cleared up. I had to set the content type in the response header...


httpServletResponse.setContentType("text/xml; charset=UTF-8");

Using <?xml version="1.0" encoding="UTF-8"?> did not fix the problem... at least from what I remember.. a little fuzzy since I was trying many things to resolve this issue...

code to test to see if xml could not be loaded into responseXML




var xml = o.responseXML;
if (xml.xml == "") {
xml = o.responseText;
loadXML(xml);
}



loadXML function to see what parsing error is occuring




function loadXML(xml) {

//For firefox and friends
if (document.implementation && document.implementation.createDocument) {
xmlDoc = document.implementation.createDocument("", "", null);
}
else if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4)
{
}};
} //end if
else {
alert('i have no name :(');
alert('Your browser can\'t load the XML file: ' + e.toString());
return;
} //end else if

xmlDoc.async="false";
xmlDoc.loadXML(xml);
alert("errorCode = " + xmlDoc.parseError.errorCode);
alert("reason = " + xmlDoc.parseError.reason);
alert("line = " + xmlDoc.parseError.line);
alert("srtText = " + xmlDoc.parseError.srcText);

}


I may be incorrect with some of my explanation as this client side stuff is fairly new to me, but I hope this helps.