Ниже приведен пример XML кода
<?xml version="1.0" encoding="utf-8" ?>
|
|
|
<Title>My Cool Book Title</Title> |
|
|
<Description>The my cool book is possibly the best cool book in that any developer could use to be a great web designer.</Description> |
|
|
<Title>Another PHP book</Title> |
|
|
<Description>Learn everything about PHP with 'Another PHP book,' your ultimate guide to the ins and outs of PHP.</Description> |
|
|
<Title>jQuery Techniques</Title> |
|
|
<Description>jQuery techniques runs you through real life examples of jQuery from beginner to expert</Description> |
|
|
<Title>MySQL Database Book</Title> |
|
|
<Description>Brush up your knowledge with the best MySQL database book on the market.</Description> |
Чтобы распарсить XML файл, необходимо сделать AJAX запрос.
Важно помнить, что если вы хотите делать кросдоменные AJAX запросы, то нужно использовать JSONP. И после этого воспользоваться методом .find(), для того чтобы добраться до нужного элемента.
$(document).ready(function () {
|
|
|
function xmlParser(xml) { |
|
|
$(xml).find("Book").each(function () { |
|
|
$(".main").append('<div><div>' + $(this).find("Title").text() + '</div><div>' + $(this).find("Description").text() + '</div><div>Published ' + $(this).find("Date").text() + '</div></div>'); |
Содержимое XML файла будет записано в блоке с классом .main.
|
<divalign="center"class="loader"><imgsrc="loader.gif"id="load"width="16"height="11"align="absmiddle"/></div> |
|
<div class="clear"></div> |