Jump to content

How can I access child nodes by attribute check?


xcandiottix

Recommended Posts

I have an XML document as so:

<Tab>

<Name N="Private Tab">

<Cell>

<Application>X01</Application>

</Cell>

<Cell>

<Application>X02</Application>

</Cell>

<Cell>

<Application>X03</Application>

</Cell>

</Name>

</Tab>

<Name N="Public Tab">

<Cell>

<Application>X01</Application>

</Cell>

<Cell>

<Application>X02</Application>

</Cell>

<Cell>

<Application>X03</Application>

</Cell>

</Name>

</Tab>

 

I have a javascript that creates 2 input buttons for each Name N="" like so:

 

[Private Tab] [Public Tab]

 

Now, when I click on Private Tab I wan to access the Nodes of the Private Tab and extract the data. So far I have had no luck. Any thoughts?

 

document.write("<table border='1'><tr>");

var x=xmlDoc.getElementsByTagName("Tab");

for (i=0;i<x.length;i++){

document.write("<td>");

document.write('<input type="button" onClick="selection(\'')

document.write(x[the letter i].getElementsByTagName("Name")[0].getAttribute("N"));

document.write('\')" value="');

document.write(x[the letter i].getElementsByTagName("Name")[0].getAttribute("N"));

document.write('"/>');

  document.write("</td>");

}

document.write("</tr></table>");

 

function selection(selected){

txt2=xmlDoc.getElementsByTagName("Name")[0].getElementsByTagName("Cell")[0].getElementsByTagName("Application")[0].childNodes[0].nodeValue;

document.getElementById("select").innerHTML=txt2;

//end

}

document.write("<div id='select'></div>");

 

This code works and gives a value of X01 if I click either button. If I click on Public Tab it will not switch to X11.

 

Any help is appreciated!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.