473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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: dc***@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.
Jul 20 '05 #1
4 2018
VK
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?
Jul 20 '05 #2
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

Jul 20 '05 #3
nope. nodeValue gives the text inside the tag. I solved the problem:
dcfile.getElementsByTagName("subhead")[0].nodeName gives what I want.

Thanks anyway.
Jul 20 '05 #4
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
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ron Harter | last post by:
I have an XML DOM that contains a response from a server it looks somethng like this: <?xml version="1.0"?> <a:multistatus xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
4
by: Jim | last post by:
Hi I'm looking to take an existing XML document, query for certain nodes, and 'recreate' the document with just the relevant nodes. I'm currently using XPath - I have established the pattern that...
5
by: Paw Pedersen | last post by:
Is it possible to load a XSD and loop throw the nodes and attributes that you whant filled out, and then generate a XML instance with the trees and data that you have filled data in? And how do...
3
by: dmc | last post by:
Can anyone suggest an elegant solution for this problem? I have a source document as follows: <Object Type="Type1"> <Attribute_A>ValueA</Attribute_A> <Attribute_B>ValueB</Attribute_B>...
2
by: Andy | last post by:
Hi, I have an XML document that uses namespaces (it is from a Word 2007 file). I want to retrieve all the "t" elements that belong to the "w" namespace (<w:t>) using XPath from VB.NET 2003 (.NET...
7
by: martinfrompi | last post by:
I have a container of XmlNodes. Some of them have been removed from the document, some haven't. Is there an easy way to tell which are which? I suppose bool IsPartOfTree(XmlNode node) {...
10
by: Simon Brooke | last post by:
The DOM API has included public Node importNode(Node,boolean) as a method of the Document interface for a long time. Does anything actually implement it? Xerces 2 is giving me: ...
2
by: nicky123 | last post by:
Hi everyone, This is a brief description that I have provided for parsing & displaying an XML document using DOM API. Please feel free to post your own comments & views regarding...
0
by: gnewsgroup | last post by:
I need to bind *some* nodes of an xml document to an asp.net Menu control. The problem is that the XML document uses the same node name and attribute name for for the entire document among all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.