Why this does not work?
See php variables. You cant have a '-' in a variable. The point that you can't create a variable with a hyphen/dash has always been that way in PHP(likely any C-type language) because that character is used for the subtraction operator.
http://www.php.net/manual/en/language.variables.basics.php
Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
If you UnderstanD Regex : As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
What if I cant control the element names with a '-' ?
However, from the docs, Accessing elements within an XML document that contain characters not permitted under PHP's naming convention (e.g. the hyphen) can be accomplished by encapsulating the element name within braces and the apostrophe.You can wrap the var in {} for simple Xml elemnts to make this work See some good explanation here
So you can still make this to work by changing :
<?php
include 'example.php';
$xml = new SimpleXMLElement($xmlstr);
$xml->{'ID-1'} = '8';//change here
$xml->name = 'Big Cliff';
$xml->asXML('test2.xml');
echo $xml->asXML();
?>