English 中文(简体)
Javacast and XML Dom - Nest 洛普
原标题:JavaScript and XML Dom - Nested Loop

因此,I m astartner in XML DOM and Javagust,但我已陷入一个问题。 在现有网站上的表格中显示我的XML数据。 问题在于在我的 Java成文法中nes一 lo。

这里是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<book_list>
  <author>
    <first_name>Mary</first_name>
    <last_name>Abbott Hess</last_name>
      <books>
        <title>The Healthy Gourmet Cookbook</title>
      </books>
  </author>
  <author>
    <first_name>Beverly</first_name>
    <last_name>Bare Bueher</last_name>
      <books>
        <title>Cary Grant: A Bio-Bibliography</title>
        <title>Japanese Films</title>
      </books>
  </author>
  <author>
    <first_name>James P.</first_name>
    <last_name>Bateman</last_name>
      <books>
        <title>Illinois Land Use Law</title>
      </books>
  </author>
</book_list>

我随后将 Java本成文读成并显示数据:

> <script type="text/javascript"> if
> (window.XMLHttpRequest)   {  
> xhttp=new XMLHttpRequest();   } else
> // Internet Explorer 5/6   {  
> xhttp=new
> ActiveXObject("Microsoft.XMLHTTP");  
> } xhttp.open("GET","books.xml",false);
> xhttp.send("");
> xmlDoc=xhttp.responseXML;
> 
> document.write("<table>"); var
> x=xmlDoc.getElementsByTagName("author");
> for (i=0;i<x.length;i++)   {  
> document.write("<tr><td>");  
> document.write(x[i].getElementsByTagName("first_name")[0].childNodes[0].nodeValue);
> document.write("&nbsp;");  
> document.write(x[i].getElementsByTagName("last_name")[0].childNodes[0].nodeValue);
> document.write("</td><td>");  
> document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
> document.write("</td></tr>");   }
> document.write("</table>"); </script>

该法典运作良好,但只归还每个作者的第一个所有权要素。 我在一定程度上理解为什么会这样做,但我不知道,如果该书的印本显示作者的所有头衔,而不仅仅是第一种,那么如何打上另一种 lo。 每当我试图打上一只 lo子时,就打破了整个文字。

问题回答
getElementsByTagName("title")[0].childNodes[0].nodeValue

因此。 你们只有第一任。 用于生成<条码>i的另一种途径

My tip: use jquery and write Your code in 3 lines without problems like that.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签