You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi
I am testing your ONVIF library and recently submitted Pull Request for a new example program
I hit upon the problem that xml2js output is different when there are xmlns namespace attributes in the XML and the ONVIF library does not cope with this.
For example xml2js gives me this output for one camera {"uri":"rtsp://192.168.1.128:554/ch0.h264","invalidAfterConnect":false,"invalidAfterReboot":false,"timeout":"PT0S"}
But another camera gives this {"uri":{"_":"rtsp://192.168.1.30:9554/h264","$":{"xmlns:tt":"http://www.onvif.org/ver10/schema"}},"invalidAfterConnect":{"_":false,"$":{"xmlns:tt":"http://www.onvif.org/ver10/schema"}},"invalidAfterReboot":{"_":false,"$":{"xmlns:tt":"http://www.onvif.org/ver10/schema"}},"timeout":{"_":"PT30S","$":{"xmlns:tt":"http://www.onvif.org/ver10/schema"}}}
*Note the '' and '$' which split the value from the namsapce.
*_
In the first camera I can use stream.uri to get the RTSP string.
But in the second camera I need to use the something like stream.uri['_']
The cause is the XML has name spaces in <soap:Body><trt:GetStreamUriResponse xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns="http://www.onvif.org/ver10/media/wsdl"><trt:MediaUri><tt:Uri xmlns:tt="http://www.onvif.org/ver10/schema">rtsp://192.168.1.30:9554/h264</tt:Uri><tt:InvalidAfterConnect xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:InvalidAfterConnect><tt:InvalidAfterReboot xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:InvalidAfterReboot><tt:Timeout xmlns:tt="http://www.onvif.org/ver10/schema">PT30S</tt:Timeout></trt:MediaUri></trt:GetStreamUriResponse></soap:Body>
Notice the xmlns after the text 'GetStreamUriResponse'
The Fix
My quick fix is to add a RegEx to remove the XML name spaces before passing them to xml2js in the lib/utils.js file
const parseSOAPString = function(xml, callback) {
/* Filter out xml name spaces */
xml = xml.replace(/xmlns(.*?)=(".*?")/g,'');
xml2js.parseString(
xml
, {
I looked for some options flags for xml2js.
I found one that aways put in the '_' but that needs all of the ONVIF library to change as the object that comes out of xml2js is different.
So I went for this quick one line fix.
Do you want me to do a Pull Request for it?
Or is there a way to get xml2js to handle this for us?
Roger
The text was updated successfully, but these errors were encountered:
Hi
I am testing your ONVIF library and recently submitted Pull Request for a new example program
I hit upon the problem that xml2js output is different when there are xmlns namespace attributes in the XML and the ONVIF library does not cope with this.
For example xml2js gives me this output for one camera
{"uri":"rtsp://192.168.1.128:554/ch0.h264","invalidAfterConnect":false,"invalidAfterReboot":false,"timeout":"PT0S"}
But another camera gives this
{"uri":{"_":"rtsp://192.168.1.30:9554/h264","$":{"xmlns:tt":"http://www.onvif.org/ver10/schema"}},"invalidAfterConnect":{"_":false,"$":{"xmlns:tt":"http://www.onvif.org/ver10/schema"}},"invalidAfterReboot":{"_":false,"$":{"xmlns:tt":"http://www.onvif.org/ver10/schema"}},"timeout":{"_":"PT30S","$":{"xmlns:tt":"http://www.onvif.org/ver10/schema"}}}
*Note the '' and '$' which split the value from the namsapce.
*_
In the first camera I can use stream.uri to get the RTSP string.
But in the second camera I need to use the something like
stream.uri['_']
The cause is the XML has name spaces in
<soap:Body><trt:GetStreamUriResponse xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns="http://www.onvif.org/ver10/media/wsdl"><trt:MediaUri><tt:Uri xmlns:tt="http://www.onvif.org/ver10/schema">rtsp://192.168.1.30:9554/h264</tt:Uri><tt:InvalidAfterConnect xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:InvalidAfterConnect><tt:InvalidAfterReboot xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:InvalidAfterReboot><tt:Timeout xmlns:tt="http://www.onvif.org/ver10/schema">PT30S</tt:Timeout></trt:MediaUri></trt:GetStreamUriResponse></soap:Body>
Notice the xmlns after the text 'GetStreamUriResponse'
The Fix
My quick fix is to add a RegEx to remove the XML name spaces before passing them to xml2js in the lib/utils.js file
I looked for some options flags for xml2js.
I found one that aways put in the '_' but that needs all of the ONVIF library to change as the object that comes out of xml2js is different.
So I went for this quick one line fix.
Do you want me to do a Pull Request for it?
Or is there a way to get xml2js to handle this for us?
Roger
The text was updated successfully, but these errors were encountered: