PHP.mk документација

DOMNodeList

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

class.domnodelist.php PHP.net прокси Преводот е вчитан
Оригинал на PHP.net
Патека class.domnodelist.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + преведен приказ Кодовите, табелите и белешките остануваат читливи во истиот тек.
DOMNodeList

Референца за `class.domnodelist.php` со подобрена типографија и навигација.

class.domnodelist.php

Класата DOMNodeList

класата mysqli_driver

Вовед

Претставува жива листа од јазли.

Синопсис на класата

class DOMNodeList implements IteratorAggregate, luk4z_7 at hotmail dot com {
/* Својства */
public readonly int $length;
/* Методи */
public count(): int
}

Својства

length

Бројот на јазли во листата. Опсегот на валидни индекси на детски јазли е од 0 до length - 1 inclusive.

Дневник на промени

Верзија = NULL
8.0.0 DOMNodeList implements IteratorAggregate сега. Претходно, Траверзабилно беше имплементирано наместо тоа.
7.2.0 На luk4z_7 at hotmail dot com интерфејсот е имплементиран и ја враќа вредноста на length property.

Белешки

Забелешка: Јазлите во листата може да се пристапат со синтаксија на низа.

Содржина

Белешки од корисници 9 белешки

ignitedfirestarter на gmail точка com
пред 13 години
If you want to recurse over a DOM then this might help: 
<?php 

/**
 * PHP's DOM classes are recursive but don't provide an implementation of 
 * RecursiveIterator. This class provides a RecursiveIterator for looping over DOMNodeList
 */
class DOMNodeRecursiveIterator extends ArrayIterator implements RecursiveIterator {
  
  public function __construct (DOMNodeList $node_list) {
    
    $nodes = array();
    foreach($node_list as $node) {
      $nodes[] = $node;
    }
    
    parent::__construct($nodes);
    
  }
  
  public function getRecursiveIterator(){
    return new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST);
  }
  
  public function hasChildren () {
    return $this->current()->hasChildNodes();
  }

  
  public function getChildren () {
    return new self($this->current()->childNodes);
  }
  
}
?>
brack на wjp точка de
пред 17 години
In PHP 5.2.5 (Windows) it is not possible to iterate correctly over the DOMNodeList object returned by DOMNode->childNodes using foreach. Instead I had to use the for loop in conjunction with the item() method of DOMNodeList for iterating over all child nodes correctly.

I don't know whether this is really a bug, but apparently it is.
niko на yopmail точка com
пред 4 години
It's worth to mention that DOMNodeList is not an Array,  so you have to convert first to an array before to use for, foreach or array_map, array_filter, array_walk functions.

Use iterator_to_array to make the conversion ( since PHP 5.1.0 ) .

<code>
  /* @ suppress warning var_dump not yet implemented for class */

@array_walk( iterator_to_array( $Some_NodeList ), 'var_dump' ) );

foreach( iterator_to_array( $Some_NodeList ) as $node )
    @var_dump( $node );

</code>

Hope is usefull.
mta59066 на gmail точка com
пред 15 години
Note that $length is calculated (php5.3.2).
Iterating over a large NodeList may be time expensive.

Prefer :
$nb = $nodelist->length;
for($pos=0; $pos<$nb; $pos++)

Than:
for($pos=0; $pos<$nodelist->length; $pos++)

I had a hard time figuring that out...
c точка 1 на smithies точка org
пред 17 години
You can modify, and even delete, nodes from a DOMNodeList if you iterate backwards:

$els = $document->getElementsByTagName('input');
for ($i = $els->length; --$i >= 0; ) {
  $el = $els->item($i);
  switch ($el->getAttribute('name')) {
    case 'MAX_FILE_SIZE' :
      $el->parentNode->removeChild($el);
    break;
    case 'inputfile' :
      $el->setAttribute('type', 'text');
    //break;
  }
}
drichter на muvicom точка de
пред 17 години
I have done some testing and have found 2 results:
(My System: Win XP with PHP 5.2.1)

1) Iteration with foreach does function correctly as "james dot j dot hackett at gmail dot com" writes, _if_ you only do readonly stuff with foreach or minor writings of some attributes.

2) foreach does not function, if you are doing some DOM-Operations while iterating. In my situation it was adding the iterated $node as an child to an new node:

$newNode = $dom->createElement('newNode') ;
foreach ($nodeList as $node) {
  echo $node->nodeValue ;
  $newNode->appendChild($node) ;
}

This only gives you the first element ...

I'm interpreting it as an confusing but correct behavior because of the changes within the $dom-object while appending the node at an additional place ... 

So, if you want to do something like 2) use for, length and item() :)
james точка j точка hackett на gmail точка com
пред 17 години
In Response to 'kassah at gmail'

You don't need to convert a DOMNodeList to an array in order iterate through it using 'foreach'.  You can use foreach directly with the DOMNodeList.

$nodeList = $someDomDocument->getElementsbytagname('user');

foreach ($nodeList as $node) {
    echo $node->nodeValue;
}
bobvandell на hotmail точка com
пред 17 години
That's actually incorrect. You can use function results as objects. It makes building an API for your database very clean and neat. For example:

Our code:

$articles = Node::screate('tags', 123456)->assets('like:title:test')->articles;

We use the above code to get articles that are linked to assets that are linked to a specific tag in our database.
drichter на muvicom точка de
пред 17 години
Addition to my first note:

An traditional for-loop does not allow you to change the DOM-tree while looping - the effects are the nearly the same as with foreach. So you have to collect the nodes in an array and do the tree-altering stuff within a second loop (looping the array this time ...)
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.