本文整理匯總了PHP中XML::_XPT方法的典型用法代碼示例。如果您正苦於以下問題:PHP XML::_XPT方法的具體用法?PHP XML::_XPT怎麽用?PHP XML::_XPT使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類XML
的用法示例。
在下文中一共展示了XML::_XPT方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: _domxpath
/**
* INSTANTIATE DOMDocument
* create or set a new Domdocument based upon a string or an already declared object
**/
private static function _domxpath($path = false, $obj = false, $force = false, $create = false)
{
self::$_LDD = false;
// check that DomDocument and DomXPath are available
// we don't need to send an error since the Core::library will handle that.
if (!class_exists('DomDocument') || !class_exists('DOMXPath')) {
die;
}
// return if $_DOM is already declared and we're not forcing re-instantiation.
if (self::$_DOM instanceof DomDocument && !$force) {
return self::$_DOM;
}
// if no object is specified, instantiate a new one.
if (!$obj) {
self::$_DOM = new DomDocument(self::$_VER, self::$_CHR);
self::$_DOM->preserveWhiteSpace = self::$_PWS;
self::$_DOM->formatOutput = self::$_FOU;
// if object provided is a valid instance, use it instead.
} elseif ($obj instanceof DomDocument) {
self::$_DOM = $obj;
// we override force, so xpath will be reinstantiated again.
$force = true;
// if object isn't dom... show error.
} else {
Core::error('VARTYP', 'LIBTIT', array(__CLASS__, 'object', 'DomDocument'));
}
// if there's a path set it and load it.
if ($path) {
// we make sure the path is set correctly
$path = self::path($path, $create, 3);
// if the specified file doesn't exist, or the file exists
// but it doesn't have a root element defined AND the function
// needs a file to be created, do so.
if ($create && (!file_exists($path) || !self::$_DOM->documentElement)) {
self::$_DOM->appendChild(self::$_DOM->createElement('root'));
self::save(false, false);
self::$_LDD = true;
// if we're not creating but the file already exists and has content on it, load it.
} elseif (!$create && file_exists($path) && filesize($path) > 0) {
self::$_DOM->load($path);
self::$_LDD = true;
}
}
// instantiate the domxpath object
if (!self::$_XPT instanceof DOMXPath || $force) {
self::$_XPT = new DOMXPath(self::$_DOM);
}
return self::$_DOM;
}