Hello. I have a Javascript that gets data from an XML document and
displays it through javascript. The problem is that when I do
dcfile.getEleme ntsByTagName("s ubhead")[0].firstChild.nod eName
all I get is #text. Can you tell me why?
Here is my code:
/*
The Dante-Cubed Standardized Markup Language Javascript API
---[Powered by DCScript]---
Written by Sean M. Hall, Dante, and Peter-Paul Koch
This is the only script we request you ask for permission to use
Permission: dc***@sfhe.cjb. net
*/
if (location.searc h.indexOf("=") > 2) {
file = location.search .substring(loca tion.search.ind exOf("=")+1);
}
else {
file="apple.xml ";
}
function getDCSML() {
if (document.imple mentation && document.implem entation.create Document)
{
dcfile = document.implem entation.create Document("", "", null);
dcfile.onload = createDisplay;
}
else if (window.ActiveX Object)
{
dcfile = new ActiveXObject(" Microsoft.XMLDO M");
dcfile.onreadys tatechange = function () {
if (dcfile.readySt ate == 4) createDisplay()
};
}
else
{
alert('Your browser can\'t handle DCSML. Too bad.');
return;
}
dcfile.load(fil e);
}
function createDisplay()
{
var x = dcfile.getEleme ntsByTagName("D CSML")[0];
var atext = dcfile.getEleme ntsByTagName("L ink")[0];
var htext = dcfile.getEleme ntsByTagName("H eader")[0];
var ahtext = dcfile.getEleme ntsByTagName("A ltHeader")[0];
var pic = dcfile.getEleme ntsByTagName("p ic")[0];
var sub = dcfile.getEleme ntsByTagName("s ubhead")[0];
/*what= new Array();
for (var c=0;x<x.childNo des.length;c++)
{
what[c] = x.childNodes[1].firstChild.nod eValue;
alert(what[c]);
}*/
var othertags = x.childNodes;
var url = atext.getAttrib ute("URL");
//Below is a list of valid DCSML tags
var tags = new Array("DCSML"," Header","AltHea der","Link","pi c","subhead" );
var makeLink = document.create Element("A");
makeLink.href = url;
var makeHeader = document.create Element("H1");
var makeAH = document.create Element("H2");
makeHeader.styl e.color="#CD853 f";
makeAH.style.co lor="#CD853F";
var mahtext = document.create TextNode(ahtext .firstChild.nod eValue);
makeAH.appendCh ild(mahtext);
var mhtext = document.create TextNode(htext. firstChild.node Value);
makeHeader.appe ndChild(mhtext) ;
var txt = document.create TextNode(atext. firstChild.node Value);
makeLink.append Child(txt);
var img = document.create Element("IMG");
img.src = pic.getAttribut e("url");
var p = document.create Element("P");
var mtxt = sub.firstChild. nodeName;
/*
How odd is this? A script inside a script? I'm branding this a
seperate script, because of its importance. It sorts the DCSML
document tags, and creates arrays for existent and non-existant tags.
*/
//Begin DCScript Tag-Sorter
not_tags= new Array();
is_tag= new Array();
for (var i=0;i<tags.leng th;i++)
{
var checktags = dcfile.getEleme ntsByTagName(ta gs[i]);
if (checktags[0] == null) {
not_tags[i] = tags[i]
}
else {
is_tag[i] = tags[i];
}
}
//End tag-sorter
//Ugh it's gonna be a bitch sorting this out...
document.body.a ppendChild(make Header);
document.body.a ppendChild(make AH);
document.body.a ppendChild(make Link);
document.body.i nnerHTML+="<p></p>";
document.body.a ppendChild(img) ;
document.body.a ppendChild(p);
document.body.i nnerHTML+='<spa n style="font-size: 13pt; font-family:
verdana; font-weight:
normal; text-align: left; color: #666666; letter-spacing:
1.2px;">'+mtxt+ '</span><br>';
document.body.i nnerHTML+=dcfil e.getElementsBy TagName("subhea d")[0].nextSibling.fi rstChild.nodeVa lue;
}
Thank you, Dante.