addXmlContent() public method

The libxml errors are disabled when the content is parsed. If you want to get parsing errors, be sure to enable internal errors via libxml_use_internal_errors(true) and then, get the errors via libxml_get_errors(). Be sure to clear errors with libxml_clear_errors() afterward.
public addXmlContent ( string $content, string $charset = 'UTF-8', integer $options = LIBXML_NONET )
$content string The XML content
$charset string The charset
$options integer Bitwise OR of the libxml option constants LIBXML_PARSEHUGE is dangerous, see http://symfony.com/blog/security-release-symfony-2-0-17-released
コード例 #1
0
ファイル: CrawlerTest.php プロジェクト: nacef/symfony
    /**
     * @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');
    }
コード例 #2
0
ファイル: Parser.php プロジェクト: naroga/junit-parser
 /**
  * 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.");
     }
 }
コード例 #3
0
 /**
  * @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));
 }
コード例 #4
0
ファイル: RenderingTest.php プロジェクト: neos/neos
 /**
  * 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');
     }
 }
コード例 #5
0
ファイル: CrawlerTest.php プロジェクト: sapwoo/portfolio
    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);
    }
コード例 #6
0
 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));
 }
コード例 #7
0
 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);
 }
コード例 #8
0
 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()));
 }
コード例 #9
0
 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>
                     <DPROCD>05.01.2014</DPROCD>
                     <S61_CD_INDIK>CR</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>DR</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));
     # Statement
     $this->assertSame(-1000.0, $statement->getLastBalance());
     $this->assertSame(-800.0, $statement->getBalance());
     $this->assertSame(-400.0, $statement->getCreditTurnover());
     $this->assertSame(-600.0, $statement->getDebitTurnover());
     # Transactions
     $statement->rewind();
     $transaction = $statement->current();
     $this->assertSame(-400.0, $transaction->getCredit());
     $transaction = $statement->next();
     $this->assertSame(-600.0, $transaction->getDebit());
 }