Any help would be appreciated, even if it's just a quick idea.
No librarys(besides stl) or external parsers
I am supposed to create a c++ program that will read the data of an XML file and store it in memory but I am having lots of trouble finding a way to do this. I was hoping that I could get some guidance from someone here. Also regex should be used to recognize the file data or split it up.
Tag names do NOT need to be preserved although it would be ideal, just the nesting data, all the data is stored as text (string)
This is an example showing you what I mean by using stacks and queues. However, It would need to be non-specific to this.
<House> // tag: push <House> on stack
<Info> // tag: push <Coordinates> on stack
<Code>ABE</Code> // element: push_back on element queue
<City>Allentown</City> // element: push_back on element queue
<ID>PA</ID> // element: puch_back on element queue
</Info> // terminator: pop stack and complete node in queue
<Exact> // tag: push <Exact> on stack
<X>40.65</X> // element: push_back on element queue
<Y>75.43</Y> // element: push_back on element queue
</Exact> // terminator: pop stack and complete node in queue
</House> // terminator: pop stack and complete node in queue
So far, it's pretty lame but I have just been able to set up the file to be read line by line and skip the header by detecting it with regex like this:
string fileline;
regex header("[<][?](.*?)[?][>]");
while (getline(ifstreamobj, fileline))
{
if (regex_match(fileline, header))
{
cout<<"Skipping what appears to be a header"<<endl;
}
//?
}
cout << "END OF FILE, EOF" << endl;
I don't know really what to do. I guess the stack would be a stack of strings where the tag name would be pushed/popped
And then the queue would be for the actual data in between the tags