473,654 Members | 3,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.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.
Jul 20 '05 #1
4 2034
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.getEleme ntsByTagName("s ubhead")[0].firstChild.nod eName


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.getEleme ntsByTagName("s ubhead")[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
1850
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/" xmlns:e="urn:schemas:httpmail:" xmlns:d="urn:schemas:mailheader:" xmlns:c="xml:" xmlns:f="urn:schemas-microsoft-com:office:office" xmlns:a="DAV:"> <a:response> <a:href>SomeData/a:href>
13
9605
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 assigned to a variable and output using document.write. (Note, there is no submit button or other form elements. Basically
4
5012
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 returns the required child nodes from the document, but am struggling to find a good statergy for recreating the file Here is an excert of my XML file <resource_data><planets><planet...
5
17654
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 you do that? Regards Paw
3
1477
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> </Object> <Object Type="Type2"> <Attribute_A>ValueA</Attribute_A>
2
7839
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 framework 1.1). I've successfully loaded the document into a XmlDocument DOM parser (I can dump the contents using OuterXML). And, I've created a XmlNamespaceManager and assigned it the "w" namespace.
7
2402
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) { while (node.ParentNode != null) { node = ParentNode; } return node == node.OwnerDocument; }
10
8791
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: org.w3c.dom.DOMException: NOT_SUPPORTED_ERR: The implementation does not support the requested type of object or operation. at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source) at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source)
2
2652
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 this discussion. Thank you. The first step of parsing an XML document is to import the DOM API related classes such as :- java.io.* which contains all the interfaces to perform an I/O operation. org.xml.sax.* which contains all the interfaces...
0
1063
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 levels like so: <node attr1="blahblah" attr2="blahblahblahblah"> <node attr1="flufffluff" attr2="shshshshsh"> <node attr1="cluckcluck" attr2="naynaynay" /> <node attr1="chillaladolads" attr2="lasfojelajdfljalsdf" /> <node attr1="eoijoawelkjladsf"...
0
8815
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8708
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8489
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8594
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1596
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.