Skip to content

Conversation

studiowbe
Copy link

Using DOMDocument::createElement() will check if the array key name is valid as an xml tagname. If it's not (like with numeric keys) a DOMException with DOM_INVALID_CHARACTER_ERR will be raised.

One thing that should be considered is that spaces in a tagname are automatically converted to '_' at the moment, but would normally also result in the exception. So there are 2 paths to consider:

  1. try and fix the tagname automatically. Downside here is that when the xml is parsed back to an array, some keys might be different, with no way to tell which.
  2. let DOMDocument parse the tagname and raise an exception if necessary.

freekmurze added a commit that referenced this pull request Mar 18, 2015
@freekmurze freekmurze merged commit 85033ab into spatie:master Mar 18, 2015
@freekmurze
Copy link
Member

Thanks!
Converting all sorts of weird characters to valid xml tagnames is beyond the scope of this package. On the other hand converting spaces to underscores is quite handy.

I'll add an $automaticallyConvertSpacesToUnderscoresInKeyNames as an argument, so user could opt out of this behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants