本文整理汇总了PHP中DOMElement::hasChildNodes方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMElement::hasChildNodes方法的具体用法?PHP DOMElement::hasChildNodes怎么用?PHP DOMElement::hasChildNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMElement
的用法示例。
在下文中一共展示了DOMElement::hasChildNodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertXmlToArray
/**
* @param \DOMDocument|\DOMElement $dom
* @return array
*/
private function convertXmlToArray($dom)
{
$result = array();
if ($dom->hasChildNodes()) {
$children = $dom->childNodes;
if (1 === $children->length) {
$child = $children->item(0);
if ($child->nodeType == XML_TEXT_NODE) {
$result['_value'] = $child->nodeValue;
return urldecode(count($result) == 1 ? $result['_value'] : $result);
}
}
$groups = array();
foreach ($children as $child) {
if (!isset($result[$child->nodeName])) {
$result[$child->nodeName] = $this->convertXmlToArray($child);
} else {
if (!isset($groups[$child->nodeName])) {
$result[$child->nodeName] = array($result[$child->nodeName]);
$groups[$child->nodeName] = 1;
}
$result[$child->nodeName][] = $this->convertXmlToArray($child);
}
}
}
return $result;
}
示例2: visitEnterSelectorSequence
/**
* If here is already data in the buffer, add a separator before starting the next.
*
* @return boolean
*/
public function visitEnterSelectorSequence()
{
if ($this->_current === $this->_dom->documentElement && $this->_current->hasChildNodes()) {
$this->_current->appendChild($this->_dom->createElementNs($this->_xmlns, 'text'))->appendChild($this->_dom->createCDATASection(', '));
}
return $this->start($this->appendElement('selector'));
}
示例3: toArrayTree
/**
* @param \DOMNode $node
* @param $path
* @return array|string
*/
protected function toArrayTree(\DOMElement $node, $path)
{
$hasChildren = false;
$record = [];
$currentPath = $path . '/' . $node->nodeName;
if ($node->hasChildNodes()) {
foreach ($node->childNodes as $child) {
if ($child instanceof \DOMElement) {
$hasChildren = true;
if (in_array($currentPath, $this->iterationPath) && in_array($child->nodeName, $this->iterationTag)) {
$record[$child->nodeName][] = $this->toArrayTree($child, $currentPath);
} else {
$record[$child->nodeName] = $this->toArrayTree($child, $currentPath);
}
}
}
}
if ($node->hasAttributes()) {
$record["_attributes"] = [];
foreach ($node->attributes as $attr) {
$record["_attributes"][$attr->name] = $attr->value;
}
if (!$hasChildren) {
$record["_value"] = $node->nodeValue;
}
} elseif (!$hasChildren) {
$record = trim($node->nodeValue);
}
return $record;
}
示例4: parseParagraph
function parseParagraph(DOMDocument $slide_xml, DOMElement $paragraph)
{
$runs = array();
if ($paragraph->hasChildNodes()) {
$paragraph_nodes = $paragraph->childNodes;
//DOMNodeList
$i = 0;
// running through the runs here
foreach ($paragraph_nodes as $paragraph_node) {
if ($paragraph_node->nodeName == "a:fld") {
$runs[$i]['content'] = $this->parseNodeField($slide_xml, $paragraph_node);
}
if ($paragraph_node->nodeName == "a:pPr") {
$runs['properties'] = $this->parseNodeProperties($paragraph_node);
continue;
}
if ($paragraph_node->nodeName == 'a:r') {
list($string, $run_parameters) = $this->parseNodeRun($slide_xml, $paragraph_node);
$runs[$i]['content'] = $string;
foreach ($run_parameters as $parameter_name => $parameter_value) {
$runs[$i][$parameter_name] = $parameter_value;
}
}
// remove empty runs
if (empty($runs[$i]['content'])) {
unset($runs[$i]);
}
if (empty($runs['properties']['bullet_type'])) {
unset($runs['properties']['bullet_type']);
}
$i++;
}
}
return $runs;
}
示例5: map
/**
* Map from DOMElement to neutral field map.
*
* @param DOMElement $itemDataFromFeed
* @return array map of neutral fields to values.
*/
public function map($itemDataFromFeed)
{
$map = array_fill_keys([$this->fieldMap[FeedMeItemModelExtension::TitleFieldName], $this->fieldMap[FeedMeItemModelExtension::BodyFieldName], $this->fieldMap[FeedMeItemModelExtension::ExternalIDFieldName], $this->fieldMap[FeedMeItemModelExtension::LinkFieldName], $this->fieldMap[FeedMeItemModelExtension::LastPublishedFieldName]], '');
if ($itemDataFromFeed->hasChildNodes()) {
$this->children($itemDataFromFeed->childNodes, $map);
}
return $map;
}
示例6: getChildByName
/**
* @param string $name
* @return bool
*/
public function getChildByName($name)
{
if ($this->fieldNode->hasChildNodes())
{
$childNodes = $this->fieldNode->childNodes;
for ($i = 0; $i < $childNodes->length; $i++)
{
$childNode = $childNodes->item($i);
if ($childNode instanceof DOMElement && $childNode->hasAttribute('name'))
{
if ($childNode->getAttribute('name') == $name)
{
return $childNode->nodeValue;
}
}
}
}
return false;
}
示例7: parse
/**
* Class EcasPhpCASParser
* @param \DOMElement $root XML element coming from phpCAS
* @return array Attributes
* @see \phpCAS
*/
public function parse(\DOMElement $root)
{
phpCAS::trace('Found attribute ' . $root->nodeName);
$result = array();
if ($root->hasAttributes()) {
$attrs = $root->attributes;
foreach ($attrs as $attr) {
if ($attr->name == 'number') {
continue;
}
phpCAS::trace('Additional attribute ' . $attr->name . ' : ' . $attr->value);
$result['@attributes'][$attr->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 = array();
foreach ($children as $child) {
$nodeName = str_replace('cas:', '', $child->nodeName);
phpCAS::traceBegin();
if ($nodeName == 'groups') {
$result['groups'] = array();
phpCas::traceBegin();
foreach ($child->childNodes as $groupChild) {
$result['groups'][] = $this->parse($groupChild);
}
phpCAS::traceEnd('Parsed groups');
} elseif (!isset($result[$nodeName])) {
$result[$nodeName] = $this->parse($child);
} else {
if (!isset($groups[$nodeName])) {
$result[$nodeName] = array($result[$nodeName]);
$groups[$nodeName] = 1;
}
$result[$nodeName][] = $this->parse($child);
}
phpCAS::traceEnd();
}
}
return $result;
}
示例8: _appendNodeAlphabetically
/**
*
* @param DOMElement $rootNode
* @param DOMElement $newNode
*/
protected function _appendNodeAlphabetically(DOMElement $rootNode, DOMElement $newNode)
{
if ($newNode->hasChildNodes()) {
$refNode = null;
foreach ($rootNode->childNodes as $child) {
if ($child instanceof DOMElement && $child->tagName > $newNode->tagName) {
$refNode = $child;
break;
}
}
if ($refNode) {
$rootNode->insertBefore($newNode, $refNode);
} else {
$rootNode->appendChild($newNode);
}
}
}
示例9: purgeEmptyElementsNode
/**
* Enlève les élements vide d'un noeud
*
* @param DOMElement $node DOMElement
*
* @return void
*/
function purgeEmptyElementsNode($node)
{
// childNodes undefined for non-element nodes (eg text nodes)
if ($node->childNodes) {
// Copy childNodes array
$childNodes = array();
foreach ($node->childNodes as $childNode) {
$childNodes[] = $childNode;
}
// Browse with the copy (recursive call)
foreach ($childNodes as $childNode) {
$this->purgeEmptyElementsNode($childNode);
}
}
// Remove if empty
if (!$node->hasChildNodes() && !$node->hasAttributes() && $node->nodeValue === "") {
$node->parentNode->removeChild($node);
}
}
示例10: getNavigationHtml
/**
* Get navigation html
*
* @return string
*/
public function getNavigationHtml()
{
$modules = Uni_Fox::getModules();
$doc = new DOMDocument();
$this->finalMenuTree = new DOMDocument();
$this->finalMenuTree->formatOutput = true;
$this->root = Uni_Data_XDOMDocument::createNode('menus', NULL, $this->finalMenuTree);
$this->finalMenuTree->appendChild($this->root);
$this->sourceQueue = array();
$this->targetQueue = array();
if (is_array($modules)) {
foreach ($modules as $module) {
if ($doc->load($module['path'] . DIRECTORY_SEPARATOR . 'conf' . DIRECTORY_SEPARATOR . 'config.xml')) {
$xPath = new DOMXPath($doc);
$menus = $xPath->query('/config/admin/menus');
if ($menus->length > 0) {
foreach ($menus as $menu) {
$this->getFinalMenuTree($menu);
}
}
}
}
}
if (isset($this->finalMenuTree) && $this->root->hasChildNodes()) {
$this->optimizeMenuTree();
$this->mnuDoc = new DOMDocument();
$this->mnuDoc->formatOutput = true;
$this->mnuRoot = Uni_Data_XDOMDocument::createNode('ul', array('class' => 'admin-nav-menu'), $this->mnuDoc);
$this->mnuDoc->appendChild($this->mnuRoot);
$this->createMenu($this->root);
if (isset($this->mnuDoc)) {
$this->menuHTML = $this->mnuDoc->saveXML($this->mnuRoot);
return $this->menuHTML;
}
}
}
示例11: _parseDefaultEntry
/**
* Allocates member variables of currentElement or can be used for subfields.
* Parses for default values and the possibility of edit and make it public.
* @param DOMElement $field
* @param Publish_Model_FormElement $subfield
* @return false if there are no child nodes
*/
private function _parseDefaultEntry($currentElement, DOMElement $field, Publish_Model_FormElement $subfield = null)
{
if ($field->hasChildNodes()) {
foreach ($field->getElementsByTagname('default') as $default) {
if ($default->hasAttributes()) {
$defaultArray = array();
$forValue = $default->getAttribute('for');
if (isset($forValue)) {
$defaultArray['for'] = $forValue;
}
$value = $default->getAttribute('value');
if (isset($value)) {
$defaultArray['value'] = $value;
}
$edit = $default->getAttribute('edit');
if (isset($edit)) {
$defaultArray['edit'] = $edit;
}
$public = $default->getAttribute('public');
if (isset($public)) {
$defaultArray['public'] = $public;
}
if (!isset($subfield)) {
$currentElement->setDefaultValue($defaultArray);
$this->log->debug(__METHOD__ . " : " . $value);
} else {
$subfield->setDefaultValue($defaultArray);
}
} else {
return false;
}
}
}
}
示例12: find_unique_key
protected function find_unique_key(DOMElement $el)
{
if ($el->hasChildNodes()) {
if ($el->childNodes->length) {
foreach ($el->childNodes as $child) {
if ($child instanceof DOMElement) {
if (!in_array($child->nodeName, $this->_unique_key)) {
$this->_unique_key[] = $child->nodeName;
}
$this->find_unique_key($child);
}
}
}
}
}
示例13: hasBlockChild
protected function hasBlockChild(\DOMElement $element)
{
if ($element->hasChildNodes()) {
$filter = new DOMElementFilter(new RecursiveDOMIterator($element));
$recursive = new \RecursiveIteratorIterator($filter, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($recursive as $element) {
if ($this->isBlockElement($element)) {
return TRUE;
}
}
}
return FALSE;
}
示例14: parseSpecVersion
/**
* Search for min and max supported UPnP version
*
* @access protected
*
* @param \DOMDocument $doc
* @param \DOMElement $tag
*/
protected function parseSpecVersion(DOMDocument &$doc, $tag)
{
if ($tag->hasChildNodes()) {
foreach ($tag->childNodes as $node) {
switch ($node->tagName) {
case 'major':
$this->specVersion_max = $node->textContent;
break;
case 'minor':
$this->specVersion_min = $node->textContent;
break;
}
}
}
}
示例15: _parseToForm
/**
* Parse the given DOMElement into containers and widgets and add them to the form
*
* @param DOMElement $element
* @param One_Form_Container_Abstract $container
*/
protected static function _parseToForm(DOMElement $element, One_Form_Container_Abstract $container)
{
$current = strtolower($element->localName);
if ($current == 'constraints' || $current == 'constraint') {
return NULL;
}
$widgetClass = self::identifyElement($current);
if (is_null($widgetClass)) {
return NULL;
}
if (is_object($widgetClass)) {
$widgetClass = get_class($widgetClass);
}
if (preg_match('/^One_Form_Container/', $widgetClass) && $widgetClass != 'One_Form_Container_Form') {
$attributes = array();
$rawAttributes = $element->attributes;
for ($i = 0; $i < $rawAttributes->length; $i++) {
$attribute = $rawAttributes->item($i);
$attributes[$attribute->localName] = $attribute->value;
}
if (false === isset($attributes['language'])) {
$attributes['language'] = strtolower(One_Config::get('app.language'));
}
$subContainerId = isset($attributes['id']) ? $attributes['id'] : NULL;
$subContainer = new $widgetClass($subContainerId, $attributes);
// containers can contain other containers or widgets
if ($element->hasChildNodes()) {
foreach ($element->childNodes as $child) {
if ($child instanceof DOMElement) {
self::_parseToForm($child, $subContainer);
}
}
}
$container->addContainer($subContainer);
} else {
if ($element->hasAttribute('role')) {
// Get cache in preparation of possible option-caching
$session = One_Repository::getSession();
$parts = explode(':', $element->getAttribute('role'));
if (count($parts) != 2) {
throw new One_Exception('You must define a valid role');
}
$relation = One_Repository::getRelation($parts[0]);
$role = $relation->getRole($parts[1]);
$relScheme = One_Repository::getScheme($role->schemeName);
// set the name and id of the so it will be recognised as a related field
$element->setAttribute('id', 'r__' . $element->getAttribute('role'));
$element->setAttribute('name', 'r__' . $element->getAttribute('role'));
if ($element->hasAttribute('optionsFrom')) {
$sessionCacheName = md5($relScheme->getName() . '#' . $element->getAttribute('optionsFrom'));
if (false === $element->hasAttribute('cacheOptions') || $element->hasAttribute('cacheOptions') && false === $session->varExists($sessionCacheName, 'One_Form_Cache')) {
$relView = new One_View($relScheme->getName(), $element->getAttribute('optionsFrom'));
$rawOptions = trim($relView->show());
$options = json_decode($rawOptions, 1);
if (false === is_array($options)) {
$options = array();
}
if ($element->hasAttribute('cacheOptions')) {
$session->set($sessionCacheName, $options, 'One_Form_Cache');
}
} else {
$options = $session->get($sessionCacheName, 'One_Form_Cache');
}
} else {
if (!$element->hasAttribute('targetAttribute')) {
$targetAttr = $relScheme->getIdentityAttribute()->getName();
} else {
$targetAttr = $element->getAttribute('targetAttribute');
}
$sessionCacheName = md5($relScheme->getName() . '#' . $targetAttr . '#' . $element->getAttribute('publishedOnly'));
if (false === $element->hasAttribute('cacheOptions') || $element->hasAttribute('cacheOptions') && false === $session->varExists($sessionCacheName, 'One_Form_Cache')) {
$q = One_Repository::selectQuery($relScheme->getName());
$tparts = explode(':', $targetAttr);
foreach ($tparts as $tkey => $tval) {
if (in_array(substr($tval, 0, 1), array('(', '['))) {
$tparts[$tkey] = substr($tval, 1) . '+';
} else {
$tparts[$tkey] = $tval . '+';
}
}
$q->setOrder($tparts);
$results = $q->execute(false);
$options = array();
foreach ($results as $result) {
$idAttr = $relScheme->getIdentityAttribute()->getName();
$valAttr = $targetAttr;
$val = '';
foreach (explode(':', $targetAttr) as $tkey => $tval) {
switch (substr($tval, 0, 1)) {
case '(':
$tval = substr($tval, 1);
$val .= '(' . $result->{$tval} . ') ';
break;
case '[':
//.........这里部分代码省略.........