1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with Java and DOM

Discussion in 'JavaScript' started by bobulos, Apr 2, 2007.

  1. #1
    Hi,

    I am a newbie (ish) to JavaScript. I need to parse an xml file and output the node names, values and attributes. I have the node names and values outputting ok but am having trouble finding what code I should use to output the attributes. Do I use getAttribute or getAttributeNode, any help would be most appreciated.


    function printTheElement(indent, node) {
    var i;
    if (node.nodeType == 3) {
    document.write("<br />Text Value" +indent + node.nodeValue);


    }
    else {
    document.write("<br />Start Node" +indent + "[" + node.nodeName + "]");


    for (i = 0; i < node.childNodes.length; i++) {
    printTheElement(indent+tab, node.childNodes);
    }

    document.write("<br />End Node" +indent + "[/" + node.nodeName + "]");
    }


    }



    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
    xmlDoc.async="false"
    xmlDoc.load("test.xml")

    printTheElement("", xmlDoc.documentElement);
     
    bobulos, Apr 2, 2007 IP
  2. bobulos

    bobulos Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ok I managed to resolve this by looking at the w3c DOM web site
     
    bobulos, Apr 3, 2007 IP