Problem parsing XML with namespaces in Mozilla

admin

Administrator
Staff member
Hi, I have just discovered the wonderfull world of XML... and struck a few problems on the way. I'll greatly appreciate your advice. Here is the nature of the problem:

I am using a simple example provided on <!-- m --><a class="postlink" href="http://www.w3schools.com/xml/xml_parser.asp">http://www.w3schools.com/xml/xml_parser.asp</a><!-- m -->

Opens well in IE and FF but when I add namespaces to xml file, FF shows nothing and doesn't throw any errors either [I call this element with with a script var x=xmlDoc.getElementsByTagName('my:price'); ]. Here is XML example:


<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v2007 (<!-- m --><a class="postlink" href="http://www.altova.com">http://www.altova.com</a><!-- m -->) -->
<bookstore xmlns:my="http://www.mysite.net/namespaces">
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<my:price>30.00</my:price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<my:price>29.99</my:price>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<my:price>49.99</my:price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<my:price>39.95</my:price>
</book>
</bookstore>


Javascript code for Mozilla type browsers allows for adding some parameters regarding namespaces and root element but I could not find any examples how to configure it.


xmlDoc=document.implementation.createDocument("","",null);


I tried varius combitations but none worked.

As well, what if XML document has numerous namespaces?

Thanks in advance
 
Back
Top