public function queryTreeWithDefaultEncoding()
 {
     $value = new String('value öäü', 'utf-8');
     $xpath = new XPath($s = sprintf('<document><node>%s</node></document>', $value->getBytes('utf-8')));
     $this->assertEquals($value, new String($xpath->query('string(/document/node)'), 'utf-8'));
 }
示例#2
0
 /**
  * Unmarshal XML to an object
  *
  * @param   xml.parser.InputSource source
  * @param   string classname
  * @param   [:var] inject
  * @return  lang.Object
  * @throws  lang.ClassNotFoundException
  * @throws  xml.XMLFormatException
  * @throws  lang.reflect.TargetInvocationException
  * @throws  lang.IllegalArgumentException
  */
 public function unmarshalFrom(InputSource $input, $classname, $inject = [])
 {
     libxml_clear_errors();
     $doc = new \DOMDocument();
     if (!$doc->load(Streams::readableUri($input->getStream()))) {
         $e = libxml_get_last_error();
         throw new XMLFormatException(trim($e->message), $e->code, $input->getSource(), $e->line, $e->column);
     }
     $xpath = new XPath($doc);
     // Class factory based on tag name, reference to a static method which is called with
     // the class name and returns an XPClass instance.
     $class = \lang\XPClass::forName($classname);
     if ($class->hasAnnotation('xmlmapping', 'factory')) {
         if ($class->hasAnnotation('xmlmapping', 'pass')) {
             $factoryArgs = [];
             foreach ($class->getAnnotation('xmlmapping', 'pass') as $pass) {
                 $factoryArgs[] = self::contentOf($xpath->query($pass, $doc->documentElement));
             }
         } else {
             $factoryArgs = [$doc->documentElement->nodeName];
         }
         $class = $class->getMethod($class->getAnnotation('xmlmapping', 'factory'))->invoke(null, $factoryArgs);
     }
     return self::recurse($xpath, $doc->documentElement, $class, $inject);
 }
示例#3
0
 public function queryTreeWithDefaultEncoding()
 {
     $xpath = new XPath('<document><node>öäü</node></document>');
     $this->assertEquals('öäü', $xpath->query('string(/document/node)'));
 }