Example #1
0
 /**
  * Test that the cropper remove all siblings.
  */
 public function testCropRemoveAllSiblings()
 {
     $cropper = new Cropper();
     $string = $cropper->crop(__DIR__ . '/sample.xml', "//book[@id='bk102']");
     $domDocument = new DOMDocument();
     $domDocument->loadXML($string);
     $domXPath = new DOMXPath($domDocument);
     $books = $domXPath->query('//book');
     $this->assertEquals(1, $books->length);
     $catalogs = $domXPath->query('//catalog');
     $this->assertEquals(1, $catalogs->length);
 }
Example #2
0
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $cropper = new Cropper();
     $result = $cropper->crop($input->getArgument('file'), $input->getArgument('path'));
     $saveTo = $input->getOption('save-to');
     if ($saveTo) {
         if (!file_put_contents($saveTo, $result)) {
             throw new \InvalidArgumentException(sprintf('Can not write in "%s"', $saveTo));
         }
     } else {
         $output->writeln($result);
     }
 }
Example #3
0
                    <input name="xpath" type="text" class="form-control"
                           placeholder="xpath expression"
                           aria-describedby="basic-addon2" required
                           value="<?php 
echo isset($_POST['xpath']) ? htmlentities($_POST['xpath']) : "";
?>
"/>
                    <!-- /input-group -->
                </div>
                <!-- /.row -->

            </form>

            <?php 
if (isset($_FILES['xmlfile'])) {
    $cropper = new Cropper();
    try {
        $croppedXml = $cropper->crop($_FILES['xmlfile']['tmp_name'], $_POST['xpath']);
        $croppedXml = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n", $croppedXml);
        echo '<pre id="data">' . htmlentities($croppedXml) . '</pre>';
    } catch (Exception $ex) {
        echo '<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span><span class="sr-only">Error:</span>
' . $ex->getMessage() . '
</div>';
    }
}
?>
        </div>
    </div>
</div>