xref: /PHP-8.3/ext/simplexml/tests/012.phpt (revision 7f2f0c00)
1--TEST--
2SimpleXML: Attribute creation
3--EXTENSIONS--
4simplexml
5--FILE--
6<?php
7
8$xml =<<<EOF
9<?xml version="1.0" encoding="ISO-8859-1" ?>
10<foo/>
11EOF;
12
13$sxe = simplexml_load_string($xml);
14
15try {
16    $sxe[""] = "value";
17} catch (ValueError $exception) {
18    echo $exception->getMessage() . "\n";
19}
20
21$sxe["attr"] = "value";
22
23echo $sxe->asXML();
24
25$sxe["attr"] = "new value";
26
27echo $sxe->asXML();
28
29try {
30    $sxe[] = "error";
31} catch (ValueError $exception) {
32    echo $exception->getMessage() . "\n";
33}
34
35__HALT_COMPILER();
36?>
37===DONE===
38--EXPECT--
39Cannot create attribute with an empty name
40<?xml version="1.0" encoding="ISO-8859-1"?>
41<foo attr="value"/>
42<?xml version="1.0" encoding="ISO-8859-1"?>
43<foo attr="new value"/>
44Cannot append to an attribute list
45