Forum Moderators: open
------------------ DTD Decleration xyz.dtd -----------
<!ELEMENT comments ( #PCDATA ) >
<!ELEMENT context ( #PCDATA ) >
<!ELEMENT dueBy ( #PCDATA ) >
<!ELEMENT logTime ( #PCDATA ) >
<!ELEMENT opt ( tasks+ ) >
<!ATTLIST opt id ID #REQUIRED >
<!ELEMENT person ( #PCDATA ) >
<!ELEMENT status ( #PCDATA ) >
<!ELEMENT task ( #PCDATA ) >
<!ELEMENT tasks ( comments, context, dueBy, logTime, person, status, task ) >
<!ATTLIST tasks id ID #REQUIRED >
-------------------------------------------
----------------------HTML File t.html ----------
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="x.js" ></script>
</head>
<body onload="onInit()">
<div id="content"></div>
</body>
</html>
------------------ Javascript x.js -------------
function loadFile(filename){//{{{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.load(filename);
return xmlDoc;
}//}}}
function onInit(){//{{{
ddiv=document.getElementById("content");
xml=loadFile("./t.xml");
var task= xml.getElementById("tsk1");
}
---------------------------------------------
in the above sample code the line task= xml.getElementById("tsk1"); returns null. On browsing the xml tree in firefox-firebug I find the isId property of the id="tsk1" attribute is set to false....
Requesting a second set of eyes to help me spot the issue.
Defining an attribute as being of type ID
We can use DTD to define an attribute as being of type ID, so that getElementById will work. The following example defines a partial doctype for RSS so that the id attribute of an <item> element is of type ID:<!DOCTYPE rss SYSTEM "-//CAKE//DTD RSS Test//EN"
[
<!ATTLIST item id ID #IMPLIED>
]>This approach works in Opera and Firefox, but not Safari or Internet Explorer.