Parse the XML sample code using jquery

  • 2020-03-30 03:54:02
  • OfStack

XML file structure :books.xml

<?xml version="1.0" encoding="UTF-8"?>
<book id="1">
<name> A simple extjs</name>
<author> Zhang SAN </author>
<book id="2">
<name> The sharp jQuery</name>
<author> Li si </author>
<book id="3">
<name> A simple flex</name>
<author> Cathy </author>
<book id="4">
<name>java Programming ideas </name>
<author> Money for seven </author>

Page code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jquery parsing xml</title>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
//Find all the book nodes
var s="";
var id=$(this).attr('id');
var name=$(this).children('name').text();
var author=$(this).children('author').text();
var price=$(this).children('price').text();
s+=id+"    "+name+"    "+author+"    "+price+"<br>";
<div id='mydiv'></div>


Related articles: