function addChildNode(SimpleXMLElement $parent, SimpleXMLElement $node) { $newchild = $parent->addChild($node->getName(), (string) $node); foreach ($node->attributes() as $name => $value) { $newchild->addAttribute($name, $value); } foreach ($node->children() as $child) { addChildNode($newchild, $child); } }
controlla se la matricola in fase di login è abilitata all'uso della applicazione e ne restituisce il profilo locale. */ require 'config.php'; $query = "select * from kb_users where matricola ='" . $_GET["m"] . "'"; $result = mysqli_query($connection, $query); $array[] = $result->fetch_array(MYSQLI_ASSOC); // record univoco mysqli_close($connection); // se esiste il record ( che è sempre unico, come la matricola ) if ($array[0] != null) { $xml = new XMLWriter(); $xml->openURI("php://output"); $xml->startDocument('1.0', 'UTF-8'); $xml->setIndent(false); $xml->startElement('user'); addChildNode($xml, "matricola", trim($array[0]["matricola"])); addChildNode($xml, "struttura", trim($array[0]["struttura"])); addChildNode($xml, "citta", trim($array[0]["citta"])); addChildNode($xml, "indirizzo", trim($array[0]["indirizzo"])); addChildNode($xml, "profilo", trim($array[0]["profilo"])); $xml->endElement(); header('Content-type: text/xml'); $xml->flush(); } function addChildNode($xml, $name, $value) { $xml->startElement($name); $xml->writeRaw($value); $xml->endElement(); }
mysqli_close($connection); // se esiste il record 1( 0 esiste sempre, è categoria "in evidenza" ) if ($array[1] != null) { $xml = new XMLWriter(); $xml->openURI("php://output"); $xml->startDocument('1.0', 'UTF-8'); $xml->setIndent(false); $xml->startElement('categories'); for ($i = 0; $i < count($array); $i++) { addChildNode($xml, false, "category"); addChildNode($xml, true, "id", trim($array[$i]["id"])); addChildNode($xml, true, "name", utf8_encode($array[$i]["name"])); addChildNode($xml, true, "inevidenza", $array[$i]["inevidenza"] == 1 ? "true" : "false"); addChildNode($xml, true, "aggiornamenti", $array[$i]["aggiornamenti"] == 1 ? "true" : "false"); addChildNode($xml, true, "descrizione", utf8_encode($array[$i]["descrizione"])); addChildNode($xml, true, "color", trim($array[$i]["color"])); addChildNode($xml, true, "elements", trim($array[$i]["elements"])); $xml->endElement(); } $xml->endElement(); header('Content-type: text/xml'); $xml->flush(); } function addChildNode($xml, $boolChiudi, $name, $value) { $xml->startElement($name); $xml->writeRaw($value); if ($boolChiudi) { $xml->endElement(); } }
$xml->startDocument('1.0', 'UTF-8'); $xml->setIndent(false); $xml->startElement('questions'); for ($i = 0; $i < count($array); $i++) { addChildNode($xml, false, "question"); addChildNode($xml, true, "domanda", utf8_encode($array[$i]["domanda"])); addChildNode($xml, true, "voti", trim($array[$i]["voti"])); addChildNode($xml, true, "data", trim($array[$i]["data"])); addChildNode($xml, true, "sinossi", utf8_encode($array[$i]["sinossi"])); addChildNode($xml, false, "categories"); // per ogni categoria di quella domanda. // [0] non indica posizione 0, ma indica label associativa ( vedi sopra array_push ) for ($j = 0; $j < count($array[$i][0]); $j++) { addChildNode($xml, false, "category"); addChildNode($xml, true, "name", trim($array[$i][0][$j]["name"])); addChildNode($xml, true, "color", trim($array[$i][0][$j]["color"])); $xml->endElement(); } $xml->endElement(); $xml->endElement(); } $xml->endElement(); header('Content-type: text/xml'); $xml->flush(); } function addChildNode($xml, $boolChiudi, $name, $value) { $xml->startElement($name); $xml->writeRaw($value); if ($boolChiudi) { $xml->endElement();