本文整理汇总了PHP中DomDocument::hasChildNodes方法的典型用法代码示例。如果您正苦于以下问题:PHP DomDocument::hasChildNodes方法的具体用法?PHP DomDocument::hasChildNodes怎么用?PHP DomDocument::hasChildNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomDocument
的用法示例。
在下文中一共展示了DomDocument::hasChildNodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: domToArray
/**
* From http://stackoverflow.com/questions/14553547/what-is-the-best-php-dom-2-array-function
*
* @param \DomDocument $root
* @return array
*/
protected function domToArray($root)
{
$result = [];
if ($root->hasAttributes()) {
$attrs = $root->attributes;
foreach ($attrs as $attr) {
$name = str_replace('cas:', '', $attr->name);
$result['attributes'][$name] = $attr->value;
}
}
if ($root->hasChildNodes()) {
$children = $root->childNodes;
if ($children->length == 1) {
$child = $children->item(0);
if ($child->nodeType == XML_TEXT_NODE) {
$result['value'] = $child->nodeValue;
return count($result) == 1 ? $result['value'] : $result;
}
}
$groups = [];
foreach ($children as $child) {
$childName = str_replace('cas:', '', $child->nodeName);
if (!isset($result[$childName])) {
$result[$childName] = $this->domToArray($child);
} else {
if (!isset($groups[$childName])) {
$result[$childName] = [$result[$childName]];
$groups[$childName] = 1;
}
$result[$childName][] = $this->domToArray($child);
}
}
}
return $result;
}
示例2: parse_session_status_XML
function parse_session_status_XML($xml_)
{
if (!$xml_ || strlen($xml_) == 0) {
return false;
}
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML($xml_);
if (!$buf) {
return false;
}
if (!$dom->hasChildNodes()) {
return false;
}
$node = $dom->getElementsByTagname('session')->item(0);
if (is_null($node)) {
return false;
}
if (!$node->hasAttribute('id')) {
return false;
}
if (!$node->hasAttribute('status')) {
return false;
}
$ret = array('id' => $node->getAttribute('id'), 'server' => $_SERVER['REMOTE_ADDR'], 'status' => $node->getAttribute('status'), 'reason' => NULL, 'role' => NULL);
if ($node->hasAttribute('reason')) {
$ret['reason'] = $node->getAttribute('reason');
}
if ($node->hasAttribute('role')) {
$ret['role'] = $node->getAttribute('role');
}
return $ret;
}
示例3: parse_server_status_XML
function parse_server_status_XML($xml_)
{
if (!$xml_ || strlen($xml_) == 0) {
return false;
}
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML($xml_);
if (!$buf) {
return false;
}
if (!$dom->hasChildNodes()) {
return false;
}
$node = $dom->getElementsByTagname('server')->item(0);
if (is_null($node)) {
return false;
}
if (!$node->hasAttribute('name')) {
return false;
}
if (!$node->hasAttribute('status')) {
return false;
}
return array('name' => $node->getAttribute('name'), 'status' => $node->getAttribute('status'));
}
示例4: compile
protected function compile()
{
$this->templateDocument = new DOMDocument();
if (!empty($this->templateString)) {
libxml_use_internal_errors(true);
$this->templateDocument->loadHTML($this->templateString, LIBXML_HTML_NODEFDTD);
libxml_use_internal_errors(false);
}
$this->templateXPath = new DOMXPath($this->templateDocument);
if ($this->templateDocument->hasChildNodes()) {
foreach ($this->templateDocument->childNodes as $node) {
$this->compileNode($node, $this->templateDocument);
}
$removals = $this->templateXPath->query('//*[@delete="1"]');
foreach ($removals as $remove) {
$remove->parentNode->removeChild($remove);
}
}
}
示例5: renderElement
/**
* Renders the element to string
* @return string
*/
public function renderElement()
{
if (isset($this->tag) && $this->tag instanceof DOMElement) {
if ($this->dom->hasChildNodes()) {
$this->dom->insertBefore($this->tag, $this->dom->firstChild);
} else {
$this->dom->appendChild($this->tag);
}
}
$out = '';
foreach ($this->dom->childNodes as $node) {
$out .= $this->dom->saveXml($node);
}
return $out;
}
示例6: parse_premium_sign_XML
function parse_premium_sign_XML($xml_)
{
if (!$xml_ || strlen($xml_) == 0) {
return false;
}
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML($xml_);
if (!$buf) {
return false;
}
if (!$dom->hasChildNodes()) {
return false;
}
$node = $dom->getElementsByTagname('message')->item(0);
if (is_null($node)) {
return false;
}
return $node->textContent;
}
示例7: init_saml2_auth
function init_saml2_auth()
{
global $sessionmanager_url;
$sm = new SessionManager($sessionmanager_url);
$ret = $sm->query('auth_params');
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML($ret);
if (!$buf) {
send_error("Unable to retrieve the SAML parameters");
}
if (!$dom->hasChildNodes()) {
send_error("Unable to retrieve the SAML parameters");
}
$saml2 = $dom->getElementsByTagname('SAML2')->item(0);
$url = $saml2->getElementsByTagname('idp_url')->item(0)->textContent;
$fingerprint = $saml2->getElementsByTagname('idp_fingerprint')->item(0)->textContent;
$cert = $saml2->getElementsByTagname('idp_cert')->item(0)->textContent;
$settings = build_saml_settings($url, $fingerprint, $cert);
return new OneLogin_Saml2_Auth($settings);
}
示例8: parse_session_dump_XML
function parse_session_dump_XML($xml_)
{
if (!$xml_ || strlen($xml_) == 0) {
return false;
}
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML($xml_);
if (!$buf) {
return false;
}
if (!$dom->hasChildNodes()) {
return false;
}
$node = $dom->getElementsByTagname('session')->item(0);
if (is_null($node)) {
return false;
}
if (!$node->hasAttribute('id')) {
return false;
}
$ret = array('id' => $node->getAttribute('id'), 'server' => $_SERVER['REMOTE_ADDR'], 'dump' => array());
foreach ($dom->getElementsByTagname('dump') as $node) {
if (!$node->hasAttribute('name')) {
return false;
}
$name = $node->getAttribute('name');
$textNode = null;
foreach ($node->childNodes as $child_node) {
if ($child_node->nodeType != XML_TEXT_NODE) {
continue;
}
$textNode = $child_node;
break;
}
if ($textNode === null) {
return false;
}
$ret['dump'][$name] = trim($textNode->wholeText);
}
return $ret;
}
示例9: parse_logout_XML
function parse_logout_XML($xml_, &$mode_)
{
if (!$xml_ || strlen($xml_) == 0) {
return false;
}
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML($xml_);
if (!$buf) {
return false;
}
if (!$dom->hasChildNodes()) {
return false;
}
$node = $dom->getElementsByTagname('logout')->item(0);
if (is_null($node)) {
return false;
}
if ($node->hasAttribute('mode')) {
$mode_ = $node->getAttribute('mode');
}
return true;
}
示例10: parse_icon_XML
function parse_icon_XML($xml_)
{
if (!$xml_ || strlen($xml_) == 0) {
return false;
}
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML($xml_);
if (!$buf) {
return false;
}
if (!$dom->hasChildNodes()) {
return false;
}
$ret = array('server' => $_SERVER['REMOTE_ADDR'], 'application' => array());
$application_node = $dom->getElementsByTagName('application')->item(0);
if (is_null($application_node)) {
return false;
}
if (!$application_node->hasAttribute('id')) {
return false;
}
$ret['application']['id'] = $application_node->getAttribute('id');
return $ret;
}
示例11: get_users_list
function get_users_list()
{
if (!defined('SESSIONMANAGER_HOST')) {
return false;
}
global $sessionmanager_url;
$sm = new SessionManager($sessionmanager_url);
$ret = $sm->query('userlist');
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML($ret);
if (!$buf) {
return false;
}
if (!$dom->hasChildNodes()) {
return false;
}
$users_node = $dom->getElementsByTagname('users')->item(0);
if (is_null($users_node)) {
return false;
}
$users = array();
foreach ($users_node->childNodes as $user_node) {
if ($user_node->hasAttribute('login')) {
$users[$user_node->getAttribute('login')] = strlen($user_node->getAttribute('displayname')) > 32 ? substr($user_node->getAttribute('displayname'), 0, 32) . '...' : $user_node->getAttribute('displayname');
}
}
natcasesort($users);
if (count($users) == 0) {
return false;
}
return $users;
}
示例12: wait_ready
function wait_ready($tr, $sessionmanager_url, $cookie)
{
add($tr['wait_aps']);
flush();
$count = 20;
while ($count-- > 0) {
$cookies = array('PHPSESSID' => $cookie);
$xml = query_sm($sessionmanager_url . '/session_status', "", $cookies);
if (!$xml) {
error($tr['unable_to_reach_sm']);
}
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML($xml);
if (!$buf) {
error($tr['internal_error']);
}
if (!$dom->hasChildNodes()) {
error($tr['internal_error']);
}
$session_node = $dom->getElementsByTagName('session');
if (count($session_node) != 1) {
error($tr['internal_error']);
}
$session_node = $session_node->item(0);
if (!is_object($session_node)) {
error($tr['internal_error']);
}
$status = $session_node->getAttribute('status');
if ($status == 'ready') {
return;
}
sleep(2);
}
add('Result=' . $tr['session_end_unexpected']);
die;
}
示例13: orderAction
public function orderAction($action_)
{
$server = Abstract_Server::load($this->server);
if (!$server) {
Logger::error('main', 'VDI_VM::orderAction unable to load Server \'' . $this->server . '\'');
return false;
}
$dom = new DomDocument('1.0', 'utf-8');
$node = $dom->createElement('vm');
$node->setAttribute('id', $this->id);
$node->setAttribute('action', $action_);
$dom->appendChild($node);
$xml = $dom->saveXML();
$xml = query_url_post_xml($server->getBaseURL() . '/hypervisor/vm/manage', $xml);
if (!$xml) {
$server->isUnreachable();
Logger::error('main', 'VDI_VM::orderAction server \'' . $server->fqdn . '\' is unreachable');
return false;
}
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML($xml);
if (!$buf) {
return false;
}
if (!$dom->hasChildNodes()) {
return false;
}
$node = $dom->getElementsByTagname('vm')->item(0);
if (is_null($node)) {
return false;
}
$status = $node->getAttribute('status');
if ($status != 'OK') {
Logger::error('main', 'VDI_VM::orderAction failed');
return false;
}
return true;
}
示例14: deleteNetworkFolder
public function deleteNetworkFolder($name_, $force_ = false)
{
if (!is_array($this->roles) || !array_key_exists(Server::SERVER_ROLE_FS, $this->roles)) {
Logger::critical('main', 'SERVER::deleteNetworkFolder - Not an FS');
return false;
}
if (!$this->isOnline()) {
Logger::debug('main', 'Server::deleteNetworkFolder("' . $name_ . '") server "' . $this->fqdn . ':' . $this->web_port . '" is not online');
return false;
}
$dom = new DomDocument('1.0', 'utf-8');
$node = $dom->createElement('share');
$node->setAttribute('id', $name_);
$node->setAttribute('force', $force_);
$dom->appendChild($node);
$xml = $dom->saveXML();
$xml = query_url_post_xml($this->getBaseURL() . '/fs/share/delete', $xml);
if (!$xml) {
$this->isUnreachable();
Logger::error('main', 'Server::deleteNetworkFolder server \'' . $this->fqdn . '\' is unreachable');
return false;
}
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML($xml);
if (!$buf) {
return false;
}
if (!$dom->hasChildNodes()) {
return false;
}
$node = $dom->getElementsByTagname('share')->item(0);
if (is_null($node)) {
return false;
}
if (!$node->hasAttribute('id')) {
return false;
}
return true;
}
示例15: parseSessionCreate
public function parseSessionCreate($xml_)
{
if (!$xml_ || strlen($xml_) == 0) {
Logger::error('main', 'SessionManagement::parseSessionCreate - Empty content');
return false;
}
$dom = new DomDocument('1.0', 'utf-8');
$buf = @$dom->loadXML($xml_);
if (!$buf) {
Logger::error('main', 'SessionManagement::parseSessionCreate - Not an XML');
return false;
}
if (!$dom->hasChildNodes()) {
Logger::error('main', 'SessionManagement::parseSessionCreate - Empty XML');
return false;
}
$node = $dom->getElementsByTagname('session')->item(0);
if (is_null($node)) {
Logger::error('main', 'SessionManagement::parseSessionCreate - No "session" node');
return false;
}
if (!$node->hasAttribute('id')) {
Logger::error('main', 'SessionManagement::parseSessionCreate - No "id" attribute in "session" node');
return false;
}
return true;
}