Should probably avoid $-prefixed properties
I'm trying a single example structure (which contains $$hashKey as added by AngularJS during edit) and x2js.json2xml_str is producing a <$$hashKey>030</$$hashKey> node, which then the parser chokes on.
The end effect is that x2js.json2xml(myVar) is always null.
I would expect an exception not a null, but in this case I guess $-prefixed properties should simply be skipped, as they are both reserved in AngularJS and invalid XML tag names anyways.
Right now I'm doing this:
function removeDollars(obj) {
if (typeof obj != 'object')
return;
for (var k in obj) {
if (k.charAt(0) == '$')
delete obj[k];
removeDollars(obj[k]);
}
}
var data = angular.copy($scope.value);
removeDollars(data);
var xml = x2js.json2xml_str(data);
Interesting point. I think the options would be:
- Open a request to the x2js library to configure "ignoring" invalid tags rather than failing. Then turn this on by default within this library.
- Create a service in this library to remove/escape XML invalid named properties.
- Do No.2 then wrap the x2js library in a configurable service to achieve no.1.
I'd say option 1 is the most sensible. If, however, x2js don't like that idea, we'd need to start trying out the other options.
I've opened a request with x2js.
Looks like there's no response from them. Guess we'll have to create the service ourselves.
$$-stuff is certaily specific to AngularJS and might not be interesting to x2js, but they should be at least interested in avoiding values that break their methods.