示例#1
0
    /**
     * Test attaching one item to another.
     *
     * @return void
     */
    public function testAppendElement()
    {
        $parent = simplexml_load_string('<top><children></children></top>');
        $child = simplexml_load_string('<child attr="true" />');
        $expected = simplexml_load_string('<top><children>
<child attr="true" />
</children></top>');
        \VuFind\SimpleXML::appendElement($parent->children, $child);
        $this->assertEquals($expected->asXML(), $parent->asXML());
    }
示例#2
0
 /**
  * Convert an array of individual records into a single string for display.
  *
  * @param string $format Format of records to process
  * @param array  $parts  Multiple records to process
  *
  * @return string
  */
 public function processGroup($format, $parts)
 {
     // If we're in XML mode, we need to do some special processing:
     if (isset($this->exportConfig->{$format}->combineXpath)) {
         $ns = isset($this->exportConfig->{$format}->combineNamespaces) ? $this->exportConfig->{$format}->combineNamespaces->toArray() : [];
         $ns = array_map(function ($current) {
             return explode('|', $current, 2);
         }, $ns);
         foreach ($parts as $part) {
             // Convert text into XML object:
             $current = simplexml_load_string($part);
             // The first record gets kept as-is; subsequent records get merged
             // in based on the configured XPath (currently only one level is
             // supported)...
             if (!isset($retVal)) {
                 $retVal = $current;
             } else {
                 foreach ($ns as $n) {
                     $current->registerXPathNamespace($n[0], $n[1]);
                 }
                 $matches = $current->xpath($this->exportConfig->{$format}->combineXpath);
                 foreach ($matches as $match) {
                     SimpleXML::appendElement($retVal, $match);
                 }
             }
         }
         return $retVal->asXML();
     } else {
         // Not in XML mode -- just concatenate everything together:
         return implode('', $parts);
     }
 }
示例#3
0
 /**
  * Display an OAI-PMH response (shared support method used by various
  * response-specific methods).
  *
  * @param SimpleXMLElement $body       Main body of response.
  * @param bool             $echoParams Include params in <request> tag?
  *
  * @return string
  */
 protected function showResponse($body, $echoParams = true)
 {
     // Set up standard response wrapper:
     $xml = simplexml_load_string('<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" />');
     $xml->addAttribute('xsi:schemaLocation', 'http://www.openarchives.org/OAI/2.0/ ' . 'http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd', 'http://www.w3.org/2001/XMLSchema-instance');
     $xml->responseDate = date($this->iso8601);
     $xml->request = $this->baseURL;
     if ($echoParams) {
         foreach ($this->params as $key => $value) {
             $xml->request[$key] = $value;
         }
     }
     // Attach main body:
     SimpleXML::appendElement($xml, $body);
     return $xml->asXml();
 }