Пример #1
0
 /**
  * Construct an XML tree from a file.
  *
  * <code>
  *   $tree= Tree::fromFile(new File('foo.xml'));
  * </code>
  *
  * @param   io.File file
  * @param   string c default __CLASS__ class name
  * @return  xml.Tree
  * @throws  xml.XMLFormatException in case of a parser error
  * @throws  io.IOException in case reading the file fails
  */
 public static function fromFile($file, $c = __CLASS__)
 {
     $parser = new XMLParser();
     $tree = new $c();
     $parser->setCallback($tree);
     $parser->parse(FileUtil::getContents($file));
     // Fetch actual encoding from parser
     $tree->setEncoding($parser->getEncoding());
     delete($parser);
     return $tree;
 }