XML Document Node Names

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dante

    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: dcsml@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.
  • VK

    #2
    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?


    Comment

    • Paul

      #3
      Re: XML Document Node Names

      [color=blue]
      > dcfile.getEleme ntsByTagName("s ubhead")[0].firstChild.nod eName[/color]

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

      Paul



      Comment

      • Dante

        #4
        Re: XML Document Node Names

        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.

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: XML Document Node Names

          Dante wrote:
          [color=blue]
          > nope. nodeValue gives the text inside the tag.[/color]

          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

          Comment

          Working...