`
boogie
  • 浏览: 235605 次
  • 性别: Icon_minigender_1
  • 来自: 宁波
社区版块
存档分类
最新评论

Reading XML with jQuery

    博客分类:
  • AJAX
阅读更多

1、sites.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<sites>
   <site id="0">
     <title>Think2Loud</title>
	<url>http://www.think2loud.com</url>
     <desc>
       <brief>this is the brief description.</brief>
       <long>...and this is the long description.  See how long it is :)</long>
     </desc>
   </site>
   <site id="2">
     <title>jaredharbour.com</title>
	<url>http://www.jaredharbour.com</url>
     <desc>
       <brief>this is the brief description.</brief>
       <long>...and this is the long description.  See how long it is :)</long>
     </desc>
   </site>
   <site id="3">
     <title>Css Tricks</title>
	<url>http://www.css-tricks.com</url>
     <desc>
       <brief>this is the brief description.</brief>
       <long>...and this is the long description.  See how long it is :)</long>
     </desc>
   </site>
 </sites>

 

2、code

$(document).ready(function(){
	$.ajax({
		type: "GET",
		url: "sites.xml",
		dataType: "xml",
		success: function(xml) {
			$(xml).find('site').each(function(){
				var id = $(this).attr('id');
				var title = $(this).find('title').text();
				var url = $(this).find('url').text();
				$('<div class="items" id="link_'+id+'"></div>').html('<a href="'+url+'">'+title+'</a>').appendTo('#page-wrap');
				$(this).find('desc').each(function(){
					var brief = $(this).find('brief').text();
					var long = $(this).find('long').text();
					$('<div class="brief"></div>').html(brief).appendTo('#link_'+id);
					$('<div class="long"></div>').html(long).appendTo('#link_'+id);
				});
			});
		}
	});
});
 

 

分享到:
评论

相关推荐

    processing xml with java

    Preface Acknowledgements 1 XML for Data 2 XML Protocols 3 Writing XML with Java 4 Converting Flat Files to XML 5 Reading XML 6 SAX 7 The XMLReader Interface 8 SAX ...

    jQuery阅读时间插件Reading Time

    **jQuery阅读时间插件Reading Time详解** jQuery Reading Time 是一个实用的JavaScript插件,它能够自动计算并显示文章或文本的预计阅读时间。这个插件适用于博客、新闻网站或者任何包含大量文字内容的网页,可以...

    Beginning XML with C# 2008: From Novice to Professional

    With this book, you’ll learn everything you need to know from the basics of reading and writing XML data to using the DOM, from LINQ and SQL Server integration to SOAP and web services. What you’...

    jQuery-reading:通过jquery分析和源码解读更好的掌握原生的JS

    jQuery分析 初心:希望通过对jQuery这个前端经典库的解释,从而更好地掌握掌握原生的JS各种DOM操作,并继续学习一些jQuery中优雅的封装技巧和重构思路

    Installing mini-xml along with a sample code

    Mini-XML supports reading of UTF-8 and UTF-16 and writing of UTF-8 encoded XML files and strings. Data is stored in a linked-list tree structure, preserving the XML data hierarchy, and arbitrary ...

    Prentice.Hall.C++.GUI.Programming.with.Qt.4.2nd.Edition.2008.chm

    Reading XML with QXmlStreamReader Reading XML with DOM Reading XML with SAX Writing XML Chapter 17. Providing Online Help Tooltips, Status Tips, and "What's This?" Help Using a Web ...

    perl program for xml simple reading

    在这个场景中,"perl program for xml simple reading" 指的是用Perl编写一个程序来解析XML文件,特别是使用`XML::Simple`模块。描述中提到这是个调试版本,意味着代码可能还存在一些问题,需要进一步优化和改进。 ...

    jquery filterizr图片列表筛选插件附教程链接

    **jQuery Filterizr 图片列表筛选插件详解** Filterizr是一款基于jQuery的强大的图像过滤和排序插件,它允许用户在网页上实现优雅的图片列表筛选效果。通过使用这个插件,开发者可以为网站添加交互性,使用户能够...

    jquery.i18n.properties.min.js

    jquery.i18n.properties.min.js

    python and xml

    Describes the lxml package for reading and writing XML files with the Python programming language.

    Reading Geospatial Raster files with GDAL(使用GDAL读取地理空间栅格文件).zip

    本文件包含了我在linux下学习opencv Reading Geospatial Raster files with GDAL(使用GDAL读取地理空间栅格文件)中的学习笔记,遇到的bug以及最重要,比较难转换的tif文件

    jQuery in Action 2008

    This book is aimed at getting you up and running with jQuery quickly and effectively and, hopefully, having some fun along the way. The entire core jQuery API is discussed, and each API method is ...

    Programming.Microsoft.SQL.Server.2000.with.XML

    If you have no working experience with XML, you should read the appendix, "Introduction to XML," before reading the rest of the book. The appendix will familiarize you with basic XML knowledge that ...

    10个很棒的jquery mobile插件

    5. **jQuery Mobile with Google Map** - 结合了 jQuery Mobile 和 Google Maps API,使得在移动应用中集成地图功能变得更加简单。 6. **Photoswipe** - 这是一个轻量级的图片查看器插件,特别适合于在移动设备上...

    XML and Web Technologies for Data Sciences with R

    Along with these general skills, the authors illustrate several applications that are relevant to data scientists, such as reading and writing spreadsheet documents both locally and via Google Docs, ...

    读写XML文件实例 Javascript

    console.error('Error reading XML:', err); return; } // 解析XML为JavaScript对象 xml2js.parseString(data, (err, result) =&gt; { if (err) { console.error('Error parsing XML:', err); return; } //...

    C#动态加载XML文件,并更改节点属性值

    Console.WriteLine($"Error occurred while reading or writing: {ex.Message}"); } ``` 在这个过程中,理解XPath(XML路径语言)也可以帮助更高效地定位XML节点。XPath是用于在XML文档中查找信息的语言,尽管在C#...

    DIXML v5.9.0 for D6-XE10.1 XML XSLT EXSLT 解析

    XML and HTML reading and writing, pull and push parser modes. XML and HTML document tree creation, traversal, load, and save. SAX and extended reader interfaces. DTD and schema validation. Encoding ...

    使用C++处理XML

    std::cerr &lt;&lt; "Error reading XML file" ; } xmlFreeTextReader(reader); } int main() { parseXML("your_xml_file.xml"); return 0; } ``` 此代码片段展示了如何逐节点读取XML文档,并打印出元素节点的信息...

    城市选择器代码 - jquery

    在本案例中,我们讨论的是一个基于jQuery实现的城市选择器,其特点是采用浅绿色调,给人一种温和的感觉,因此特别适合集成到大型项目中。 jQuery是一个强大的JavaScript库,它简化了HTML文档遍历、事件处理、动画...

Global site tag (gtag.js) - Google Analytics