PHP DOM createElement - allow spaces

How to use spaces in createElement when creating xml file

I need to use

$main = $doc->createElement("$cname"."Data" );

Where

$cname="Company Name"

But due to spaces in $cname, I get the following error:

Fatal error: exception for exception "DOMException" with the message "Invalid character error" in the .php file: 50 Stack trace: # 0 file.php (50): Level above> createElement ('Geosoft company ...') # 1 {main } thrown in file.php on line 50

How to fix it?

Regards, Rekch

+3
source share
1 answer

http://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar

NameStartChar:: = ":" | [A-Z] | "_" | [a-z] | [# xC0- # xD6] | [# xD8- # xF6] | [# xF8- # x2FF] | [# x370- # x37D] | [# x37F- # x1FFF] | [# x200C- # x200D] | [# x2070- # x218F] | [# x2C00- # x2FEF] | [# x3001- # xD7FF] | [# xF900- # xFDCF] | [# xFDF0- # xFFFD] | [# X10000- # xEFFFF]

NameChar:: = NameStartChar | "-" | "" | [0-9] | # xB7 | [# x0300- # x036F] | [# X203F- # x2040]

:

$main = $doc->createElement("Data");
$main->setAttribute('origin', $cname);

xml

+5

Source: https://habr.com/ru/post/1770054/


All Articles