public static function objects2XML($data) { $parser = new PicnicXMLParser(); $parser->loadObjects($data); $parser->write(); return $parser->getXML(); }
public function render($data) { $type = $this->picnic()->router()->outputType(); if ($type == "xml") { PicnicBenchmark::instance()->mark("end"); header("Content-type: text/xml"); echo PicnicXMLParser::objects2XML($this->picnic()->controller()); exit; } else { if ($type == "json") { PicnicBenchmark::instance()->mark("end"); header("Content-type: text/x-javascript"); echo json_encode($this->picnic()->controller()); exit; } else { if ($this->_template == null) { throw new PicnicTemplateNotDefinedException("No template has been defined to use", 0, "PicnicView", "render"); } if (file_exists($this->templatePath())) { $contents = $this->getTemplateContents($this->templatePath()); if ($contents === false) { exit("TEMPLATE ERROR"); } PicnicBenchmark::instance()->mark("end"); if ($this->layoutTemplatePath() != "" && file_exists($this->layoutTemplatePath())) { // TODO: use getTemplateContents() include $this->layoutTemplatePath(); } else { echo $contents; } } else { throw new PicnicTemplateNotDefinedException("The template '{$this->_template}' does not exist in the template path '{$this->_templateFolder}'", 0, "PicnicView", "render"); } } } }
$episode->season = 1; $episode->number = $i + 1; $collection[] = $episode; } $obj1 = new TVShow(); $obj1->name = "Heroes"; $obj1->episodes = $collection; $obj2 = new TVShow(); $obj2->name = "How I Met Your Mother"; $obj2->episodes = $collection; $data = array($obj1, $obj2); /*$data = new StandardObject(); $data->username = "******"; $data->password = "******"; $data->collection = array("1", "2", "3", "4", "5"); */ $parser = new PicnicXMLParser(); $parser->loadObjects($data); $s = $parser->write("")->outputMemory(true); echo "<h2>from</h2>"; echo "<pre>"; var_dump($data); echo "</pre>"; echo "<h2>to</h2>"; echo "<textarea style=\"width: 100%; height: 450px;\">"; echo $s; echo "</textarea>"; echo "<h2>and back to</h2>"; echo "<pre>"; var_dump($parser->read()); echo "</pre>"; echo "<h2>to hello.xml file</h2>";