admin管理员组文章数量:1289528
I'm trying to iterate through a DOM elements children and display their attributes in my code:
document.write("<table border='1'>");
var testcaseiterator = xmlDoc.getElementsByTagName("TestCase")[1].childNodes;
for(i=0; i < testcaseiterator.length; i++){
document.write("<tr><td>");
document.write(testcaseiterator[i].getAttribute('name'));
document.write("</td></tr>");
}
document.write("</table>");
My XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="XSLTOutput2.xsl"?>
<TestSuite>
<ActiveStep case="6" step="14" />
<TestCase name="Visit all buttons [in region Button: Navi 0]">
<Verification type="screen" id="1e542f75-1ba2-482d-8edd-39f70620d6dd" status="">
<screen widgetid="audio_radio_fm">
<menu entryStrategy="FIRST" looped="false" orientation="HORIZONTAL" selectable="true" widgetid="status">
<entry selectable="true" widgetid="status" widgettype="entry">
<label widgetid="status_label">status</label>
</entry>
</menu>
<menu entryStrategy="SECOND" looped="false" orientation="HORIZONTAL" selectable="true" widgetid="apl">
<button selectable="true" widgetid="apl_navi" widgettype="button">
<label widgetid="apl_navi_label">Navi</label>
</button>
<button selectable="true" widgetid="apl_audio" widgettype="button">
<label widgetid="apl_audio_label">Audio</label>
</button>
<button selectable="true" widgetid="apl_tel" widgettype="button">
<label widgetid="apl_tel_label">Tel</label>
</button>
<button selectable="true" widgetid="apl_video" widgettype="button">
<label widgetid="apl_video_label">Video</label>
</button>
<button selectable="true" widgetid="apl_system" widgettype="button">
<label widgetid="apl_system_label">System</label>
</button>
<button selectable="true" widgetid="apl_net" widgettype="button">
<img src="img/apl_net.png" widgetid="apl_net_image" />
</button>
</menu>
<menu entryStrategy="FIRST" looped="false" orientation="HORIZONTAL" selectable="true" widgetid="plf">
<entry selectable="true" widgetid="playfield" widgettype="entry">
<label widgetid="playfield_label">playfield</label>
</entry>
</menu>
<menu entryStrategy="MIDDLE" looped="false" orientation="HORIZONTAL" selectable="true" widgetid="audio_radio_sfl">
<button selectable="true" widgetid="audio_radio_sfl_radio" widgettype="button">
<label widgetid="audio_radio_sfl_radio_label">Radio</label>
</button>
<button selectable="true" widgetid="audio_radio_sfl_presets" widgettype="button">
<label widgetid="audio_radio_sfl_presets_label">Presets</label>
</button>
<button selectable="true" widgetid="audio_radio_sfl_info" widgettype="button">
<label widgetid="audio_radio_sfl_info_label">Info</label>
</button>
<button selectable="true" widgetid="audio_radio_sfl_fm" widgettype="button">
<label widgetid="audio_radio_sfl_fm_label">FM</label>
</button>
<button selectable="true" widgetid="audio_radio_sfl_sound" widgettype="button">
<label widgetid="audio_radio_sfl_sound_label">Sound</label>
</button>
</menu>
</screen>
</Verification>
<Verification optionID="Audio" type="focus" id="d713b58b-06b1-4274-9a79-fe90a071383c" status="" />
<Command type="cce:left" id="3a591a3c-9b9f-41a7-9b50-0892197128ec" status="" />
<Verification optionID="Navi" type="focus" id="6037419a-25ae-4a7f-b842-0e88df9dfe4c" status="" />
</TestCase>
This is not working: Any ideas?
I'm trying to iterate through a DOM elements children and display their attributes in my code:
document.write("<table border='1'>");
var testcaseiterator = xmlDoc.getElementsByTagName("TestCase")[1].childNodes;
for(i=0; i < testcaseiterator.length; i++){
document.write("<tr><td>");
document.write(testcaseiterator[i].getAttribute('name'));
document.write("</td></tr>");
}
document.write("</table>");
My XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="XSLTOutput2.xsl"?>
<TestSuite>
<ActiveStep case="6" step="14" />
<TestCase name="Visit all buttons [in region Button: Navi 0]">
<Verification type="screen" id="1e542f75-1ba2-482d-8edd-39f70620d6dd" status="">
<screen widgetid="audio_radio_fm">
<menu entryStrategy="FIRST" looped="false" orientation="HORIZONTAL" selectable="true" widgetid="status">
<entry selectable="true" widgetid="status" widgettype="entry">
<label widgetid="status_label">status</label>
</entry>
</menu>
<menu entryStrategy="SECOND" looped="false" orientation="HORIZONTAL" selectable="true" widgetid="apl">
<button selectable="true" widgetid="apl_navi" widgettype="button">
<label widgetid="apl_navi_label">Navi</label>
</button>
<button selectable="true" widgetid="apl_audio" widgettype="button">
<label widgetid="apl_audio_label">Audio</label>
</button>
<button selectable="true" widgetid="apl_tel" widgettype="button">
<label widgetid="apl_tel_label">Tel</label>
</button>
<button selectable="true" widgetid="apl_video" widgettype="button">
<label widgetid="apl_video_label">Video</label>
</button>
<button selectable="true" widgetid="apl_system" widgettype="button">
<label widgetid="apl_system_label">System</label>
</button>
<button selectable="true" widgetid="apl_net" widgettype="button">
<img src="img/apl_net.png" widgetid="apl_net_image" />
</button>
</menu>
<menu entryStrategy="FIRST" looped="false" orientation="HORIZONTAL" selectable="true" widgetid="plf">
<entry selectable="true" widgetid="playfield" widgettype="entry">
<label widgetid="playfield_label">playfield</label>
</entry>
</menu>
<menu entryStrategy="MIDDLE" looped="false" orientation="HORIZONTAL" selectable="true" widgetid="audio_radio_sfl">
<button selectable="true" widgetid="audio_radio_sfl_radio" widgettype="button">
<label widgetid="audio_radio_sfl_radio_label">Radio</label>
</button>
<button selectable="true" widgetid="audio_radio_sfl_presets" widgettype="button">
<label widgetid="audio_radio_sfl_presets_label">Presets</label>
</button>
<button selectable="true" widgetid="audio_radio_sfl_info" widgettype="button">
<label widgetid="audio_radio_sfl_info_label">Info</label>
</button>
<button selectable="true" widgetid="audio_radio_sfl_fm" widgettype="button">
<label widgetid="audio_radio_sfl_fm_label">FM</label>
</button>
<button selectable="true" widgetid="audio_radio_sfl_sound" widgettype="button">
<label widgetid="audio_radio_sfl_sound_label">Sound</label>
</button>
</menu>
</screen>
</Verification>
<Verification optionID="Audio" type="focus" id="d713b58b-06b1-4274-9a79-fe90a071383c" status="" />
<Command type="cce:left" id="3a591a3c-9b9f-41a7-9b50-0892197128ec" status="" />
<Verification optionID="Navi" type="focus" id="6037419a-25ae-4a7f-b842-0e88df9dfe4c" status="" />
</TestCase>
This is not working: Any ideas?
Share Improve this question edited Sep 16, 2014 at 16:15 Nakilon 35.1k16 gold badges111 silver badges147 bronze badges asked May 21, 2013 at 14:33 Hans EnHans En 9265 gold badges15 silver badges32 bronze badges 3- 1 How is it not working? What is happening? Are there errors on the console? – James Montagne Commented May 21, 2013 at 14:34
- No errors in the browser. The table just does not show up. If I just write a String in the document.write() then it prints a few lines with my String. Not in the correct number though. – Hans En Commented May 21, 2013 at 14:35
-
Do you have
document.write("<table>")
anywhere? – bfavaretto Commented May 21, 2013 at 14:37
1 Answer
Reset to default 5var testcaseiterator = xmlDoc.getElementsById("tc").childNodes;
The rest of the code looks okay.
for(i=0; i < testcaseiterator.length; i++)
{
document.write("<tr><td>");
document.write(testcaseiterator[i].getAttribute('name'));
document.write("</td></tr>");
}
document.write("</table>")
You will also have to edit the 5th line of the XML,
<TestCase id ="tc" name="Visit all buttons [in region Button: Navi 0]">
This will only work if you XML in your DOM structure.
本文标签: htmlHow can I iterate through an Elements child nodes using JavascriptStack Overflow
版权声明:本文标题:html - How can I iterate through an Elements child nodes using Javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741464522a2380232.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论