<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>jQuery XML to JSON Plugin v1.0 (2008-07-03)</title>
<!--// documentation resources //-->
<script src='jquery.js' type="text/javascript"></script>
<script src='documentation.js' type="text/javascript"></script>
<link href='documentation.css' type="text/css" rel="stylesheet"/>
<!--// code-highlighting //-->
<script type="text/javaScript" src="/jquery/project/chili/jquery.chili-2.0.js"></script>
<!--///jquery/project/chili-toolbar/jquery.chili-toolbar.pack.js//-->
<script type="text/javascript">try{ChiliBook.recipeFolder="/jquery/project/chili/"}catch(e){}</script>
<!--// plugin-specific resources //-->
<script src='jquery.xml2json.js' type="text/javascript" language="javascript"></script>
<script src="testing.js" type="text/javascript" language="javascript"></script>
<style type="text/css">
.test-result{ font-size:97%; background:#f7f7f7; padding:3px 10px; border:#ccc solid 3px; height:250px; overflow:auto; }
.test-result ul{ margin:0 0 0 15px; }
</style>
</head>
<body>
<a name="top"></a>
<div id="wrap">
<div id="roof">
<a href="http://www.fyneworks.com/jquery/"><strong>jQuery Plugins</strong></a>:
<a href="http://www.fyneworks.com/jquery/multiple-file-upload/">Multiple File Upload</a>,
<a href="http://www.fyneworks.com/jquery/star-rating/">Star Rating</a>,
<strong>NEW:</strong>
<a href="http://www.fyneworks.com/jquery/FCKEditor/">CKEditor</a>
(old: <a href="http://www.fyneworks.com/jquery/FCKEditor/">FCKEditor</a>),
<a href="http://www.fyneworks.com/jquery/Codepress/">Codepress</a>,
<a href="http://www.fyneworks.com/jquery/xml-to-json/">XML to JSON</a>
<span style="position:absolute; right:0;">
<script type="text/javascript">digg_title='jQuery XML to JSON Plugin';</script>
<script type="text/javascript">digg_url='http://www.fyneworks.com/jquery/xml-to-json/';</script>
<script type="text/javascript">digg_bgcolor='#e7e7e7';digg_skin='compact';digg_window='new';</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
</span>
</div>
<div id="head">
<table width="100%" cellspacing="5">
<tr>
<td valign="middle">
<h1>jQuery XML to JSON Plugin</h1>
<span style="cursor:help; background:#C00; padding:2px; color:#FFF;" title="Current Version">
v<strong>1.0</strong>
</span>
</td>
<td valign="middle" width="450" align="right">
<div id="search" style="display:none">
<form action="http://www.google.com/cse" id="cse-search-box" target="_blank">
<label for="q">Find another jQuery plugin:</label>
<input type="hidden" name="cx" value="partner-pub-9465008056978568:j3ebzr-v1o0" />
<input type="hidden" name="ie" value="ISO-8859-1" />
<input type="text" name="q" id="q" size="20" />
<input type="submit" name="sa" value="Search" />
</form>
<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script>
</div>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="6856904">
<input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
</td>
</tr>
</table>
</div>
<div class="hint">
<span style="float:right">
See also: <a href="http://plugins.jquery.com/project/xmlObjectifier/">xmlObjectifier</a>
</span>
<strong>Hint</strong>:
use <a href="http://www.getfirefox.com/" target="_blank">Firefox</a>
with <a href="http://getfirebug.com/" target="_blank">Firebug</a> to
really see what's going on.
</div>
<div id="body">
<div id="ad"><a href="http://www.pinesandneedles.com/" target="_blank"><img src="http://www.pinesandneedles.com/U/fyneworks-ad.png" width="120" height="200" alt="FREE mistletoe with your Christmas tree" style="margin:0 0 40px 0;"/></a>
<!--//
<div id='vu_ytplayer_vjVQa1PpcFNzWL_xJNUOpZhjtZP7PE8aGHuLQqHHrFI='><a href='http://www.youtube.com/browse'>Watch the latest videos on YouTube.com</a></div>
<script type='text/javascript' src='http://www.youtube.com/watch_custom_player?id=vjVQa1PpcFNzWL_xJNUOpZhjtZP7PE8aGHuLQqHHrFI='></script>
//-->
<script type="text/javascript"><!--
google_ad_client = "pub-9465008056978568";
/* 120x600, created 25/11/09 */
google_ad_slot = "4176621808";
google_ad_width = 120;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div id="documentation" class="tabs">
<ul class="Clear">
<li><a href="#tab-Overview" id="btn-Overview">Overview</a></li>
<li><a href="#tab-Usage" id="btn-Usage">Usage</a></li>
<li><a href="#tab-Examples" id="btn-Examples">Examples</a></li>
<li><a href="#tab-Download" id="btn-Download">Download</a></li>
<li><a href="#tab-Support" id="btn-Support">Support</a></li>
<li><a href="#tab-License" id="btn-License">License</a></li>
</ul><!--// tabs //-->
<!--//
####################################
#
# * START CONTENT *
#
####################################
//-->
<div id="tab-Overview">
<h2>What is this?</h2>
<p>
The <strong>XML to JSON Plugin</strong> (<em>jQuery.xml2json</em>)
is a script you can use to convert simple XML into a JSON object.
</p>
<table width="100%">
<tr>
<td valign="top" width="50%">
<h3>Convert this...</h3>
<pre class="code"><code class="html"><xml>
<message>Hello world</message>
</xml></code></pre>
</td>
<td valign="top" width="50%">
<h3>...into this:</h3>
<pre class="code"><code class="js">{
message: 'Hello world';
}</code></pre>
</td>
</tr>
</table>
<h2>How does it work?</h2>
<table width="100%">
<tr>
<td valign="top" width="50%">
<h3>With XML in a string</h3>
<a href="javascript:;" onClick="eval($(this).next().text())">Click here to test this code</a>
<pre class="code"><code class="js">var xml = '<xml><message>Hello world</message></xml>';
var json = $.xml2json(xml);
alert(json.message);</code></pre>
</td>
<td valign="top" width="50%">
<h3>With XML loaded via Ajax</h3>
<a href="javascript:;" onClick="eval($(this).next().text())">Click here to test this code</a>
<pre class="code"><code class="js">$.get('data/hello.xml', function(xml){
var json = $.xml2json(xml);
alert(json.message);
});</code></pre>
</td>
</tr>
</table>
<h2>Why convert XML to JSON?</h2>
<p>
Those of you with a little more jQuery experience will know that
in simple cases (such as the above) we could use jQuery DOM traversing
functionality to achieve the same result without the need of a plugin:
</p>
<pre class="code"><code class="js"
>alert($('<xml><message>Hello world</message></xml>').find('message').text());</code></pre>
<div style="color:#006600">
<strong>Hint</strong>: you do not need this plugin if that's as complex as your XML will get.
</div>
<p>
<strong>However</strong>, jQuery's DOM traversing can soon become a little tiring
if...<br/>
A. you frequenly process XML responses from Ajax calls<br/>
B. you parse com