Best way to escape colon (:) in XML in MeteorJS?

One of my JSON object has name

ns2:user 

as in this case:

{ 'ns2:user': 
    { '$': { 'xmlns:ns2': 'identity.rest.mgmt.acs.nm.cisco.com' },
    description: [ 'Sebastian Cheung Telecomms Design' ],
    id: [ '123' ],
    etc

what is the best way in MeteorJS to escape the : before parsing, as I don’t think this can be iterated over, and eventually getting the id value of 123. Cheers

Just quote the whole name 'ns2:user'

Hi Rob,

Tried:

xml2js.parseString(res.body, function (jsError, jsResult) {
              console.log('id is : ', jsResult.'ns2:user'.id); <- name expected and Expecting new line???
            });

Is this what you mean?

OK - with the extra context you provided:

xml2js.parseString(res.body, function (jsError, jsResult) {
              console.log('id is : ', jsResult['ns2:user'].id);
            });
1 Like

Thanks Rob much appreciated.

1 Like