By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,341 Members | 1,726 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,341 IT Pros & Developers. It's quick & easy.

Open a XML and parse it with DOM

P: n/a
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 XUL and SVG).

Thanks
Nov 23 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Carles Company Soler wrote:
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 XUL and SVG).
With Mozilla you have two options, you can create a dummy DOM XML
document e.g.

var xmlDocument = document.implementation.createDocument('', 'dummy',
null);
xmlDocument.onload = function (evt) {
// now access document contents here e.g.
alert('Found ' + xmlDocument.getElementsByTagName('*').length +
'eleemnts.');
};
xmlDocument.load('file.xml');

or you can use XMLHttpRequest to load the file and then access the
responseXML property.

Note that getElementById in XML documents does only work if the DTD
defines the attributes of type ID and the parser reads the DTD or has
that information hardcoded for certain elements (e.g. XHTML or SVG
elements).
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 23 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.