Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have my server return XML and then parse it with jQuery:</p> <p>PHP (you'd have to translate this to ASP, of course):</p> <pre><code>$dom = new DOMImplementation(); $document = $dom-&gt;createDocument(); $document-&gt;formatOutput = true; $document-&gt;preserveWhitespace = true; $functionResult = $document-&gt;createElement('FunctionResult'); $document-&gt;appendChild($functionResult); $functionStatus = $document-&gt;createElement('FunctionStatus'); $functionResult-&gt;appendChild($functionStatus); $ingredients = $document-&gt;createElement('Ingredients'); $functionResult-&gt;appendChild($ingredients); $ingredient = $document-&gt;createElement('Ingredient'); $ingredients-&gt;appendChild($ingredient); $success = true; $message = 'Request successful; '; $functionStatus-&gt;setAttribute('function', $function); $functionStatus-&gt;setAttribute('success', $success); $functionStatus-&gt;setAttribute('message', addslashes($message)); // Now respond to the requestor Header("Content-type: text/xml", 1); robLog("\nAjax result:\n" . stripslashes($document-&gt;saveXML()), false, true); echo $document-&gt;saveXML(); </code></pre> <p>Give you XML like this:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;FunctionResult&gt; &lt;FunctionStatus function="getIngredients" success="1" message="Request successful"/&gt; &lt;Ingredients&gt; &lt;Ingredient&gt; ... &lt;/Ingredient&gt; &lt;/Ingredients&gt; &lt;/FunctionResult&gt; </code></pre> <p>Which you can parse like this:</p> <pre><code>$('Ingredient', xml).each(function() { var ingredientDescriptor = {}; $.each(this.attributes, function(i, attribute) { var name = attribute.name; var value = attribute.value; ingredientDescriptor[name] = value; }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload