Detect Doctype (DTD)
Test all different doctypes (DTD).
See source for the example code and below for correct code.
This is a revisioned version of the previous one. The new one is faster and takes less space.
03-01-2007Code for Detect Doctype (DTD)
// Detects Doctype (DTD);
// syntax: detectDoctype();
// return: [Boolean and Object] boolean if exist and object doctype with specified info;
// doctype.registration [String or null or false] string if excist, null if not found, false if not excist;
// doctype.organization [String or null or false] string if excist, null if not found, false if not excist;
// doctype.label [String or Array or null or false] string if excist, array if multiple, null if not found, false if not excist;
// doctype.label.host [String or Array or null or false] string if excist, array if multiple, null if not found, false if not excist;
// doctype.label.version [String or Array or null or false] string if excist, array if multiple, null if not found, false if not excist;
// doctype.label.type [String or Array or null or false] string if excist, array if multiple, null if not found, false if not excist;
// doctype.language [String or null or false] string if excist, null if not found, false if not excist;
var detectDoctype=function(){
var regDTD = /\s*(.*)\/\/\s*(\w*)\/\/\s*(\w*)\s+(.*)\s*\/\/\s*(\w*)\s*/gi;
var regLabel = /(\w*)\s+([a-zA-Z]*)\s*([\d\.]*)\s*(\w*)/gi;
window.doctype={};
doctype.registration=null;
doctype.organization=null;
doctype.type=null;
doctype.label=[null];
doctype.label.host=null;
doctype.label.version=null;
doctype.label.type=null;
doctype.language=null;
if(document.doctype){
identifier=document.doctype.publicId;
}
else {
return false;
}
if(typeof(identifier)=="string" && identifier.match(regDTD)){
doctype.registration=RegExp.$1?RegExp.$1:null;
doctype.organization=RegExp.$2?RegExp.$2:null;
doctype.type=RegExp.$3?RegExp.$3:null;
doctype.label=RegExp.$4?RegExp.$4:null;
doctype.language=RegExp.$5?RegExp.$5:null;
if(labels=doctype.label.split(/\s*plus\s*/)){
doctype.label=labels;
doctype.label.host=[];
doctype.label.version=[];
doctype.label.type=[];
for(var i=0; i<labels.length; i++){
labels[i].match(regLabel);
doctype.label.host.push(RegExp.$1?RegExp.$1:null);
doctype.label.version.push(RegExp.$3?RegExp.$3:null);
if(RegExp.$2){
doctype.label.type.push(RegExp.$2?RegExp.$2:null);
}
else{
doctype.label.type.push(RegExp.$4?RegExp.$4:null);
} } }
return true;
}
else{
doctype.registration=false;
doctype.organization=false;
doctype.type=false;
doctype.label=[false];
doctype.label.host=false;
doctype.label.version=false;
doctype.label.type=false;
doctype.language=false;
return false;
}
};
Detect Doctype (DTD) v2
This text should not be seen and spoken.