本文整理汇总了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;
}