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


#1

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


#2

Just quote the whole name 'ns2:user'


#3

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?


#4

OK - with the extra context you provided:

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

#5

Thanks Rob much appreciated.