LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-04-2010, 10:12 AM   #1
estratos
Member
 
Registered: Jan 2006
Distribution: Ubuntu
Posts: 85

Rep: Reputation: 15
JavaScript - File not recognized as XML by Firefox


This question is not specific to Linux but maybe some of the gurus around here will know how to solve my problem.

I'm loading an XML file stored in a tiny web server (based on lwip). This web server is not very cooperative and is not marking the http content-type as "text/xml". As result, Firefox is not recognizing the file as xml (IE does) so I can't use DOM methods for parsing the xml file.

overrideMimeType("text/xml") should help me avoid this problem but, even having overrided the mymetype, the content-type received is still "text/plain".

This is a portion of my JavaScript code:

Code:
var xmlObj;

// loadXMLdata is called from the html file
function loadXMLdata()
{
  var dataFile = window.location.href.substring(0, window.location.href.lastIndexOf("/") + 1) + "config/myfile.xml";	

  if (window.XMLHttpRequest)
  {
    xmlObj = new XMLHttpRequest();

    // This should override the mimetype...
    if (xmlObj.overrideMimeType)
      xmlObj.overrideMimeType("text/xml");

    xmlObj.onreadystatechange = fillXMLdata;
    xmlObj.open("GET", dataFile, true);
    xmlObj.send("");
  }
  else
  {
    alert("Your browser can not handle this script");
    return;
  }
}

// fillXMLdata is called from loadXMLdata once the xml object is ready
function fillXMLdata()
{
  if (xmlObj.readyState == 4)
  {
    // Here Content-Type shows again "text/plain"
    alert(xmlObj.getAllResponseHeaders());

    var xmlDoc = xmlObj.responseXML.documentElement;

    // And here section is null
    var section = xmlDoc.getElementsByTagName("section")[0];
  }
}
The xml is quite simple:

Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<section>
  <item>1</item>
  <item>2</item>
</section>
Thanks guys for your comments.

Daniel.

Last edited by estratos; 02-04-2010 at 10:13 AM.
 
Old 02-05-2010, 08:13 AM   #2
estratos
Member
 
Registered: Jan 2006
Distribution: Ubuntu
Posts: 85

Original Poster
Rep: Reputation: 15
Never mind, I ended by patching the problem on the server side.

Thanks.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
flashplayer 10 not recognized by firefox-1.5.06.uci on dsl -- i copied the .so file fence Linux - Newbie 5 02-18-2009 11:04 PM
Reading/Wirting file/parsing xml file using javascript fakhrul Programming 1 08-14-2007 05:08 PM
Ubuntu Edgy/Firefox 2/Javascript - Firefox closes accessing websites with Javascript Interdictor Ubuntu 8 11-02-2006 11:58 AM
LXer: JavaScript meets XML in Firefox on Ubuntu Linux LXer Syndicated Linux News 0 08-07-2006 11:54 AM
xml and javascript logicdisaster Programming 0 06-28-2004 05:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration