473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

How to parse this xml in mozilla

KB
Hi folks,

I'm trying to adopt microsoft-specific code to mozilla. I have an xml
file which I can't figure out how to parse using the XMLDocument
object:

<?xml version="1.0" encoding="utf-16" ?>
<locations>
<loc id="401" name="one" />
<loc id="402" name="two" />
<loc id="403" name="three" />
</locations>

here's the code:

var xmlfile = <above...>
xmldoc = document.implementation.createDocument( "", "", null );
xmldoc.addEventListener("load", onload, false);
xmldoc.load( xmlfile );
.....
.....
function onload( evt )
{
// the following code works in IE, but in NS childNodes is
empty
var locs = xmldoc.childNodes[0];
for ( var i=0; i<locs.childNodes.length; i++ )
{
elem = locs.childNodes[i];
if ( elem.nodeName == "loc" )
{
var id = elem.attributes[0].value;
var name = elem.attributes[1].value;
alert( 'location : ' + id + ',' + name );
}
}
}

Any help is greatly appreciated
Kevin
Jul 23 '05 #1
2 1630
KB wrote:
Hi folks,

I'm trying to adopt microsoft-specific code to mozilla. I have an xml
file which I can't figure out how to parse using the XMLDocument
object:

<snip>

You might give some google hits a look:

http://www.quirksmode.org/dom/importxml.html
http://webfx.eae.net/dhtml/xmlextras/xmlextras.html

MIke
Jul 23 '05 #2


KB wrote:

I'm trying to adopt microsoft-specific code to mozilla. I have an xml
file which I can't figure out how to parse using the XMLDocument
object:

<?xml version="1.0" encoding="utf-16" ?>
<locations>
<loc id="401" name="one" />
<loc id="402" name="two" />
<loc id="403" name="three" />
</locations>

here's the code:

var xmlfile = <above...>
That should be a URL e.g.
var xmlfile = "file.xml";
xmldoc = document.implementation.createDocument( "", "", null );
xmldoc.addEventListener("load", onload, false);
Don't use a function named onload as that is the window.onload handler,
anything else is fine e.g.
xmldoc.addEventListener("load", xmlLoadHandler, false);
xmldoc.load( xmlfile );
....
....
function onload( evt )
function xmlLoadHandler (evt) {
{
// the following code works in IE, but in NS childNodes is
empty
var locs = xmldoc.childNodes[0];


Better
var locs = xmldoc.documentElement;
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3

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

Similar topics

6
by: Els | last post by:
***newbie question*** Hi, I am trying to make my server (Apache) parse .html files as .php. I found this line of code: ForceType application/x-httpd-php placed it in an .htaccess file and...
3
by: John Reese | last post by:
Mozilla, Firefox, Thunderbird, and so forth use this awful format called MORK to store all kinds of things: which messages you've read in a newsgroup, headers and indexes into the mbox file of...
4
by: Matteo | last post by:
Hy everybody. I'm not a html writer, but a sysadmin who's trying to help a user able to compile an online form with IE but not with Mozilla (Moz1.6, Ns7.1, Firefox 0.8+) due to a javascript date...
3
by: Daniel | last post by:
I admit that I am a novice when it comes to the HTML DOM and JavaScript. Basically, here is what I want to do: 1. Import some HTML from a remote web site 2. Parse the HTML to locate a specific...
3
by: Mags | last post by:
Hi everyone, Not a programmer, just need a little help.... I have a form with a type="file" field, which uploads the file to the server (using ColdFusion). is there a way to parse the...
6
by: mike | last post by:
regards: what is the mechanism of "IE" and "Firefox 1.0" to parse HTML file and show the result on the screen?....@@. thank you may god be with you
8
by: Spartanicus | last post by:
The document at http://homepage.ntlworld.com/spartanicus/custom_dtd.htm uses a custom DTD, the w3c validator validates it but with this warning: "Unknown Parse Mode! The MIME Media Type...
8
by: Douglas Crockford | last post by:
There is a new version of JSON.parse in JavaScript. It is vastly faster and smaller than the previous version. It uses a single call to eval to do the conversion, guarded by a single regexp test to...
1
by: Carles Company Soler | last post by:
Hi, how can I open an xml document and parse it with DOM? For example I want to access it via getElementById and all this. I'm using Mozilla Firefox if that's important (it's an application using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.