Example #1
0
 /**
  * Parses ais html into DOM.
  *
  * @param Trace $trace
  * @param string $html
  *
  * @returns DOMDocument parsed DOM
  * @throws ParseException on failure
  */
 public static function createDomFromHtml(Trace $trace, $html)
 {
     Preconditions::checkIsString($html);
     $dom = new DOMDocument();
     $trace->tlog("Loading html to DOM");
     $loaded = @$dom->loadHTML($html);
     if (!$loaded) {
         throw new ParseException("Problem parsing html to DOM.");
     }
     $trace->tlog('Fixing id attributes in the DOM');
     ParserUtils::fixIdAttributes($trace, $dom);
     return $dom;
 }
 /**
  * Creates array with elements parsed from html containing information list.
  *
  * @param string $aisResponseHtml
  *
  * @returns complete array with parsed data from html
  * @throws ParseException on failure of creating DOM from html
  */
 public function parseHtml(Trace $trace, $aisResponseHtml)
 {
     Preconditions::checkIsString($aisResponseHtml);
     $html = self::fixBr($trace, $aisResponseHtml);
     $domWholeHtml = ParserUtils::createDomFromHtml($trace, $html);
     $domWholeHtml->preserveWhiteSpace = false;
     //ziskanie nazvu skoly, jedina vec co chcem ziskat co sa nenachadza v tabulke
     $b = $domWholeHtml->getElementsByTagName("b");
     $trace->tlog("Finding first element with tag name 'b'");
     $bb = $b->item(0);
     if ($bb !== null) {
         $this->spracujB($trace, $bb);
     }
     $trNodes = $domWholeHtml->getElementsByTagName("tr");
     $trace->tlog("Getting all elements with tag name 'tr'");
     // prechadzam vsetkymi <tr> tagmi
     $firstTr = true;
     foreach ($trNodes as $tr) {
         // nechcem uplne prvy tag co je v tr, za <b> je iba nazov: informacny list
         if ($firstTr) {
             $firstTr = false;
             continue;
         }
         $trace->tlog("Getting all elements with tag name 'td'");
         $tdNodes = $tr->getElementsByTagName("td");
         // prechadzam <td> tagmi
         foreach ($tdNodes as $td) {
             if (!$td->hasChildNodes()) {
                 continue;
             }
             $trace->tlog("Getting all child nodes of element 'td'");
             foreach ($td->childNodes as $final) {
                 if ($final->nodeType != \XML_ELEMENT_NODE) {
                     continue;
                 }
                 if ($final->tagName == 'b') {
                     $trace->tlog("Parsing node with tag name 'b'");
                     $this->spracujB($trace, $final);
                 } else {
                     if ($final->tagName == 'div') {
                         $trace->tlog("Parsing node with tag name 'div'");
                         $this->parseDiv($trace, $final);
                     }
                 }
             }
         }
     }
 }