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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.