/** * @param Position $position * @param string $content */ public function getPositionData(Position $position, $content) { $crawler = new Crawler($content); $trs = $crawler->filter('#full-props-list tr'); $data = []; if ($trs->count() > 0) { foreach ($trs as $tr) { $crawler->clear(); $crawler->addNode($tr); $th = $crawler->filter('th'); $td = $crawler->filter('td'); if ($th->count() > 0 && $td->count() > 0) { $data[trim($th->text())] = trim($td->text()); } } } $position->setAttributes($data); }
public function testAddNode() { $crawler = new Crawler(); $crawler->addNode($this->createNodeList()->item(0)); $this->assertEquals('foo', $crawler->filterXPath('//div')->attr('class'), '->addNode() adds nodes from a \\DOMNode'); }
protected function extractDump($dump) { $crawler = new Crawler(); $crawler->addContent($dump); foreach ($crawler->filter('table') as $table) { $table_crawler = new Crawler(); $table_crawler->addNode($table); $tag_group_name = $table_crawler->attr('g1'); $tag_full_name = $table_crawler->attr('name'); $tag_g0 = $table_crawler->attr('g0'); $tag_g2 = $table_crawler->attr('g2'); $tags = $table_crawler->filter('tag'); foreach ($tags as $tag) { $tag_crawler = new Crawler(); $tag_crawler->addNode($tag); $extra = array(); if ($tag_crawler->attr('g0')) { $extra['local_g0'] = $tag_crawler->attr('g0'); } if ($tag_crawler->attr('g1') && !in_array($tag_crawler->attr('g1'), array('MakerNotes', 'Chapter#'))) { $g_name = $tag_crawler->attr('g1'); $extra['local_g1'] = $tag_crawler->attr('g1'); } else { $g_name = $tag_group_name; } if ($tag_crawler->attr('g2')) { $extra['local_g2'] = $tag_crawler->attr('g2'); } $flags = explode(',', $tag_crawler->attr('flags')); if (in_array('Avoid', $flags)) { $extra['flag_Avoid'] = 'true'; } if (in_array('Binary', $flags)) { $extra['flag_Binary'] = 'true'; } if (in_array('Permanent', $flags)) { $extra['flag_Permanent'] = 'true'; } if (in_array('Protected', $flags)) { $extra['flag_Protected'] = 'true'; } if (in_array('Unsafe', $flags)) { $extra['flag_Unsafe'] = 'true'; } if (in_array('List', $flags)) { $extra['flag_List'] = 'true'; } if (in_array('Mandatory', $flags)) { $extra['flag_Mandatory'] = 'true'; } if (in_array('Bag', $flags)) { $extra['flag_Bag'] = 'true'; } if (in_array('Seq', $flags)) { $extra['flag_Seq'] = 'true'; } if (in_array('Alt', $flags)) { $extra['flag_Alt'] = 'true'; } $subspace = str_replace('::', '\\', $g_name); $tag_name = $tag_crawler->attr('name'); $classname = self::generateClassname($tag_name); $tag_id = $tag_crawler->attr('id'); $properties = array_merge(array('Id' => $tag_id, 'Name' => $tag_name, 'FullName' => $tag_full_name, 'GroupName' => $g_name, 'g0' => $tag_g0, 'g1' => $tag_group_name, 'g2' => $tag_g2, 'Type' => $tag_crawler->attr('type'), 'Writable' => $tag_crawler->attr('writable'), 'Description' => $tag_crawler->filter('desc[lang="en"]')->first()->text()), $extra); if ($tag_crawler->attr('count')) { $properties['MaxLength'] = $tag_crawler->attr('count'); } $this->types[$tag_crawler->attr('type')] = $tag_crawler->attr('type'); if ($tag_crawler->attr('index')) { $properties['Index'] = $tag_crawler->attr('index'); } if (count($tag_crawler->filter('values')) > 0) { $values = array(); $values_tag = $tag_crawler->filter('values')->first(); $Keys = $values_tag->filter('key'); foreach ($Keys as $Key) { $KeyCrawler = new Crawler(); $KeyCrawler->addNode($Key); $Id = $KeyCrawler->attr('id'); $Label = $KeyCrawler->filter('val[lang="en"]')->first()->text(); $values[$Id] = array('Id' => $Id, 'Label' => $Label); } $properties['Values'] = $values; } $this->createTagClass($subspace, $classname, $properties); } } $this->generateTypes(); }
/** * @covers Symfony\Component\DomCrawler\Crawler::addNode */ public function testAddNode() { if (!class_exists('Symfony\\Component\\CssSelector\\CssSelector')) { $this->markTestSkipped('The "CssSelector" component is not available'); } $crawler = new Crawler(); $crawler->addNode($this->createNodeList()->item(0)); $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addNode() adds nodes from an \\DOMNode'); }