1--TEST-- 2DOMNode::normalize() 3--SKIPIF-- 4<?php 5include('skipif.inc'); 6?> 7--FILE-- 8<?php 9 10/* Create an XML document 11 * with structure 12 * <book> 13 * <author></author> 14 * <title>This is the title</title> 15 * </book> 16 * Calculate the number of title text nodes (1). 17 * Add another text node to title. Calculate the number of title text nodes (2). 18 * Normalize author. Calculate the number of title text nodes (2). 19 * Normalize title. Calculate the number of title text nodes (1). 20*/ 21 22$doc = new DOMDocument(); 23 24$root = $doc->createElement('book'); 25$doc->appendChild($root); 26 27$title = $doc->createElement('title'); 28$root->appendChild($title); 29 30$author = $doc->createElement('author'); 31$root->appendChild($author); 32 33$text = $doc->createTextNode('This is the first title'); 34$title->appendChild($text); 35 36echo "Number of child nodes of title = "; 37var_dump($title->childNodes->length); 38 39// add a second text node to title 40$text = $doc->createTextNode('This is the second title'); 41$title->appendChild($text); 42 43echo "Number of child nodes of title after adding second title = "; 44var_dump($title->childNodes->length); 45 46// should do nothing 47$author->normalize(); 48 49echo "Number of child nodes of title after normalizing author = "; 50var_dump($title->childNodes->length); 51 52 53// should concatenate first and second title text nodes 54$title->normalize(); 55 56echo "Number of child nodes of title after normalizing title = "; 57var_dump($title->childNodes->length); 58 59?> 60--EXPECTF-- 61Number of child nodes of title = int(1) 62Number of child nodes of title after adding second title = int(2) 63Number of child nodes of title after normalizing author = int(2) 64Number of child nodes of title after normalizing title = int(1) 65