Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   XML Document Node Names (http://www.velocityreviews.com/forums/t874521-xml-document-node-names.html)

Dante 12-13-2003 07:40 PM

XML Document Node Names
 
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.getElementsByTagName("subhead")[0].firstChild.nodeName
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: dcsml@sfhe.cjb.net
*/
if (location.search.indexOf("=") > 2) {
file = location.search.substring(location.search.indexOf( "=")+1);
}
else {
file="apple.xml";
}
function getDCSML() {
if (document.implementation && document.implementation.createDocument)
{
dcfile = document.implementation.createDocument("", "", null);
dcfile.onload = createDisplay;
}
else if (window.ActiveXObject)
{
dcfile = new ActiveXObject("Microsoft.XMLDOM");
dcfile.onreadystatechange = function () {
if (dcfile.readyState == 4) createDisplay()
};
}
else
{
alert('Your browser can\'t handle DCSML. Too bad.');
return;
}
dcfile.load(file);
}
function createDisplay()
{
var x = dcfile.getElementsByTagName("DCSML")[0];
var atext = dcfile.getElementsByTagName("Link")[0];
var htext = dcfile.getElementsByTagName("Header")[0];
var ahtext = dcfile.getElementsByTagName("AltHeader")[0];
var pic = dcfile.getElementsByTagName("pic")[0];
var sub = dcfile.getElementsByTagName("subhead")[0];
/*what= new Array();
for (var c=0;x<x.childNodes.length;c++)
{
what[c] = x.childNodes[1].firstChild.nodeValue;
alert(what[c]);
}*/
var othertags = x.childNodes;
var url = atext.getAttribute("URL");
//Below is a list of valid DCSML tags
var tags = new Array("DCSML","Header","AltHeader","Link","pic","s ubhead");
var makeLink = document.createElement("A");
makeLink.href = url;
var makeHeader = document.createElement("H1");
var makeAH = document.createElement("H2");
makeHeader.style.color="#CD853f";
makeAH.style.color="#CD853F";
var mahtext = document.createTextNode(ahtext.firstChild.nodeValu e);
makeAH.appendChild(mahtext);
var mhtext = document.createTextNode(htext.firstChild.nodeValue );
makeHeader.appendChild(mhtext);
var txt = document.createTextNode(atext.firstChild.nodeValue );
makeLink.appendChild(txt);
var img = document.createElement("IMG");
img.src = pic.getAttribute("url");
var p = document.createElement("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.length;i++)
{
var checktags = dcfile.getElementsByTagName(tags[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.appendChild(makeHeader);
document.body.appendChild(makeAH);
document.body.appendChild(makeLink);
document.body.innerHTML+="<p></p>";
document.body.appendChild(img);
document.body.appendChild(p);
document.body.innerHTML+='<span style="font-size: 13pt; font-family:
verdana; font-weight:

normal; text-align: left; color: #666666; letter-spacing:
1.2px;">'+mtxt+'</span><br>';
document.body.innerHTML+=dcfile.getElementsByTagNa me("subhead")[0].nextSibling.firstChild.nodeValue;
}

Thank you, Dante.

VK 12-13-2003 09:03 PM

Re: XML Document Node Names
 
I think more important to see the source document your are scripting
with. Can you post <subhead> block's foo with a couple of lines above
and below?



Paul 12-13-2003 10:08 PM

Re: XML Document Node Names
 

> dcfile.getElementsByTagName("subhead")[0].firstChild.nodeName


the name of the node is #text (because the first child is a
text-node), I think you want the value, try .nodeValue :)

Paul




Dante 12-14-2003 04:15 AM

Re: XML Document Node Names
 
nope. nodeValue gives the text inside the tag. I solved the problem:
dcfile.getElementsByTagName("subhead")[0].nodeName gives what I want.

Thanks anyway.

Thomas 'PointedEars' Lahn 12-14-2003 08:47 PM

Re: XML Document Node Names
 
Dante wrote:

> nope. nodeValue gives the text inside the tag.


You meant it retrieves the text content of the element. Inside a <tag>
are the tag name, optional attribute identifiers and (depending on the
markup language) optional values, and special punctuators like `=' and
`/'.


PointedEars


All times are GMT. The time now is 05:23 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.