/** * @dataProvider getEzXmlTestDocuments */ public function testConvertToDocbook($from, $to) { if (!is_file($to)) { $this->markTestSkipped("Comparision file '{$to}' not yet defined."); } $document = new ezcDocumentEzXml(); $document->loadFile($from); $docbook = $document->getAsDocbook(); $xml = $docbook->save(); $this->assertTrue($docbook instanceof ezcDocumentDocbook); // Store test file, to have something to compare on failure $tempDir = $this->createTempDir('ezxml_docbook_') . '/'; file_put_contents($tempDir . basename($to), $xml); // We need a proper XSD first, the current one does not accept legal // XML. // $this->checkDocbook( $docbook->getDomDocument() ); $this->assertEquals(file_get_contents($to), $xml, 'Document not visited as expected.'); // Remove tempdir, when nothing failed. $this->removeTempDir(); }
/** * Create document from structure * * Build a ezcDocumentDocument object from the structure created during the * visiting process. * * @param mixed $content * @return ezcDocumentDocument */ protected function createDocument($content) { $document = $content->ownerDocument; $this->appendFootnotes($content); $ezxml = new ezcDocumentEzXml(); $ezxml->setDomDocument($document); return $ezxml; }
<?php require 'tutorial_autoload.php'; $document = new ezcDocumentEzXml(); $document->loadString('<?xml version="1.0"?> <section xmlns="http://ez.no/namespaces/ezpublish3"> <header>Paragraph</header> <paragraph>Some content...</paragraph> </section>'); $docbook = $document->getAsDocbook(); echo $docbook->save();
<?php require 'tutorial_autoload.php'; class myLinkProvider extends ezcDocumentEzXmlLinkProvider { public function fetchUrlById($id, $view, $show_path) { return 'http://host/path/' . $id; } public function fetchUrlByNodeId($id, $view, $show_path) { } public function fetchUrlByObjectId($id, $view, $show_path) { } } $document = new ezcDocumentEzXml(); $document->loadString('<?xml version="1.0"?> <section xmlns="http://ez.no/namespaces/ezpublish3"> <header>Paragraph</header> <paragraph>Some content, with a <link url_id="1">link</link>.</paragraph> </section>'); // Set link provider $converter = new ezcDocumentEzXmlToDocbookConverter(); $converter->options->linkProvider = new myLinkProvider(); $docbook = $converter->convert($document); echo $docbook->save();