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

xmldom getAttribute firefox problem

P: n/a
Hi all

I am trying to get a url attribute from an xml node:
<item>
<media url="http://blablabla.com" />
</item>

I can do this in IE with the following code:
var newDom = xmlhttp.responseXML;
var x = newDom.getElementsByTagName("item");
var urlNode = x[0].getElementsByTagName('media');
var myUrl = urlNode[0].getAttribute('url');

If I try this code in FireFox it gives me the following error:

urlNode[0] has no properties referring to this line : myUrl =
urlNode[0].getAttribute('url');

I've tried to fix it lots of ways with no joy.

Any help is much appreciated

Thanks in advance

John

Oct 17 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
jp*******@googlemail.com wrote:
I am trying to get a url attribute from an xml node:
<item>
<media url="http://blablabla.com" />
</item>

I can do this in IE with the following code:
var newDom = xmlhttp.responseXML;
var x = newDom.getElementsByTagName("item");
var urlNode = x[0].getElementsByTagName('media');
var myUrl = urlNode[0].getAttribute('url');

If I try this code in FireFox it gives me the following error:

urlNode[0] has no properties referring to this line : myUrl =
urlNode[0].getAttribute('url');

I've tried to fix it lots of ways with no joy.
Firebug (1.05) test case

var s = [
'<item>',
'<media url="http://blablabla.com" />',
'</item>'
].join("\n");

try
{
var p = new DOMParser();
var newDom = p.parseFromString(s, "text/xml");
var x = newDom.getElementsByTagName("item");
var urlNode = x[0].getElementsByTagName("media");
var myUrl = urlNode[0].getAttribute("url");
myUrl
}
catch (e)
{
e
}

WFM in Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7)
Gecko/20070914 Firefox/2.0.0.7

Either you are doing something else wrong or an extension interferes.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Oct 17 '07 #2

P: n/a
On 18 Oct, 00:11, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
jphayc...@googlemail.com wrote:
I am trying to get a url attribute from an xml node:
<item>
<media url="http://blablabla.com" />
</item>
I can do this in IE with the following code:
var newDom = xmlhttp.responseXML;
var x = newDom.getElementsByTagName("item");
var urlNode = x[0].getElementsByTagName('media');
var myUrl = urlNode[0].getAttribute('url');
If I try this code in FireFox it gives me the following error:
urlNode[0] has no properties referring to this line : myUrl =
urlNode[0].getAttribute('url');
I've tried to fix it lots of ways with no joy.

Firebug (1.05) test case

var s = [
'<item>',
'<media url="http://blablabla.com" />',
'</item>'
].join("\n");

try
{
var p = new DOMParser();
var newDom = p.parseFromString(s, "text/xml");
var x = newDom.getElementsByTagName("item");
var urlNode = x[0].getElementsByTagName("media");
var myUrl = urlNode[0].getAttribute("url");
myUrl
}
catch (e)
{
e
}

WFM in Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7)
Gecko/20070914 Firefox/2.0.0.7

Either you are doing something else wrong or an extension interferes.

PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann- Hide quoted text -

- Show quoted text -
Thank you Thomas. You are right

A colleague has established that it is the way the xml is delivered/
formated that is causing problems

John

Oct 19 '07 #3

P: n/a
jp*******@googlemail.com wrote:
On 18 Oct, 00:11, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
>Firebug (1.05) test case

var s = [
'<item>',
'<media url="http://blablabla.com" />',
'</item>'
].join("\n");

try
{
var p = new DOMParser();
var newDom = p.parseFromString(s, "text/xml");
var x = newDom.getElementsByTagName("item");
var urlNode = x[0].getElementsByTagName("media");
var myUrl = urlNode[0].getAttribute("url");
myUrl
}
catch (e)
{
e
}

WFM in Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7)
Gecko/20070914 Firefox/2.0.0.7

Either you are doing something else wrong or an extension interferes.
[...]
Please trim your quotes as described and recommended in the FAQ:

http://jibbering.com/faq/
Thank you Thomas. You are right

A colleague has established that it is the way the xml is delivered/
formated that is causing problems
ACK. Probably you have not served it with an XML MIME media type.

What I found most interesting when creating the test case is that Firebug
now appears to have E4X support built-in which is why

var s =
<item>
<media url="http://blablabla.com" />
</item>;

works there, too. (For DOMParser::parseFromString(), implicit conversion
from type `xml' to type `string' then takes place.)
PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Oct 22 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.