how to determine an empty node with QDomNode
-
Hello friends.
I have the following XML file:
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="/home/user/.config/application/config.xsd"> <app> <applicationdisplayname>My Application Display Name</applicationdisplayname> <applicationhashkey>a9cd0d49e19637c0fea893d12ac87f64</applicationhashkey> <applicationname>MyApplicationName</applicationname> <applicationversion>1.0</applicationversion> <organizationname>MyOrganizationName</organizationname> <organizationdomain>https://www.myorganizationdomain.com</organizationdomain> <showsplash>1</showsplash> <iconimage>icono.png</iconimage> <mayorversion>5</mayorversion> <minorversion>0</minorversion> <pathversion>0</pathversion> </app> </settings>
I'm trying to go through this file, which I do correctly, the detail is when I try to make the following comparison:
if ( element.nodeValue ().isEmpty () ) { }
where element is a QDomElement, when making this comparison, either in the node configuration or node application, they return the following information:
My Application Display Namea9cd0d49e19637c0fea893d12ac87f64MyApplicationName1.0MyOrganizationNamehttps: //www.myorganizationdomain.com1icono.png500
I've been searching the documentation and forums for a long time but I do not get to achieve this
My point is, how do I determine if the node or application settings do not have values directly as well as the applicationdisplayname node.
Or if there is any post in this forum that you have not seen, I would greatly appreciate the help.
Thanks in advance.
-
Hi JonB, thanks for your quick response.
In effect, I just want to get the values of (And that's how I do it):
<applicationdisplayname> My Application Display Name </applicationdisplayname> <applicationhashkey> a9cd0d49e19637c0fea893d12ac87f64 </applicationhashkey> <applicationname> MyApplicationName </applicationname> . . .
I already detected the problem that was presented to me, when I traversed the XML tree, each node converted it directly to QDomElement and that was where the error was located. Well, when comparing with
element.nodeValue () .isEmpty ()
The value thrown is the one mentioned in the first post, then I switched to QDomNode and when doing the same comparison I threw empty and additional to that allows me to go deeper into the tree and ask if it is a QDomText and better control my requirements.
In short, the solution is to obtain the QDomDocument, go through each node of the XML tree as QDomNode and compare it with
element.nodeValue () .isEmpty ()
what you have told me happens
@JonB said in how to determine an empty node with QDomNode:
Are you thinking of:
<app>
some-arbitrary-text-here
<applicationdisplayname>My Application Display Name</applicationdisplayname>That (some-arbitrary-text-here) is not going to happen. A node will either be a text node, containing text, or it will be an element which instead contains other child nodes. If by any chance that is what you are asking about.
Thank you very much for your help and guidance.
-
@remizero
Given the value you quote, you're not testing the desired element. The element with the value you show is the whole of the document, or at least that of the<app>
node. So show what you have yourelement
variable to.EDIT:
either in the node configuration or node application
What do these mean?? If by any chance you are talking about the
<settings>
or<app>
nodes it would be so much clearer if you said so?do not have values directly
Are you thinking of:
<app> some-arbitrary-text-here <applicationdisplayname>My Application Display Name</applicationdisplayname>
That (
some-arbitrary-text-here
) is not going to happen. A node will either be a text node, containing text, or it will be an element which instead contains other child nodes. If by any chance that is what you are asking about. -
Hi JonB, thanks for your quick response.
In effect, I just want to get the values of (And that's how I do it):
<applicationdisplayname> My Application Display Name </applicationdisplayname> <applicationhashkey> a9cd0d49e19637c0fea893d12ac87f64 </applicationhashkey> <applicationname> MyApplicationName </applicationname> . . .
I already detected the problem that was presented to me, when I traversed the XML tree, each node converted it directly to QDomElement and that was where the error was located. Well, when comparing with
element.nodeValue () .isEmpty ()
The value thrown is the one mentioned in the first post, then I switched to QDomNode and when doing the same comparison I threw empty and additional to that allows me to go deeper into the tree and ask if it is a QDomText and better control my requirements.
In short, the solution is to obtain the QDomDocument, go through each node of the XML tree as QDomNode and compare it with
element.nodeValue () .isEmpty ()
what you have told me happens
@JonB said in how to determine an empty node with QDomNode:
Are you thinking of:
<app>
some-arbitrary-text-here
<applicationdisplayname>My Application Display Name</applicationdisplayname>That (some-arbitrary-text-here) is not going to happen. A node will either be a text node, containing text, or it will be an element which instead contains other child nodes. If by any chance that is what you are asking about.
Thank you very much for your help and guidance.