Howl Of the Sun
Howl Of the Sun

Reputation: 25

Accessing a JSON parsed SOAP envelope with Javascript

This is my first post and I'm new to this wonderful world of development so I apologize in advance if this is a stupid question.

I am using Xml2js to send a soap request. I then parse the response into json. My issue is drilling down into the soap envelope. This is what the response looks like:

{ 'soap:Envelope': { '$': { 'xmlns:soap': 'http://schemas.xmlsoap.org/soap/envelope/' }, 'soap:Header': [ [Object] ], 'soap:Body': [ [Object] ] } }

This is an expanded view

{ 'soap:Envelope': 
 { '$': { 'xmlns:soap': 'http://schemas.xmlsoap.org/soap/envelope/' },
 'soap:Header': 
  [ { DWHeader: 
       [ { '$': { xmlns: 'Some Xmls' },
           SenderInfo: 
            [ { ApplicationID: [ 'Id' ],
                Credentials: [ { AuthToken: [ 'Authtoken' ] } ] } ],
           GlobalTimeoutMS: [ '123' ],
           TrackingID: [ '123' ],
           TraceResults: 
            [ { TraceResult: 
                 [ { IPAddress: [ '0.0.0.0' ],
                     Instance: [ '123' ],
                     Actor: [ '123' ],
                     Timestamp: [ '2015-08-08T15:45:40.844Z' ],
                     DetailedMessage: [ '123' ] } ] } ],
           TraceSettings: [ { '$': { Enabled: 'false' } } ] } ] } ],
 'soap:Body': 
  [ { GetCurrentLocationOfAllMobilesResponse: 
       [ { '$': { xmlns: 'Some xmls' },
           Tracks: 
            [ { Track: 
                 [ { Id: [ 'Id' ],
                     TimeStamp: [ '2015-09-14T21:09:47Z' ],
                     HardwareId: [ 'Some id' ],
                     MobileName: [ 'Truck' ],
                     Lat: [ 'Some Lat' ],
                     Lon: [ 'Some Lon' ],
                     Heading: [ '0' ],
                     Speed: [ '0' ],
                     GPSLock: [ 'true' ],
                     Old: [ 'false' ],
                     Ping: [ 'false' ],
                     Motion: [ 'false' ],
                     Speeding: [ 'false' ],
                     Ignition: [ 'false' ],
                     IgnitionStatus: [ 'Engine Off' ],
                     Street: [ 'Address' ],
                     City: [ 'Some City' ],
                     StateProvince: [ 'Some State' ],
                     PostalCode: [ 'Some Zip' ],
                     County: [ 'Some County' ],
                     Rssi: [ '32' ],
                     Sats: [ '11' ],
                     TimeZone: [ 'Some Timezone' ],
                     Sensor1: [ 'true' ],
                     Sensor2: [ 'false' ] }
                    ] } ] } ] } ] } }

I need the Track array but when I try to drill down I have a problem with the 'soap:Envelope' and 'soap:Body'.

This is my first question so if I haven't posted enough information let me know and I'll include more.

Thanks!

Upvotes: 2

Views: 2333

Answers (1)

Jason Turner
Jason Turner

Reputation: 849

Have you tried using bracket notation?

var tracksArray = response['soap:Envelope']['soap:Body'][0].GetCurrentLocationOfAllMobilesResponse[0].Tracks

See this answer for more about bracket notation: https://stackoverflow.com/a/4968448/4178531

Upvotes: 1

Related Questions