1--TEST-- 2Test 1: Creating Elements with and without Namespaces 3--SKIPIF-- 4<?php require_once('skipif.inc'); ?> 5--FILE-- 6<?php 7 8print " 1 DOMDocument::createElement('valid')\n"; 9try { 10 $dom = new domDocument; 11 $dom->createElement('valid'); 12 print "valid\n"; 13} catch (Exception $e) { 14 print $e->getMessage() . "\n"; 15} 16 17print " 2 DOMDocument::createElement('-invalid')\n"; 18try { 19 $dom = new domDocument; 20 $dom->createElement('-invalid'); 21 print "valid\n"; 22} catch (Exception $e) { 23 print $e->getMessage() . "\n"; 24} 25 26print " 3 DOMDocument::createElement(' ')\n"; 27try { 28 $dom = new domDocument; 29 $dom->createElement(' '); 30 print "valid\n"; 31} catch (Exception $e) { 32 print $e->getMessage() . "\n"; 33} 34 35print " 4 DOMDocument::createElement('prefix:valid')\n"; 36try { 37 $dom = new domDocument; 38 $dom->createElement('prefix:valid'); 39 print "valid\n"; 40} catch (Exception $e) { 41 print $e->getMessage() . "\n"; 42} 43 44print " 5 DOMDocument::createElementNS('http://valid.com', 'valid')\n"; 45try { 46 $dom = new domDocument; 47 $dom->createElementNS('http://valid.com', 'valid'); 48 print "valid\n"; 49} catch (Exception $e) { 50 print $e->getMessage() . "\n"; 51} 52 53print " 6 DOMDocument::createElementNS('http://valid.com', 'prefix:valid')\n"; 54try { 55 $dom = new domDocument; 56 $dom->createElementNS('http://valid.com', 'prefix:valid'); 57 print "valid\n"; 58} catch (Exception $e) { 59 print $e->getMessage() . "\n"; 60} 61 62print " 7 DOMDocument::createElementNS('http://valid.com', '-invalid')\n"; 63try { 64 $dom = new domDocument; 65 $dom->createElementNS('http://valid.com', '-invalid'); 66 print "valid\n"; 67} catch (Exception $e) { 68 print $e->getMessage() . "\n"; 69} 70 71print " 8 DOMDocument::createElementNS('http://valid.com', 'prefix:-invalid')\n"; 72try { 73 $dom = new domDocument; 74 $dom->createElementNS('http://valid.com', 'prefix:-invalid'); 75 print "valid\n"; 76} catch (Exception $e) { 77 print $e->getMessage() . "\n"; 78} 79 80print " 9 DOMDocument::createElementNS('', 'prefix:invalid')\n"; 81try { 82 $dom = new domDocument; 83 $dom->createElementNS('', 'prefix:invalid'); 84 print "valid\n"; 85} catch (Exception $e) { 86 print $e->getMessage() . "\n"; 87} 88 89print "10 DOMDocument::createElementNS('http://valid.com', 'prefix:valid:invalid')\n"; 90try { 91 $dom = new domDocument; 92 $dom->createElementNS('http://valid.com', 'prefix:valid:invalid'); 93 print "valid\n"; 94} catch (Exception $e) { 95 print $e->getMessage() . "\n"; 96} 97 98print "11 DOMDocument::createElementNS('http://valid.com', '-prefix:valid')\n"; 99try { 100 $dom = new domDocument; 101 $dom->createElementNS('http://valid.com', '-prefix:valid'); 102 print "valid\n"; 103} catch (Exception $e) { 104 print $e->getMessage() . "\n"; 105} 106 107print "12 DOMDocument::createElementNS('-', 'prefix:valid')\n"; 108try { 109 $dom = new domDocument; 110 $dom->createElementNS('-', 'prefix:valid'); 111 print "valid\n"; 112} catch (Exception $e) { 113 print $e->getMessage() . "\n"; 114} 115 116 117print "13 DOMElement::__construct('valid')\n"; 118try { 119 $element = new DomElement('valid'); 120 print "valid\n"; 121} catch (Exception $e) { 122 print $e->getMessage() . "\n"; 123} 124 125print "14 DOMElement::__construct('-invalid')\n"; 126try { 127 $element = new DomElement('-invalid'); 128 print "valid\n"; 129} catch (Exception $e) { 130 print $e->getMessage() . "\n"; 131} 132 133print "15 DOMElement::__construct(' ')\n"; 134try { 135 $element = new DomElement(' '); 136 print "valid\n"; 137} catch (Exception $e) { 138 print $e->getMessage() . "\n"; 139} 140 141print "16 DOMElement::__construct('prefix:valid')\n"; 142try { 143 $element = new DomElement('prefix:valid'); 144 print "valid\n"; 145} catch (Exception $e) { 146 print $e->getMessage() . "\n"; 147} 148 149print "17 DOMElement::__construct('valid', '', 'http://valid.com')\n"; 150try { 151 $element = new DomElement('valid', '', 'http://valid.com'); 152 print "valid\n"; 153} catch (Exception $e) { 154 print $e->getMessage() . "\n"; 155} 156 157print "18 DOMElement::__construct('prefix:valid', '', 'http://valid.com')\n"; 158try { 159 $element = new DomElement('prefix:valid', '', 'http://valid.com'); 160 print "valid\n"; 161} catch (Exception $e) { 162 print $e->getMessage() . "\n"; 163} 164 165print "19 DOMElement::__construct('-invalid', '', 'http://valid.com')\n"; 166try { 167 $element = new DomElement('-invalid', '', 'http://valid.com'); 168 print "valid\n"; 169} catch (Exception $e) { 170 print $e->getMessage() . "\n"; 171} 172 173print "20 DOMElement::__construct('prefix:-invalid', '', 'http://valid.com')\n"; 174try { 175 $element = new DomElement('prefix:-invalid', '', 'http://valid.com'); 176 print "valid\n"; 177} catch (Exception $e) { 178 print $e->getMessage() . "\n"; 179} 180 181print "21 DOMElement::__construct('prefix:invalid', '', '')\n"; 182try { 183 $element = new DomElement('prefix:invalid', '', ''); 184 print "valid\n"; 185} catch (Exception $e) { 186 print $e->getMessage() . "\n"; 187} 188 189print "22 DOMElement::__construct('prefix:valid:invalid', '', 'http://valid.com')\n"; 190try { 191 $element = new DomElement('prefix:valid:invalid', '', 'http://valid.com'); 192 print "valid\n"; 193} catch (Exception $e) { 194 print $e->getMessage() . "\n"; 195} 196 197print "23 DOMElement::__construct('-prefix:valid', '', 'http://valid.com')\n"; 198try { 199 $element = new DomElement('-prefix:valid', '', 'http://valid.com'); 200 print "valid\n"; 201} catch (Exception $e) { 202 print $e->getMessage() . "\n"; 203} 204 205print "24 DOMElement::__construct('prefix:valid', '', '-')\n"; 206try { 207 $element = new DomElement('prefix:valid', '', '-'); 208 print "valid\n"; 209} catch (Exception $e) { 210 print $e->getMessage() . "\n"; 211} 212 213/* the qualifiedName has a prefix and the namespaceURI is null */ 214 215print "25 DOMDocument::createElementNS('', 'prefix:valid')\n"; 216try { 217 $dom = new domDocument; 218 $dom->createElementNS('', 'prefix:valid'); 219 print "valid\n"; 220} catch (Exception $e) { 221 print $e->getMessage() . "\n"; 222} 223 224/* the qualifiedName has a prefix that is "xml" and the namespaceURI 225 is different from "http://www.w3.org/XML/1998/namespace" [XML Namespaces] */ 226 227print "26 DOMDocument::createElementNS('http://wrong.namespaceURI.com', 'xml:valid')\n"; 228try { 229 $dom = new domDocument; 230 $dom->createElementNS('http://wrong.namespaceURI.com', 'xml:valid'); 231 print "valid\n"; 232} catch (Exception $e) { 233 print $e->getMessage() . "\n"; 234} 235 236print "27 DOMElement::__construct('xml:valid', '', 'http://wrong.namespaceURI.com')\n"; 237try { 238 $element = new DomElement('xml:valid', '', 'http://wrong.namespaceURI.com'); 239 print "valid\n"; 240} catch (Exception $e) { 241 print $e->getMessage() . "\n"; 242} 243 244/* This is okay because we reuse the xml namespace from the document */ 245print "28 DOMDocument::createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:valid')\n"; 246try { 247 $dom = new domDocument; 248 $dom->createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:valid'); 249 print "valid\n"; 250} catch (Exception $e) { 251 print $e->getMessage() . "\n"; 252} 253 254/* This isn't because the xml namespace isn't there and we can't create it */ 255print "29 DOMElement::__construct('xml:valid', '', 'http://www.w3.org/XML/1998/namespace')\n"; 256try { 257 $element = new DomElement('xml:valid', '', 'http://www.w3.org/XML/1998/namespace'); 258 print "valid\n"; 259} catch (Exception $e) { 260 print $e->getMessage() . "\n"; 261} 262 263 264/* the qualifiedName or its prefix is "xmlns" and the namespaceURI is 265 different from "http://www.w3.org/2000/xmlns/" */ 266 267print "30 DOMDocument::createElementNS('http://wrong.namespaceURI.com', 'xmlns:valid')\n"; 268try { 269 $dom = new domDocument; 270 $dom->createElementNS('http://wrong.namespaceURI.com', 'xmlns:valid'); 271 print "valid\n"; 272} catch (Exception $e) { 273 print $e->getMessage() . "\n"; 274} 275 276print "31 DOMElement::__construct('xmlns:valid', '', 'http://wrong.namespaceURI.com')\n"; 277try { 278 $element = new DomElement('xmlns:valid', '', 'http://wrong.namespaceURI.com'); 279 print "valid\n"; 280} catch (Exception $e) { 281 print $e->getMessage() . "\n"; 282} 283 284print "32 DOMDocument::createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:valid')\n"; 285try { 286 $dom = new domDocument; 287 $dom->createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:valid'); 288 print "valid\n"; 289} catch (Exception $e) { 290 print $e->getMessage() . "\n"; 291} 292 293print "33 DOMElement::__construct('xmlns:valid', '', 'http://www.w3.org/2000/xmlns/')\n"; 294try { 295 $element = new DomElement('xmlns:valid', '', 'http://www.w3.org/2000/xmlns/'); 296 print "valid\n"; 297} catch (Exception $e) { 298 print $e->getMessage() . "\n"; 299} 300 301/* the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the 302 qualifiedName nor its prefix is "xmlns". */ 303 304print "34 DOMDocument::createElementNS('http://www.w3.org/2000/xmlns/', 'wrongprefix:valid')\n"; 305try { 306 $dom = new domDocument; 307 $dom->createElementNS('http://www.w3.org/2000/xmlns/', 'wrongprefix:valid'); 308 print "valid\n"; 309} catch (Exception $e) { 310 print $e->getMessage() . "\n"; 311} 312 313print "35 DOMElement::__construct('wrongprefix:valid', '', 'http://www.w3.org/2000/xmlns/')\n"; 314try { 315 $element = new DomElement('wrongprefix:valid', '', 'http://www.w3.org/2000/xmlns/'); 316 print "valid\n"; 317} catch (Exception $e) { 318 print $e->getMessage() . "\n"; 319} 320 321 322 323?> 324--EXPECT-- 325 1 DOMDocument::createElement('valid') 326valid 327 2 DOMDocument::createElement('-invalid') 328Invalid Character Error 329 3 DOMDocument::createElement(' ') 330Invalid Character Error 331 4 DOMDocument::createElement('prefix:valid') 332valid 333 5 DOMDocument::createElementNS('http://valid.com', 'valid') 334valid 335 6 DOMDocument::createElementNS('http://valid.com', 'prefix:valid') 336valid 337 7 DOMDocument::createElementNS('http://valid.com', '-invalid') 338Namespace Error 339 8 DOMDocument::createElementNS('http://valid.com', 'prefix:-invalid') 340Namespace Error 341 9 DOMDocument::createElementNS('', 'prefix:invalid') 342Namespace Error 34310 DOMDocument::createElementNS('http://valid.com', 'prefix:valid:invalid') 344Namespace Error 34511 DOMDocument::createElementNS('http://valid.com', '-prefix:valid') 346Namespace Error 34712 DOMDocument::createElementNS('-', 'prefix:valid') 348valid 34913 DOMElement::__construct('valid') 350valid 35114 DOMElement::__construct('-invalid') 352Invalid Character Error 35315 DOMElement::__construct(' ') 354Invalid Character Error 35516 DOMElement::__construct('prefix:valid') 356Namespace Error 35717 DOMElement::__construct('valid', '', 'http://valid.com') 358valid 35918 DOMElement::__construct('prefix:valid', '', 'http://valid.com') 360valid 36119 DOMElement::__construct('-invalid', '', 'http://valid.com') 362Invalid Character Error 36320 DOMElement::__construct('prefix:-invalid', '', 'http://valid.com') 364Namespace Error 36521 DOMElement::__construct('prefix:invalid', '', '') 366Namespace Error 36722 DOMElement::__construct('prefix:valid:invalid', '', 'http://valid.com') 368Namespace Error 36923 DOMElement::__construct('-prefix:valid', '', 'http://valid.com') 370Invalid Character Error 37124 DOMElement::__construct('prefix:valid', '', '-') 372valid 37325 DOMDocument::createElementNS('', 'prefix:valid') 374Namespace Error 37526 DOMDocument::createElementNS('http://wrong.namespaceURI.com', 'xml:valid') 376Namespace Error 37727 DOMElement::__construct('xml:valid', '', 'http://wrong.namespaceURI.com') 378Namespace Error 37928 DOMDocument::createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:valid') 380valid 38129 DOMElement::__construct('xml:valid', '', 'http://www.w3.org/XML/1998/namespace') 382Namespace Error 38330 DOMDocument::createElementNS('http://wrong.namespaceURI.com', 'xmlns:valid') 384Namespace Error 38531 DOMElement::__construct('xmlns:valid', '', 'http://wrong.namespaceURI.com') 386Namespace Error 38732 DOMDocument::createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:valid') 388valid 38933 DOMElement::__construct('xmlns:valid', '', 'http://www.w3.org/2000/xmlns/') 390valid 39134 DOMDocument::createElementNS('http://www.w3.org/2000/xmlns/', 'wrongprefix:valid') 392Namespace Error 39335 DOMElement::__construct('wrongprefix:valid', '', 'http://www.w3.org/2000/xmlns/') 394Namespace Error 395