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/