Closed Bug 295567 Opened 20 years ago Closed 20 years ago

getElementById() looks broken for XML documents

Categories

(Core :: XML, defect)

x86
Windows 2000
defect
Not set
major

Tracking

()

VERIFIED INVALID

People

(Reporter: surkov, Unassigned)

Details

Attachments

(3 files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; ru-RU; rv:1.7.5) Gecko/20041108 Firefox/1.0 (ax)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8b) Gecko/20050217

When I specify arbitrary namespace to XML document (not xul of html namespace)
then getElementById() returns null.

In instance:

var xmlwnd=window.open(xmlurl);
window.setTimeout(function()
	{
		alert(xmlwnd.document.getElementById('user'));
	},
0);

or if I load XML document by XMLHttpRequest object then I get the same result.

requestor=new XMLHttpRequest();
requestor.open("get", url, false);
requestor.send(null);
var xmldoc=requestor.responseXML;

alert(xmldoc.getElementById('user'));

Reproducible: Always
Since you haven't included a testcase, I'm going to guess that you haven't
defined the ID in the DTD, which you need to do for arbitrary XML.
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
Yes. I didn't use DTD for my XML file. Can you provide a link on such XML file
with DTD?
Attached file test xml
Attached file xml dtd
Attached file testcase
save xml, dtd and xul files at root of local disc C: and run xul file.

getElementById() returns null. What is wrong?
Your DTD is broken. Use an XML validator to check (for example
http://www.stg.brown.edu/service/xmlvalid/).
Is there a way to attach external DTD (stored in individual file) to xml file by
file or http protocol? If I can load external DTD by chrome protocol only then why?
Status: RESOLVED → VERIFIED
(In reply to comment #7)
> Is there a way to attach external DTD (stored in individual file) to xml file by
> file or http protocol? If I can load external DTD by chrome protocol only then
why?

Mozilla does not support loading external DTDs from remote sites. You should put
a small DOCTYPE section in the beginning of all your XML documents. For example:

<!DOCTYPE foo [
<!ATTLIST abc myid ID #IMPLIED>
]>
<foo>
<abc myid="someid">I can getElementById() this!</abc>
<script
xmlns="http://www.w3.org/1999/xhtml">alert(document.getElementById("someid").firstChild.nodeValue);</script>
</foo>
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: