当前位置: 首页>>代码示例>>PHP>>正文


PHP Crawler::addXmlContent方法代码示例

本文整理汇总了PHP中Symfony\Component\DomCrawler\Crawler::addXmlContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Crawler::addXmlContent方法的具体用法?PHP Crawler::addXmlContent怎么用?PHP Crawler::addXmlContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\DomCrawler\Crawler的用法示例。


在下文中一共展示了Crawler::addXmlContent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAddXmlContent

    /**
     * @covers Symfony\Component\DomCrawler\Crawler::addXmlContent
     */
    public function testAddXmlContent()
    {
        $crawler = new Crawler();
        $crawler->addXmlContent('<html><div class="foo"></div></html>', 'UTF-8');

        $this->assertEquals('foo', $crawler->filter('div')->attr('class'), '->addXmlContent() adds nodes from an XML string');
    }
开发者ID:nacef,项目名称:symfony,代码行数:10,代码来源:CrawlerTest.php

示例2: addXmlContent

 /**
  * Adds a XML content to the report.
  *
  * @param string $xml The XML content. Use file_get_contents($path) to get the XML text from a file.
  * @param string $charset The character encoding in the XML.
  * @return Parser The parser.
  * @throws InvalidReportException
  */
 public function addXmlContent($xml, $charset = 'UTF-8')
 {
     if (self::isStringValidXml($xml)) {
         $crawler = new Crawler();
         $crawler->addXmlContent($xml, $charset);
         $this->reports[] = $crawler;
         return $this;
     } else {
         throw new InvalidReportException("The report is not a valid XML.");
     }
 }
开发者ID:naroga,项目名称:junit-parser,代码行数:19,代码来源:Parser.php

示例3: listingAction

 /**
  * @Route("/page/listing", name="front_listing")
  */
 public function listingAction()
 {
     $url = "http://www.ffbsq.org/bowling/listing/listing-ws.php?output=xml&asfile=false&num_licence=&departement=&region=&club=poitevin&nom=";
     $crawler = new Crawler();
     $crawler->addXmlContent(file_get_contents($url));
     $listing = array();
     foreach ($crawler as $xListing) {
         foreach ($xListing->childNodes as $joueur) {
             $tmpJoueur = array();
             foreach ($joueur->attributes as $attr) {
                 $tmpJoueur[$attr->name] = $joueur->getAttribute($attr->name);
             }
             $listing[] = $tmpJoueur;
         }
     }
     $dynamicArray = $this->getDynamicArray($listing);
     array_multisort($dynamicArray['moyenne'], SORT_DESC, $dynamicArray['nom'], SORT_ASC, $listing);
     return $this->render(':default:listing.html.twig', array('listing' => $listing));
 }
开发者ID:nathix86,项目名称:bcp-website,代码行数:22,代码来源:DefaultController.php

示例4: assertSelectEquals

 /**
  * Helper function for setting assertions
  * @static
  * @param string $selector
  * @param string $content
  * @param integer|bool $count assert specific number of elements, assert any elements exist if true, assert no elements exist if false
  * @param mixed $actual
  * @param string $message
  * @param boolean $isHtml
  */
 public static function assertSelectEquals($selector, $content, $count, $actual, $message = '', $isHtml = true)
 {
     if ($message === '') {
         $message = $selector . ' did not match: ' . $actual;
     }
     $crawler = new Crawler();
     if ($actual instanceof \DOMDocument) {
         $crawler->addDocument($actual);
     } elseif ($isHtml) {
         $crawler->addHtmlContent($actual);
     } else {
         $crawler->addXmlContent($actual);
     }
     $crawler = $crawler->filter($selector);
     if (is_string($content)) {
         $crawler = $crawler->reduce(function (Crawler $node, $i) use($content) {
             if ($content === '') {
                 return $node->text() === '';
             }
             if (preg_match('/^regexp\\s*:\\s*(.*)/i', $content, $matches)) {
                 return (bool) preg_match($matches[1], $node->text());
             }
             return strstr($node->text(), $content) !== false;
         });
     }
     $found = count($crawler);
     if (is_numeric($count)) {
         self::assertEquals($count, $found, $message);
     } elseif (is_bool($count)) {
         $found = $found > 0;
         if ($count) {
             self::assertTrue($found, $message);
         } else {
             self::assertFalse($found, $message);
         }
     } elseif (is_array($count) && (isset($count['>']) || isset($count['<']) || isset($count['>=']) || isset($count['<=']))) {
         if (isset($count['>'])) {
             self::assertTrue($found > $count['>'], $message);
         }
         if (isset($count['>='])) {
             self::assertTrue($found >= $count['>='], $message);
         }
         if (isset($count['<'])) {
             self::assertTrue($found < $count['<'], $message);
         }
         if (isset($count['<='])) {
             self::assertTrue($found <= $count['<='], $message);
         }
     } else {
         throw new \PHPUnit_Framework_Exception('Invalid count format');
     }
 }
开发者ID:neos,项目名称:neos,代码行数:62,代码来源:RenderingTest.php

示例5: testAddXmlContentWithErrors

    public function testAddXmlContentWithErrors()
    {
        $internalErrors = libxml_use_internal_errors(true);
        $crawler = new Crawler();
        $crawler->addXmlContent(<<<EOF
<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <nav><a href="#"><a href="#"></nav>
    </body>
</html>
EOF
, 'UTF-8');
        $this->assertTrue(count(libxml_get_errors()) > 1);
        libxml_clear_errors();
        libxml_use_internal_errors($internalErrors);
    }
开发者ID:sapwoo,项目名称:portfolio,代码行数:19,代码来源:CrawlerTest.php

示例6: parseOctgnImport

 public function parseOctgnImport($octgn)
 {
     /* @var $em \Doctrine\ORM\EntityManager */
     $em = $this->get('doctrine')->getManager();
     $content = array();
     $crawler = new Crawler();
     $crawler->addXmlContent($octgn);
     $cardcrawler = $crawler->filter('deck > section > card');
     $content = array();
     foreach ($cardcrawler as $domElement) {
         $quantity = intval($domElement->getAttribute('qty'));
         if (preg_match('/bc0f047c-01b1-427f-a439-d451eda(\\d{5})/', $domElement->getAttribute('id'), $matches)) {
             $card_code = $matches[1];
         } else {
             continue;
         }
         $card = $em->getRepository('NetrunnerdbCardsBundle:Card')->findOneBy(array('code' => $card_code));
         if ($card) {
             $content[$card->getCode()] = $quantity;
         }
     }
     $desccrawler = $crawler->filter('deck > notes');
     $description = array();
     foreach ($desccrawler as $domElement) {
         $description[] = $domElement->nodeValue;
     }
     return array("content" => $content, "description" => implode("\n", $description));
 }
开发者ID:adamcieslicki,项目名称:netrunnerdb,代码行数:28,代码来源:BuilderController.php

示例7: parseOctgnImport

 public function parseOctgnImport($octgn)
 {
     /* @var $em \Doctrine\ORM\EntityManager */
     $em = $this->getDoctrine()->getManager();
     $crawler = new Crawler();
     $crawler->addXmlContent($octgn);
     // read octgnId
     $cardcrawler = $crawler->filter('deck > section > card');
     $octgnIds = [];
     foreach ($cardcrawler as $domElement) {
         $octgnIds[$domElement->getAttribute('id')] = intval($domElement->getAttribute('qty'));
     }
     // read desc
     $desccrawler = $crawler->filter('deck > notes');
     $descriptions = [];
     foreach ($desccrawler as $domElement) {
         $descriptions[] = $domElement->nodeValue;
     }
     $content = [];
     $faction_code = null;
     foreach ($octgnIds as $octgnId => $qty) {
         $card = $em->getRepository('AppBundle:Card')->findOneBy(array('octgnId' => $octgnId));
         if ($card) {
             $content[$card->getCode()] = $qty;
         }
         // TOFIX
         $faction = $em->getRepository('AppBundle:Faction')->findOneBy(array('name' => $octgnId));
         if ($faction) {
             $faction_code = $faction->getCode();
         }
     }
     $description = implode("\n", $descriptions);
     return array("faction_code" => $faction_code, "content" => $content, "description" => $description);
 }
开发者ID:Alsciende,项目名称:thronesdb,代码行数:34,代码来源:BuilderController.php

示例8: bowlingInfosAction

 public function bowlingInfosAction($num_licence)
 {
     $url = $this->get('bcp.external_url_generator');
     $url->setUrl("http://www.ffbsq.org/bowling/listing/listing-ws.php");
     $url->addArguments(array('ouput' => 'xml', 'asfile' => 'false', 'num_licence' => $num_licence));
     $crawler = new Crawler();
     $crawler->addXmlContent(file_get_contents($url->generate()));
     $infos = $crawler->filter('listing > joueur');
     return $this->render(':User:bowling_infos.html.twig', array('infos' => $infos->count() == 0 ? null : $infos->first()));
 }
开发者ID:nathix86,项目名称:bcp-website,代码行数:10,代码来源:UserController.php

示例9: testParseCrawler

 public function testParseCrawler()
 {
     $parser = new CSOBCZParser();
     $reflectionParser = new \ReflectionClass($this->parserClassName);
     $method = $reflectionParser->getMethod('parseCrawler');
     $method->setAccessible(true);
     # Positive statement
     $crawler = new Crawler();
     $content = '
         <FINSTA>
             <FINSTA03>
                 <S28_CISLO_VYPISU>2</S28_CISLO_VYPISU>
                 <S25_CISLO_UCTU>12345/0300</S25_CISLO_UCTU>
                 <S60_CD_INDIK>C</S60_CD_INDIK>
                 <S60_DATUM>01.01.2014</S60_DATUM>
                 <S60_CASTKA>1000,00</S60_CASTKA>
                 <SUMA_KREDIT>=400,00</SUMA_KREDIT>
                 <SUMA_DEBIT>=600,00</SUMA_DEBIT>
                 <S62_CD_INDIK>C</S62_CD_INDIK>
                 <S62_DATUM>01.02.2014</S62_DATUM>
                 <S62_CASTKA>800,00</S62_CASTKA>
                 <FINSTA05>
                     <REF_TRANS_SYS>2001</REF_TRANS_SYS>
                     <DPROCD>05.01.2014</DPROCD>
                     <S61_CD_INDIK>C</S61_CD_INDIK>
                     <S61_CASTKA>+400,00</S61_CASTKA>
                     <S86_SPECSYMOUR>13</S86_SPECSYMOUR>
                     <S86_VARSYMOUR>11</S86_VARSYMOUR>
                     <S86_KONSTSYM>12</S86_KONSTSYM>
                     <PART_ACCNO>156789</PART_ACCNO>
                     <PART_BANK_ID>1000</PART_BANK_ID>
                     <PART_ID1_1>Tran 1</PART_ID1_1>
                     <PART_ID1_2/>
                     <PART_ID2_1/>
                     <PART_ID2_2/>
                 </FINSTA05>
                 <FINSTA05>
                     <REF_TRANS_SYS>2002</REF_TRANS_SYS>
                     <DPROCD>07.01.2014</DPROCD>
                     <S61_CD_INDIK>D</S61_CD_INDIK>
                     <S61_CASTKA>+600,00</S61_CASTKA>
                     <S86_SPECSYMOUR>23</S86_SPECSYMOUR>
                     <S86_VARSYMOUR>21</S86_VARSYMOUR>
                     <S86_KONSTSYM>22</S86_KONSTSYM>
                     <PART_ACCNO>256789</PART_ACCNO>
                     <PART_BANK_ID>2000</PART_BANK_ID>
                     <PART_ID1_1>Tran 2</PART_ID1_1>
                     <PART_ID1_2/>
                     <PART_ID2_1/>
                     <PART_ID2_2/>
                 </FINSTA05>
             </FINSTA03>
         </FINSTA>
     ';
     $crawler->addXmlContent($content);
     $statement = $method->invokeArgs($parser, array($crawler));
     $this->assertInstanceOf('\\JakubZapletal\\Component\\BankStatement\\Statement\\Statement', $statement);
     # Statement
     $this->assertSame($statement, $parser->getStatement());
     $this->assertEquals('12345/0300', $statement->getAccountNumber());
     $this->assertEquals(new \DateTime('2014-01-01 12:00:00'), $statement->getDateLastBalance());
     $this->assertSame(1000.0, $statement->getLastBalance());
     $this->assertSame(800.0, $statement->getBalance());
     $this->assertSame(400.0, $statement->getCreditTurnover());
     $this->assertSame(600.0, $statement->getDebitTurnover());
     $this->assertEquals(2, $statement->getSerialNumber());
     $this->assertEquals(new \DateTime('2014-02-01 12:00:00'), $statement->getDateCreated());
     # Transactions
     $statement->rewind();
     $this->assertCount(2, $statement);
     $transaction = $statement->current();
     $this->assertEquals('156789/1000', $transaction->getCounterAccountNumber());
     $this->assertEquals(2001, $transaction->getReceiptId());
     $this->assertSame(400.0, $transaction->getCredit());
     $this->assertNull($transaction->getDebit());
     $this->assertEquals(11, $transaction->getVariableSymbol());
     $this->assertEquals(12, $transaction->getConstantSymbol());
     $this->assertEquals(13, $transaction->getSpecificSymbol());
     $this->assertEquals('Tran 1', $transaction->getNote());
     $this->assertEquals(new \DateTime('2014-01-05 12:00:00'), $transaction->getDateCreated());
     $transaction = $statement->next();
     $this->assertNull($transaction->getCredit());
     $this->assertSame(600.0, $transaction->getDebit());
     # Negative statement
     $crawler = new Crawler();
     $content = '
         <FINSTA>
             <FINSTA03>
                 <S28_CISLO_VYPISU>2</S28_CISLO_VYPISU>
                 <S25_CISLO_UCTU>12345/0300</S25_CISLO_UCTU>
                 <S60_CD_INDIK>D</S60_CD_INDIK>
                 <S60_DATUM>01.01.2014</S60_DATUM>
                 <S60_CASTKA>1000,00</S60_CASTKA>
                 <SUMA_KREDIT>=-400,00</SUMA_KREDIT>
                 <SUMA_DEBIT>=-600,00</SUMA_DEBIT>
                 <S62_CD_INDIK>D</S62_CD_INDIK>
                 <S62_DATUM>01.02.2014</S62_DATUM>
                 <S62_CASTKA>800,00</S62_CASTKA>
                 <FINSTA05>
                     <REF_TRANS_SYS>2001</REF_TRANS_SYS>
//.........这里部分代码省略.........
开发者ID:jakubzapletal,项目名称:bank-statements,代码行数:101,代码来源:CSOBCZParserTest.php


注:本文中的Symfony\Component\DomCrawler\Crawler::addXmlContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。