Important: Please read the 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
    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:


    another device with


    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="" xmlns:SOAP-ENV="" xmlns:chan="" xmlns:tdn="" xmlns:tds="" xmlns:tev="" xmlns:tptz="" xmlns:trt="" xmlns:tt="" xmlns:wsa="" xmlns:wsa5="" xmlns:wsdd="" xmlns:wsnt="" xmlns:wsrfbf="" xmlns:wsrfr="" xmlns:wstop="" xmlns:xmime="" xmlns:xop="" xmlns:xsd="" xmlns:xsi="">

  • @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="" xmlns:SOAP-ENV="" xmlns:chan="" xmlns:tdn="" ...

    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