Check Valid XML Name In Valuetree

A few times I’ve been bit trying to convert a value tree over to xml only to find there is some property in there which is not conforming to the xml standard and raising an issue.

At this point however it’s difficult to track down what is setting that property in the XML. It would be great if there was a way to somehow check properties as they’re added to the value tree and ensure that they’re safe for serialization.

I was going to suggest you override ValueTree and add a check for setProperty, but then I looked and I see ValueTree is marked as final

How would you see this operating? Since a ValueTree does not have to generate XML, it’s not an overhead you would want for general ValueTree usage.

It seems like it would be easy enough to create a standalone function to check and then use that.

For now I just added this to the value tree class:

ValueTree& ValueTree::setPropertyExcludingListener (Listener* listenerToExclude, const Identifier& name,
                                                    const var& newValue, UndoManager* undoManager)
{
    jassert (XmlElement::isValidXmlName(name.toString()));

It makes sense to me this would live here because a huge use case on the value trees is to have them be serializable, it seems strange they could be in a state where they couldn’t serialize and you wouldn’t learn about it until you try?