PDA

View Full Version : recursive QDomDocument



check_in
20th October 2012, 22:39
I am using QDomDocument to generate XML file from previous database configuration.

I have setup a class that I will call Struct to populate attribute names, attribute values, tag
with a pointer to nested nodes (in non XML as identified) that was populated recursively
using '_tag' as delimeter

Attribute name, values, nested pointers are of QList types in Struct. h as follows:

class Struct
{
public:
Struct();
private:
QString _entity_name;// same as
QString _tag;

QList <QString *> _attr_name_list;
QList <QString *> _attr_value_list;
QList <Struct *> _nested_node_list;
};

#endif // STRUCT

Now have another class (Get_new_config) calling Tree_xml, accessing 'Struct', to build xml using QDomDocument.
Changed names, deleted a lot stuff, seeking concepts here

void Get_new_config::construct_node_list(QList<QString *> &file_list,
int &index, QList<Struct *> &node_list)
{
...
while(indx < index)
{
list_string = *new_file_list.at(indx);
if((list_string.contains("###"))&&(###))
{
list_string = list_string.remove("###");
temp_object = Struct->recursive_populate(new_file_list, indx,
*node_data_out); // also called recursively(in class) to populate subnodes

*look << "BACK FROM POPULATE - node_list.appended" << endl; // parent captured with ptr to nested nodes in
// each object member variable *_nested_node_list
node_list.append(temp_object);
}
indx++;

} // end - while

Tree->Tree_xml(new QDomDocument(document),temp_object)

Now comes my question in Tree->Tree_xml, appending subnodes to subnodes and ultimately to root

Here's what i have:

void Tree::Tree_xml(QDomDocument* document, Struct *current_object)

{

QString newTagName;

QString TagName = current_object->get_tag_name();
QDomElement root = document->createElement(TagName);
QDomProcessingInstruction instr = document->createProcessingInstruction("xml",
"version= '1.0' encoding='UTF-8'");

for(int i =0; i< current_object->get_attr_name_list_size();i++)
{
root.setAttribute(current_object->get_attr_name_list_at(i),
current_object->get_attr_val_list_at(i));
}

for(int j=0; j< current_object->get_nested_node_list_size(); j++)
{
temp_object = current_object->get_nested_node_list_at(j);
newTagName = temp_object->get_tag_name();
QDomElement newTagName = document->createElement(newTagName);
document->appendChild(newTagName);

if (temp_object->get_nested_node_list_size()> 0)
Tree_xml(QDomDocument* document, Struct *current_object) //recursively call Tree_xml for nested nodes
}

}

My question is I am recursively sending the paramater QDomDocument* document which couldn't be correct.
Should I be appending child to child?