angular-xml icon indicating copy to clipboard operation
angular-xml copied to clipboard

Should probably avoid $-prefixed properties

Open lapo-luchini opened this issue 11 years ago • 4 comments

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);

lapo-luchini avatar Jan 27 '15 16:01 lapo-luchini

Interesting point. I think the options would be:

  1. Open a request to the x2js library to configure "ignoring" invalid tags rather than failing. Then turn this on by default within this library.
  2. Create a service in this library to remove/escape XML invalid named properties.
  3. 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.

johngeorgewright avatar Jan 27 '15 19:01 johngeorgewright

I've opened a request with x2js.

johngeorgewright avatar Jan 27 '15 19:01 johngeorgewright

Looks like there's no response from them. Guess we'll have to create the service ourselves.

johngeorgewright avatar Feb 13 '15 09:02 johngeorgewright

$$-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.

lapo-luchini avatar Apr 30 '15 11:04 lapo-luchini