+if ($isXml) {
+ $xmlDoc = new DOMDocument();
+ $root = $xmlDoc->appendChild($xmlDoc->createElement("nodes"));
+ foreach ($nodes as $node) {
+ $xmlNode = $root->appendChild($xmlDoc->createElement("node"));
+ $xmlNode->appendChild($xmlDoc->createElement("text", $node['text']));
+ $xmlNode->appendChild($xmlDoc->createElement("id", $node['id']));
+ $xmlNode->appendChild($xmlDoc->createElement("cls", $node['cls']));
+ $xmlNode->appendChild($xmlDoc->createElement("leaf", isset($node['leaf'])));
+ }
+ header("Content-Type: text/xml");
+ $xmlDoc->formatOutput = true;
+ echo $xmlDoc->saveXml();
+} else {
+ echo json_encode($nodes);
+}
\ No newline at end of file