Building a Tree from an XML file in c++

Hi everyone. For a project for my class I am given a phylogenetic tree that is in an xml file. We are to use RapidXML to parse the data in this tree and to build a multiway tree in memory so that it can be searched in different ways. I know how to traverse the tree breadth first using a queue to create nodes from the xml node data, but I'm getting stuck on how to create relationships between these nodes. That is how to add a child node to a parent. I've posted my code below. Any help in the right direction would be greatly appreciated! I'm really stumped

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class Node
{
public:
    std::string name;
    std::vector<Node *> children; //vector of pointers to the child nodes
    
    Node(std::string n);
    
    void add(Node* n) {children.push_back(n);}
    Node* get(size_t i) {return children[i];}
    size_t size() const {return children.size();}
    
};
Node::Node(std::string n)
{
    name = n;
}


class Tree
{
public:
    //pointer to the root node
    Node *root;
    Tree();
    
    bool empty() const {return root == NULL;}
    void setRoot(Node *n) {root = n;}
};
Tree::Tree()
{
    root = NULL;
}

//helper method to convert xml node to a node
Node *buildNode(xml_node<> *n)
{
    Node *node;
    xml_node<> *name = n->first_node("name");
    //check for Null name and set name of the node
    if(name !=0)
    {
        node = new Node(name->value());
    }
    else
    {
        node = new Node("NULL");
    }
    return node;
}
void breadthFirst(xml_node<> *xml)
{
    Tree *tree = new Tree();

    //Initialize queue
    queue<xml_node<>* > q;
    
    //push the root node onto the queue
    q.push(xml);
    
    
    while(!q.empty())
    {
        
        //visit the xml node and create a node
        Node *treeNode = buildNode(q.front());
        
        //special case for root
        if(tree->empty())
        {
            tree->root = treeNode;
        }
        
        //remove from queue
        q.pop();
        
        //loop through the children of the node and add to the queue
        for(xml_node<> * kids = q.front()->first_node("species"); kids; kids = kids->next_sibling())
        {
            q.push(kids);
        }
        
        //Continue the above while there is still something in the queue
        
    }
}

int main()
{
    xml_document<> doc;
	ifstream theFile ("File.xml");
	vector<char> buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
	buffer.push_back('\0');
	doc.parse<0>(&buffer[0]);
    
	xml_node<> * root = doc.first_node("MyJournal");
    return 0;
}


For the purposes of just figuring out how to build the tree, I'm using a simplified version of the phylogenetic xml file with a format like this:
1
2
3
4
5
6
7
8
9
10
11
12
<MyJournal>
    <species>
        <name>Parent1</name>
        <species>
            <name>child1</name>
            <species>
                <name>grandchild1</name>
            </species>
            <species>
                <name>grandchild2</name>
            ...
Topic archived. No new replies allowed.