简体   繁体   English

使用Javascript解析XML

[英]Parsing XML using Javascript

I want to access XML elements in the following document. 我想访问以下文档中的XML元素。 There about 935 items AircraftReport. 大约有935项AircraftReport。 I know how to display all of them by using .find() and .each() but I am having trouble getting only the first 10 AircraftReports. 我知道如何使用.find().each()来显示所有这些信息,但是我很难仅获取前10个AircraftReports。

<response>
<data num_results="935">
<AircraftReport>
     <latitude>50.5</latitude>
     <longitude>-51.8</longitude>
</AircraftReport>
<AircraftReport>
     <latitude>55.9167</latitude>
     <longitude>-43.1</longitude>
</AircraftReport>
....
</data>
</response>

I am assuming I have to write that in a for loop. 我假设我必须在for循环中编写该代码。 How can this be done with jQuery? jQuery如何做到这一点?

There are 2 ways to solve this problem... the first is to enhance the server side code to support paging where by the server will send only 10 items per request with corresponding paging details... 有两种方法可以解决此问题...第一种是增强服务器端代码以支持分页,其中服务器每次请求将仅发送10个项目以及相应的分页详细信息...

Another is to do it in the client side using slice() 另一种方法是使用slice()在客户端进行

$(this).find("AircraftReport").slice(0, 10).each(function(){...} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM