コード例 #1
0
ファイル: JangleClasses.php プロジェクト: rsinger/Jangle
 function toXML()
 {
     $xml = new xmlWriter();
     $xml->openMemory();
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement("OpenSearchDescription");
     $xml->writeAttribute("xmlns", "http://a9.com/-/spec/opensearch/1.1/");
     $xml->writeAttribute("xmlns:jangle", "http://jangle.org/opensearch/");
     $xml->writeElement("ShortName", $this->shortName);
     if (isset($this->longName)) {
         $xml->writeElement("LongName", $this->longName);
     }
     if (isset($this->description)) {
         $xml->writeElement("Description", $this->description);
     }
     if (isset($this->developer)) {
         $xml->writeElement("Developer", $this->description);
     }
     if (isset($this->contact)) {
         $xml->writeElement("Contact", $this->contact);
     }
     if (isset($this->attribution)) {
         $xml->writeELement("Attribution", $this->attribution);
     }
     if (isset($this->syndicationRight)) {
         $xml->writeElement("SyndicationRight", $this->syndicationRight);
     }
     if (isset($this->adultContent)) {
         $xml->writeElement("adultContent", $this->adultContent);
     }
     if (isset($this->language)) {
         if (is_array($this->language)) {
             for ($i = 0; $i < count($this->language); $i++) {
                 $xml->writeELement("Language", $this->language[$i]);
             }
         } else {
             $xml->writeElement("Language", $this->language);
         }
     }
     if (count($this->inputEncoding)) {
         if (is_array($this->inputEncoding)) {
             for ($i = 0; $i < count($this->inputEncoding); $i++) {
                 $xml->writeELement("InputEncoding", $this->inputEncoding[$i]);
             }
         } else {
             $xml->writeElement("InputEncoding", $this->inputEncoding);
         }
     }
     if (count($this->outputEncoding)) {
         if (is_array($this->outputEncoding)) {
             for ($i = 0; $i < count($this->outputEncoding); $i++) {
                 $xml->writeELement("OutputEncoding", $this->OuputEncoding[$i]);
             }
         } else {
             $xml->writeElement("OuputEncoding", $this->OuputEncoding);
         }
     }
     if (count($this->tags)) {
         $xml->writeElement("Tags", join($this->tags, " "));
     }
     if (count($this->image)) {
         $xml->startElement("Image", $this->image["location"]);
         if ($this->image["height"]) {
             $xml->writeAttribute("height", $this->image["height"]);
         }
         if ($this->image["width"]) {
             $xml->writeAttribute("width", $this->image["width"]);
         }
         if ($this->image["type"]) {
             $xml->writeAttribute("type", $this->image["type"]);
         }
         $xml->endElement();
     }
     if (count($this->indexes) || isset($this->exampleQuery)) {
         $xml->startElement("Query");
         if (isset($this->exampleQuery)) {
             $xml->writeAttribute("role", "example");
             $xml->writeAttribute("searchTerms", $this->exampleQuery);
         }
         if (count($this->indexes)) {
             $xml->startElement("zr:explain");
             $xml->writeAttribute("xmlns:zr", "http://explain.z3950.org/dtd/2.1/");
             $xml->startElement("zr:indexInfo");
             for ($i = 0; $i < count($this->indexes); $i++) {
                 $xml->startElement("zr:set");
                 $xml->writeAttribute("name", $this->indexes[$i]->name);
                 if ($this->indexes[$i]->identifier) {
                     $xml->writeAttribute("identifier", $this->indexes[$i]->identifier);
                 }
                 $xml->endELement();
                 for ($x = 0; $x < count($this->indexes[$i]->indexes); $x++) {
                     $xml->startElement("zr:index");
                     $xml->startElement("zr:map");
                     $xml->startElement("zr:name");
                     $xml->writeAttribute("set", $this->indexes[$i]->name);
                     $xml->text($this->indexes[$i]->indexes[$x]);
                     $xml->endElement();
                     $xml->endElement();
                     $xml->endELement();
                 }
             }
             $xml->endElement();
             $xml->endElement();
         }
         $xml->endElement();
     }
     $xml->endElement();
     return $xml->outputMemory(true);
 }