Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QDomDocument elementsByTagName and namespace



  • Hi I have to extrace the elments from a QDomDocument. The elements could have a node like
    "s:Body"
    or
    "SOAP-ENV:Body
    How can I extract the nodes searching "Body" without the namespace? Is there a way to have the namespace?



  • @mrdebug
    Assuming you've checked that elementsByTagName() does not return namespaced-items. Then QDomNodeList QDomDocument::elementsByTagNameNS(const QString &nsURI, const QString &localName) can be used if you know which namespace(s) you want to search.

    I'm not sure about a "get element by tag name across any namespace".



  • My problem in the implementation of onvif protocol.
    A device responses with this document:

    <SOAP-ENV:Body>
    ..
    

    another device with

    <s:Body>
    ..
    

    so witch is the right way to have the "Body" element?



  • @mrdebug
    I assume you will find that the response starts with a declaration of what namespaces it is using and what "aliases" (like s:) it is going to use? That's how it works in XML documents, I don't know anything about devices and what they might do.

    Have you verified that elementsByTagName() does not return namespaced-items?



  • The function elementsByTagName() works with "SOAP-ENV:Body" and "s:Body". But the problem is that on my desk I have two devices that uses two different namespaces. My problem is to manage the response for all the devices. I think that could be other devices with other different namespaces.
    Maybe the problem is the onvif / soap / xml protocol.
    This is the full response

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:chan="http://schemas.microsoft.com/ws/2005/02/duplex" xmlns:tdn="http://www.onvif.org/ver10/network/wsdl" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:wsdd="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Header></SOAP-ENV:Header>
    <SOAP-ENV:Body>
    <tds:GetCapabilitiesResponse>
    <tds:Capabilities>
    <tt:Device>
    <tt:XAddr>http://192.168.1.156:5000/onvif/device_service</tt:XAddr>
    <tt:Network>
    <tt:IPFilter>false</tt:IPFilter>
    <tt:ZeroConfiguration>false</tt:ZeroConfiguration>
    <tt:IPVersion6>false</tt:IPVersion6>
    <tt:DynDNS>false</tt:DynDNS>
    </tt:Network>
    <tt:System>
    <tt:DiscoveryResolve>false</tt:DiscoveryResolve>
    <tt:DiscoveryBye>false</tt:DiscoveryBye>
    <tt:RemoteDiscovery>true</tt:RemoteDiscovery>
    <tt:SystemBackup>false</tt:SystemBackup>
    <tt:SystemLogging>false</tt:SystemLogging>
    <tt:FirmwareUpgrade>false</tt:FirmwareUpgrade>
    <tt:SupportedVersions>
    <tt:Major>2</tt:Major>
    <tt:Minor>0</tt:Minor>
    </tt:SupportedVersions>
    <tt:Extension>
    <tt:HttpFirmwareUpgrade>false</tt:HttpFirmwareUpgrade>
    <tt:HttpSystemBackup>false</tt:HttpSystemBackup>
    <tt:HttpSystemLogging>false</tt:HttpSystemLogging>
    <tt:HttpSupportInformation>false</tt:HttpSupportInformation>
    </tt:Extension>
    </tt:System>
    <tt:IO>
    <tt:InputConnectors>2</tt:InputConnectors>
    <tt:RelayOutputs>2</tt:RelayOutputs>
    </tt:IO>
    </tt:Device>
    <tt:Media>
    <tt:XAddr>http://192.168.1.156:5000/onvif/media_service</tt:XAddr>
    <tt:StreamingCapabilities>
    <tt:RTPMulticast>true</tt:RTPMulticast>
    <tt:RTP_TCP>true</tt:RTP_TCP>
    <tt:RTP_RTSP_TCP>true</tt:RTP_RTSP_TCP>
    </tt:StreamingCapabilities>
    </tt:Media>
    <tt:PTZ>
    <tt:XAddr>http://192.168.1.156:5000/onvif/ptz_service</tt:XAddr>
    </tt:PTZ>
    <tt:Extension>
    <tt:DeviceIO>
    <tt:XAddr>http://192.168.1.156:5000/onvif/deviceio_service</tt:XAddr>
    <tt:VideoSources>1</tt:VideoSources>
    <tt:VideoOutputs>0</tt:VideoOutputs>
    <tt:AudioSources>0</tt:AudioSources>
    <tt:AudioOutputs>0</tt:AudioOutputs>
    <tt:RelayOutputs>0</tt:RelayOutputs>
    </tt:DeviceIO>
    </tt:Extension>
    </tds:Capabilities>
    </tds:GetCapabilitiesResponse>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    
    


  • @mrdebug said in QDomDocument elementsByTagName and namespace:

    The function elementsByTagName() works with "SOAP-ENV:Body" and "s:Body".

    Then in that case I don't follow your problem since you get BODY elements returned regardless of nname space, which seems to be what you want.

    Anyway, if you want to find the namespaces used that is what the line

    <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:chan="http://schemas.microsoft.com/ws/2005/02/duplex" xmlns:tdn="http://www.onvif.org/ver10/network/wsdl" ...

    defines. If you look at the one which uses <s:Body> you'll see that has s: defined in same line.


Log in to reply