PHP Doku:: Returns type of node - function.domnode-node-type.html

Verlauf / Chronik / History: (2) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzXML-ManipulationDOM-XMLDOM-XML-FunktionenDomNode->node_type

Ein Service von Reinhard Neidl - Webprogrammierung.

DOM-XML-Funktionen

<<DomNode->node_name

DomNode->node_value>>

DomNode->node_type

(PHP 4 >= 4.1.0)

DomNode->node_type Returns type of node

Beschreibung

int DomNode->node_type ( void )

Returns the type of the node. All possible types are listed in the table in the introduction.

<?php

include 'example.inc';

$dom domxml_open_mem($xmlstr);

$chapter $dom->document_element();

// Let's see the elements contained in chapter
foreach($chapter->child_nodes() as $node) {
  if (
$node->node_type() == XML_ELEMENT_NODE) {
    echo 
$node->node_name() . "\n";
  }
}

?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

title
para

3 BenutzerBeiträge:
- Beiträge aktualisieren...
dysmann
13.04.2008 13:14
node_type return one of the constants listed in the chapter "predefined constants"
wasti dot redl at gmx dot net
23.05.2005 10:40
That's not a parser issue, that's according to the DOM specification.

> Attr objects inherit the Node interface, but since they are not
> actually child nodes of the element they describe, the DOM does
> not consider them part of the document tree.

They are not child nodes, so they shouldn't be in the child_nodes collection.

17.06.2003 21:37
Doesn't pick up nodes of type XML_ATTRIBUTE_NODE (attributes)

Use DomNode->has_attributes() then DomNode->attributes() to retrieve a list (NameNodeMap object) of Attr objects for current node.

Is likely to be a parser issue, I'm using version 2.4.19-4 of libxml2.

Pete.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)