本文整理汇总了PHP中DOMDocument::xinclude方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument::xinclude方法的具体用法?PHP DOMDocument::xinclude怎么用?PHP DOMDocument::xinclude使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::xinclude方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
public static function load($file)
{
$document = new DOMDocument();
$document->load($file);
$document->xinclude();
return $document->saveXML();
}
示例2: loadRecordHML
function loadRecordHML($filename)
{
global $recID;
$dom = new DOMDocument();
$dom->load($filename);
$dom->xinclude();
return $dom->saveXML();
}
示例3: main
function main()
{
$uri = realpath(__DIR__ . '/xinclude-1.xml');
$xml = file_get_contents($uri);
$doc = new DOMDocument();
$doc->loadXML($xml);
$doc->documentURI = $uri;
$doc->xinclude();
var_dump($doc->saveXML());
}
示例4: load
static function load($filename)
{
$document = new \DOMDocument();
if ($document->load($filename) !== false) {
$document->xinclude();
return new document($document);
} else {
return null;
}
}
示例5: load
/**
* Load an $actual document into a DOMDocument. This is called
* from the selector assertions.
*
* If $actual is already a DOMDocument, it is returned with
* no changes. Otherwise, $actual is loaded into a new DOMDocument
* as either HTML or XML, depending on the value of $isHtml. If $isHtml is
* false and $xinclude is true, xinclude is performed on the loaded
* DOMDocument.
*
* Note: prior to PHPUnit 3.3.0, this method loaded a file and
* not a string as it currently does. To load a file into a
* DOMDocument, use loadFile() instead.
*
* @param string|DOMDocument $actual
* @param bool $isHtml
* @param string $filename
* @param bool $xinclude
* @param bool $strict
*
* @return DOMDocument
*
* @since Method available since Release 3.3.0
*/
public static function load($actual, $isHtml = false, $filename = '', $xinclude = false, $strict = false)
{
if ($actual instanceof DOMDocument) {
return $actual;
}
if (!is_string($actual)) {
throw new PHPUnit_Framework_Exception('Could not load XML from ' . gettype($actual));
}
if ($actual === '') {
throw new PHPUnit_Framework_Exception('Could not load XML from empty string');
}
// Required for XInclude on Windows.
if ($xinclude) {
$cwd = getcwd();
@chdir(dirname($filename));
}
$document = new DOMDocument();
$document->preserveWhiteSpace = false;
$internal = libxml_use_internal_errors(true);
$message = '';
$reporting = error_reporting(0);
if ('' !== $filename) {
// Necessary for xinclude
$document->documentURI = $filename;
}
if ($isHtml) {
$loaded = $document->loadHTML($actual);
} else {
$loaded = $document->loadXML($actual);
}
if (!$isHtml && $xinclude) {
$document->xinclude();
}
foreach (libxml_get_errors() as $error) {
$message .= "\n" . $error->message;
}
libxml_use_internal_errors($internal);
error_reporting($reporting);
if ($xinclude) {
@chdir($cwd);
}
if ($loaded === false || $strict && $message !== '') {
if ($filename !== '') {
throw new PHPUnit_Framework_Exception(sprintf('Could not load "%s".%s', $filename, $message != '' ? "\n" . $message : ''));
} else {
if ($message === '') {
$message = 'Could not load XML for unknown reason';
}
throw new PHPUnit_Framework_Exception($message);
}
}
return $document;
}
示例6: validateConfig
protected function validateConfig($filename = 'simple.xml')
{
$xml_file = realpath(__DIR__ . '/Fixtures/' . $filename);
$this->assertTrue(is_readable($xml_file), 'XML file ' . $xml_file . ' is not readable.');
$schema_file = realpath(__DIR__ . '/../../../../../src/Environaut/Config/Reader/Schema/environaut.xsd');
$this->assertTrue(is_readable($schema_file), 'Schema file ' . $schema_file . ' is not readable.');
libxml_use_internal_errors(true);
$dom = new \DOMDocument('1.0', 'UTF-8');
$this->assertTrue($dom->load($xml_file, LIBXML_NOCDATA), 'Could not load XML file ' . $xml_file . ' - Error was: ' . print_r(libxml_get_errors(), true));
$this->assertNotEquals(-1, $dom->xinclude(), 'XInclude resolution failed. Error was: ' . print_r(libxml_get_errors(), true));
$valid = $dom->schemaValidate($schema_file);
libxml_use_internal_errors(false);
return $valid;
}
示例7: loadRecordHTML
function loadRecordHTML($recHMLFilename, $styleFilename)
{
global $recID, $outputFilename;
$recHmlDoc = new DOMDocument();
$recHmlDoc->load($recHMLFilename);
$recHmlDoc->xinclude();
if (!$styleFilename) {
return $recHmlDoc->saveHTMLFile($outputFilename);
}
$xslDoc = DOMDocument::load($styleFilename);
$xslProc = new XSLTProcessor();
$xslProc->importStylesheet($xslDoc);
// set up common parameters for stylesheets.
// $xslProc->setParameter('','hbaseURL',HEURIST_BASE_URL);
// $xslProc->setParameter('','dbName',HEURIST_DBNAME);
// $xslProc->setParameter('','dbID',HEURIST_DBID);
$xslProc->setParameter('', 'standalone', '1');
$xslProc->transformToURI($recHmlDoc, $outputFilename);
}
示例8: process
function process($book = NULL)
{
if (!empty($book)) {
// Load the XML source
$xml = new DOMDocument();
$xml->load(SRC_DIR . "/{$book}/book.xml");
// Interpolate all XInclude directives.
$xml->xinclude();
// Save it back out.
$xml->save(SCRIPT_DIR . "/resolved/{$book}.xml");
} else {
// Load the XML source
$xml = new DOMDocument();
$xml->load(SRC_DIR . '/set.xml');
// Interpolate all XInclude directives.
$xml->xinclude();
// Save it back out.
$xml->save(SCRIPT_DIR . '/resolved/set.xml');
}
}
示例9: process
/**
* Call this function to activate the xml handler
*
*
* @param string the name of the xml file to process
* @param string - path of parent. default to root
* @return boolean success
*/
public function process($src, $parent = false)
{
//load xml file
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->load($src);
$doc->xinclude();
$flow = Nexista_Flow::singleton('Nexista_Flow');
//import new doc into flow recursively
$new = $flow->flowDocument->importNode($doc->documentElement, 1);
//append to parent if called for
if ($parent) {
$res = Nexista_Flow::find($parent);
if ($res->length > 0) {
$parent = $res->item(0);
$parent->appendChild($new);
} else {
return false;
}
} else {
$flow->root->appendChild($new);
}
return true;
}
示例10: process
function process()
{
// Load the XML source
$xml = new DOMDocument();
$xml->load(SRC_DIR . '/set.xml');
// Interpolate all XInclude directives.
$xml->xinclude();
// Load the XSLT stylesheet.
$xsl = new DOMDocument();
$xsl->load(DOCBOOK_STYLESHEET_DIR . '/html/docbook.xsl');
// Configure the transformer
$proc = new XSLTProcessor();
if (!$proc->hasExsltSupport()) {
throw new Exception('EXSLT Support not available.');
}
$proc->importStyleSheet($xsl);
// attach the xsl rules
//file_put_contents('test.html', $proc->transformToXml($xml));
$book = $xml->getElementById('tm');
var_dump($book);
var_dump(gettype($book));
file_put_contents('test-book.html', $proc->transformToXml($book));
}
示例11: switch
function __construct($xml, $documentURI = false, $flag = self::XML_FILE)
{
$d = new \DOMDocument();
switch ($flag) {
case self::XML_FILE:
if (!$d->load($xml)) {
throw new \Exception("Failed to load factory XML", 92656);
}
break;
case self::XML_STRING:
if (!$d->loadXML($xml)) {
throw new \Exception("Failed to load factory XML", 92656);
}
if ($documentURI) {
$d->documentURI = $documentURI;
}
break;
default:
throw new \Exception("Invalid construct flag", 95637);
}
if (-1 === $d->xinclude()) {
throw new \Exception("Failed to load factory XML", 92657);
} else {
if (!($this->simp = simplexml_import_dom($d))) {
throw new \Exception("Failed to load factory XML", 92658);
}
}
switch ($tmp = strtolower((string) $this->simp->getName())) {
case 'setup':
case 'methods':
$this->rootEl = $tmp;
break;
default:
throw new \Exception("Unexpected Factory configuration data root element", 17893);
}
}
示例12: import
function import($filename, $params = array())
{
fs::exists($filename) or runtime_error('XSL stylesheet not found: ' . $filename);
$xsl = new DOMDocument();
$xsl->load(fs::normalize($filename));
$import = $xsl->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:import');
$href = $xsl->createAttribute('href');
$href->value = dirname(__FILE__) . '/xpath.xsl';
$import->appendChild($href);
$xsl->firstChild->insertBefore($import, $xsl->firstChild->firstChild);
$xsl->xinclude();
$this->xslt->importStylesheet($xsl);
foreach ($this->params as $name => $value) {
$this->xslt->removeParameter('', $name);
}
$this->params = $params;
$this->xslt->setParameter('', $params);
}
示例13: xinclude
/**
* Substitutes XIncludes in a DOMDocument object.
*
* @param int Bitwise OR of the libxml option constants.
*
* @return int The number of XIncludes in the document.
*
* @author Noah Fontes <noah.fontes@bitextender.com>
* @since 1.0.0
*/
public function xinclude($options = 0)
{
$luie = libxml_use_internal_errors(true);
libxml_clear_errors();
$result = parent::xinclude($options);
if (libxml_get_last_error() !== false) {
$throw = false;
$errors = array();
foreach (libxml_get_errors() as $error) {
if ($error->level != LIBXML_ERR_WARNING) {
$throw = true;
}
$errors[] = sprintf('[%s #%d] Line %d: %s', $error->level == LIBXML_ERR_WARNING ? 'Warning' : ($error->level == LIBXML_ERR_ERROR ? 'Error' : 'Fatal'), $error->code, $error->line, $error->message);
}
libxml_clear_errors();
if ($throw) {
libxml_use_internal_errors($luie);
throw new DOMException(sprintf('Error%s occurred while resolving XInclude directives: ' . "\n\n%s", count($errors) > 1 ? 's' : '', implode("\n", $errors)));
}
}
libxml_use_internal_errors($luie);
// necessary due to a PHP bug, see http://trac.agavi.org/ticket/621 and http://bugs.php.net/bug.php?id=43364
if (version_compare(PHP_VERSION, '5.2.6', '<')) {
$documentUri = $this->documentURI;
$this->loadXml($this->saveXml());
$this->documentURI = $documentUri;
}
return $result;
}
示例14: DOMDocument
echo "Loading and parsing {$ac["INPUT_FILENAME"]}... ";
flush();
$dom = new DOMDocument();
// realpath() is important: omitting it causes severe performance degradation
// and doubled memory usage on Windows.
$didLoad = $dom->load(realpath("{$ac['srcdir']}/{$ac["INPUT_FILENAME"]}"), $LIBXML_OPTS);
// Check if the XML was simply broken, if so then just bail out
if ($didLoad === false) {
echo "failed.\n";
print_xml_errors();
errors_are_bad(1);
}
echo "done.\n";
echo "Validating {$ac["INPUT_FILENAME"]}... ";
flush();
$dom->xinclude();
print_xml_errors();
if ($ac['PARTIAL'] != '' && $ac['PARTIAL'] != 'no') {
// {{{
$dom->validate();
// we don't care if the validation works or not
$node = $dom->getElementById($ac['PARTIAL']);
if (!$node) {
echo "failed.\n";
echo "Failed to find partial ID in source XML: {$ac['PARTIAL']}\n";
errors_are_bad(1);
}
if ($node->tagName !== 'book' && $node->tagName !== 'set') {
// this node is not normally allowed here, attempt to wrap it
// in something else
$parents = array();
示例15: load
/**
* Load an $actual document into a DOMDocument. This is called
* from the selector assertions.
*
* If $actual is already a DOMDocument, it is returned with
* no changes. Otherwise, $actual is loaded into a new DOMDocument
* as either HTML or XML, depending on the value of $isHtml. If $isHtml is
* false and $xinclude is true, xinclude is performed on the loaded
* DOMDocument.
*
* Note: prior to PHPUnit 3.3.0, this method loaded a file and
* not a string as it currently does. To load a file into a
* DOMDocument, use loadFile() instead.
*
* @param string|DOMDocument $actual
* @param boolean $isHtml
* @param string $filename
* @param boolean $xinclude
*
* @return DOMDocument
* @since Method available since Release 3.3.0
* @author Mike Naberezny <mike@maintainable.com>
* @author Derek DeVries <derek@maintainable.com>
* @author Tobias Schlitt <toby@php.net>
*/
public static function load($actual, $isHtml = false, $filename = '', $xinclude = false)
{
if ($actual instanceof DOMDocument) {
return $actual;
}
$document = new DOMDocument();
$internal = libxml_use_internal_errors(true);
$message = '';
$reporting = error_reporting(0);
if ($isHtml) {
$loaded = $document->loadHTML($actual);
} else {
$loaded = $document->loadXML($actual);
}
if ('' !== $filename) {
// Necessary for xinclude
$document->documentURI = $filename;
}
if (!$isHtml && $xinclude) {
$document->xinclude();
}
foreach (libxml_get_errors() as $error) {
$message .= $error->message;
}
libxml_use_internal_errors($internal);
error_reporting($reporting);
if ($loaded === false) {
if ($filename != '') {
throw new PHPUnit_Framework_Exception(sprintf('Could not load "%s".%s', $filename, $message != '' ? "\n" . $message : ''));
} else {
throw new PHPUnit_Framework_Exception($message);
}
}
return $document;
}