Exemple #1
0
 function testTextQuery()
 {
     $file = new qio\File(__DIR__ . '/Mock/mock.xml');
     $query = new XML\Query();
     $query->from($file);
     $result = $query();
     $resource = $query->getResource();
     $this->assertEquals(775, strlen($result));
     $this->assertInstanceOf('qio\\Resource', $resource);
 }
Exemple #2
0
 /**
  * Performs xpath limiter procedure
  * @param \SimpleXMLElement|array $input
  * @return mixed
  */
 function execute($input)
 {
     $xpath = $this->xpath;
     if ($input instanceof \SimpleXMLElement && isset($input->{$xpath})) {
         return $input->{$xpath};
     }
     if (is_object($input) && method_exists($input, 'xpath')) {
         $namespaces = $this->query->getNamespaces();
         foreach ($namespaces as $prefix => $ns) {
             $input->registerXPathNamespace($prefix, $ns);
         }
         return $input->xpath($xpath);
     } elseif (qtil\ArrayUtil::isIterable($input)) {
         $results = [];
         foreach ($input as $i) {
             if (is_object($i) && method_exists($i, 'xpath')) {
                 $results[] = $this->execute($i);
             }
         }
         return $results;
     }
 }