28 Oct

Parsing XML from JQuery

<!DOCTYPE html>
  <script src="http://code.jquery.com/jquery-latest.js"></script>

<p id="someElement"></p>
<p id="anotherElement"></p>

var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>",
    xmlDoc = $.parseXML( xml ),
    $xml = $( xmlDoc ),
    $title = $xml.find( "title" );

/* append "RSS Title" to #someElement */
$( "#someElement" ).append( $title.text() );

/* change the title to "XML Title" */
$title.text( "XML Title" );

/* append "XML Title" to #anotherElement */
$( "#anotherElement" ).append( $title.text() );


Baris 4: isi dengan path jquery sesuai dengan kebutuhan
Baris 12: contoh isi XML yang akan di parsing
Baris 13: parsing XML document dari JQuery
Baris 15: contoh pencarian element tertentu dalam XML (title)

Leave a Reply

Your email address will not be published. Required fields are marked *