You are getting the text of the <folder> and <file> elements that you are asking for at lines 38 and 40. If you want the value of the name attribute of these elements then you should ask for that.
You are getting the text of the <folder> and <file> elements that you are asking for at lines 38 and 40. If you want the value of the name attribute of these elements then you should ask for that.
I have updated the code and edited the values in the previous comment. Could you look at that?
Do you understand the difference between XML attribute value and XML tag text?
I am new to XML programming. Could you see my updated code and give me suggestion and a solution?
Qt Code:
for(int k = 0;k < nodeList.count(); k++) { firmFolder += el.attribute("name"); firmFolder += "/"; } nodeList = docElem.elementsByTagName("file"); for(int l = 0;j < nodeList.count(); l++) { firmFiles += el.attribute("name"); firmFiles += " "; }To copy to clipboard, switch view to plain text mode
I have added these codes. but am getting folder as release/sf/ppro/release/bios and file as 223452256611841084?
But i should get this as release/sf/ppro/ and file 2234522566 for first loop.. and release/bios and file 11841084 for the second loop.. How to get this..
Last edited by Gokulnathvc; 11th September 2012 at 07:21.
The code has not been changed as far as I can see. There's still the obvious errors at line 38/40I am new to XML programming. Could you see my updated code and give me suggestion and a solution?
I have already told you what you need to query to retrieve the folder/file name from the <folder>/<file> element, and you are already using the relevant function. Wysota has already given you the name of the attribute you want. If you explain which part you do not understand we can help
Kindly check the updated code..
QDomNodeList nodeList = docElem.elementsByTagName("folder");
for(int k = 0;k < nodeList.count(); k++)
{
QDomElement el = nodeList.at(k).toElement();
firmFolder += el.attribute("name");
firmFolder += "/";
}
nodeList = docElem.elementsByTagName("file");
for(int l = 0;j < nodeList.count(); l++)
{
QDomElement el = nodeList.at(l).toElement();
firmFiles += el.attribute("name");
firmFiles += " ";
}
In your code you are destroying the xml structure, instead using a flat list of tags. You need to recursively walk down the DOM tree.
Could you modify my code.. how it should be like?
Find the top-most "folder" tag, then read its attribute, ask for the first child tag, if it is folder or file then process it, otherwise ignore it. Then proceed to the next sibling and keep doing the same until you reach the end of hierarchy.
QDomNode::firstChild(), QDomNode::firstChildElement(), QDomNode::nextSibling(), QDomNode::nextSiblingElements() and QDomNode::toElement() are your friends.
There is also a simple example in QDomElement docs.
How to find the top most tag and process as i mentioned in the output in the previous comment. I am getting the same output..
Qt Code:
for(int k = 0; !n.isNull(); n = n.nextSibling(), k++) { firmFolder += el.attribute("name"); firmFolder += "/"; nodeList = docElem.elementsByTagName("file"); el = nodeList.at(k).toElement(); firmFiles += el.attribute("name"); firmFiles += " "; }To copy to clipboard, switch view to plain text mode
I have added this code.. but am not getting the required output as mentioned.. Could you help me? I am getting releasesfppro and file as 22345 22566 1184.. and it comes out of the loop.. i cant see other values.
Last edited by Gokulnathvc; 11th September 2012 at 08:43.
You are still processing a flat list of tags. And you'll be doing that all the time until you get rid of "elementsByTagName" which gives you a flat list of elements. Please see the example in QDomElement.
Could you edit my code and give a sample code. How I should process it?
You will continue to get the same output if you continue to do the same things... so try something different. Wysota's list of documentation does not include elementsByTagName() because it gives you all the folder elements descended from a parent... and you do not want them all at once.
If you want the first element perhaps a function with the word "first" in its name would be a good place to start.
Bookmarks