Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML namespace not handled properly (plus workaround) #32

Closed
RogerHardiman opened this issue Apr 30, 2016 · 1 comment
Closed

XML namespace not handled properly (plus workaround) #32

RogerHardiman opened this issue Apr 30, 2016 · 1 comment

Comments

@RogerHardiman
Copy link
Collaborator

RogerHardiman commented Apr 30, 2016

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

@RogerHardiman
Copy link
Collaborator Author

Pull Request #33 included the xmlns fix.
This issue is now closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant