Jquery reads and parses XML

Source: Internet
Author: User

Jquery: jquery-1.4.2.min.js

 

You must use IIS to run properly.

 

Demo.html

Code

< HTML xmlns = " Http://www.w3.org/1999/xhtml " >

<Head>

< Meta HTTP - Equiv = " Content-Type " Content = " Text/html; charset = GBK "   / >

< Title > Stripingtable < / Title>
< Script SRC = " Jquery-1.4.2.min.js " Type = " Text/JavaScript " > < / SCRIPT>

< Script Type = " Text/JavaScript " >

$ (Document). Ready ( Function (){
$. Get ( ' Mydata. xml ' , Function (D ){

$ ( ' Body ' ). Append ( ' <H1> Saturn recommends several books to you: ' );
$ ( ' Body ' ). Append ( ' <DL/> ' );

$ (D). Find ('Book'). Each (Function(){

VaR $ Book = $ ( This );
VaR Title = $ Book. ATTR ( " Title " );
VaR Description = $ Book. Find ( ' Description ' ). Text (); // The field content is read here
VaR Imageurl = $ Book. ATTR ( ' Imageurl ' ); // Here is the attribute value of the read Field

VaR Html =   ' <DT> '   + Imageurl +   ' "/> </DT> ' ;
Html + =   ' <DD> <SPAN class = "loadingpic" alt = "loading"/> ' ;
Html + =   ' <P class = "title"> '   + Title +   ' </P> ' ;
Html + =   ' <P> '   + Description +   ' </P> ' ;
Html + =   ' </DD> ' ;

$ ('DL'). Append ($ (HTML ));

$ ('. Loadingpic'). Fadeout (2000);
});
});
});

< / SCRIPT>
< / Head>

< Body >
< Div >
< Div ID = " Info " > < / Div>
< / Bdoy>

< / HTML>

 

 

Mydata. xml

Code

<? XML version = "1.0" encoding = "UTF-8" ?>
< Book >
< Book Title = "Tibetan password" Imageurl = "Images/tibet_code.jpg" >
< Description >
Here is a book Introduction
</ Description >
</ Book >

< Book Title = "Cambridge IELTS 6" Imageurl = "Images/ielts.jpg" >
< Description >
Here is a book Introduction
</ Description >
</ Book >

< Book Title = "Professional ASP. NET" Imageurl = "Images/asp.jpg" >
< Description >
Here is a book Introduction
</ Description >
</ Book >
</ Book >  

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.