Console Based XML parser available
by Matthew "Ashteth" Kee · in Torque Game Builder · 10/24/2005 (1:21 pm) · 23 replies
I recently needed an XML parser for level saving and loading so I went ahead and built a console object to assist with this task. What I ended up creating was a stack based XML parser that is based upon the TinyXML library and the pre-existing pickler/persistance resource for TGE owners. Anyways, its still fairly rudimentary but may be of interest to some. An example is included with the resource. If you have any problems or feature requests, feel free to e-mail me (address in profile) or leave a reply here.
XML Console Parser
XML Console Parser
#2
10/25/2005 (8:16 pm)
An update: I added XML writing functionality and added a write demo to the resource. If you previously downloaded the resource, you may wish to do so again.
#3
11/08/2006 (2:31 am)
I tried to add this yesterday to the latest version of TGB, refused to compile. Not at home now, so I don't know the error. Anyway, can someone corfirm if it should work with the latest TGB code?
#4
11/10/2006 (2:14 am)
Looks like this resource is not supported anymore?
#5
11/11/2006 (9:17 am)
Anyone???
#6
I would love to just do something like:
%myXML=new XMLDoc();
%levelName=%myXML.firstChild().firstChild().attributes("name");
or another example:
%row=%myXML.firstChild().childNodes(1).firstChild().firstChild().nodeValue();
I just can't get this resource to work, and even if I could... it is stack based (I could live with that though, but right now I can't even get that to work... and it looks like nobody cares)
11/11/2006 (10:57 am)
Ok... 20$ (sorry, all I have) if someone can add proper XML functionality to TGB. I would love to just do something like:
%myXML=new XMLDoc();
%levelName=%myXML.firstChild().firstChild().attributes("name");
or another example:
%row=%myXML.firstChild().childNodes(1).firstChild().firstChild().nodeValue();
I just can't get this resource to work, and even if I could... it is stack based (I could live with that though, but right now I can't even get that to work... and it looks like nobody cares)
#7
Incidentally, I have updated the resource. Hopefully it will work for you.
11/11/2006 (1:41 pm)
It is more about lack of time than not caring... I don't actually use this resource anymore, so when I get time to program, I prefer to work on other things. Incidentally, I have updated the resource. Hopefully it will work for you.
#8
One thing though. I'm storing multiple levels in 1 file. I wrote a parser for it, but I'm stuck after parsing one level. Can't seem to get the second level in the stack.
I have something like:
So using pushFirstChildElement i go to the first levelrow, and using nextSiblingElement, I go trough all rows of the first level. But how do I jump to the second level after I parsed the last row of the first level?
11/12/2006 (7:18 am)
Thank you!! works like a charm.One thing though. I'm storing multiple levels in 1 file. I wrote a parser for it, but I'm stuck after parsing one level. Can't seem to get the second level in the stack.
I have something like:
So using pushFirstChildElement i go to the first levelrow, and using nextSiblingElement, I go trough all rows of the first level. But how do I jump to the second level after I parsed the last row of the first level?
#9
11/13/2006 (4:24 am)
Not possible? Or am I missing something?
#10
and then use nextSiblingElement().
11/13/2006 (3:30 pm)
You need to use popElement() until the stack is returned to
#11
11/14/2006 (12:05 am)
Ah that makes sense. Thank you!
#12
Why is that? I wil work around it by not using spaces, but this really shouldn't happen.
11/22/2006 (10:53 am)
Euh, i just found out that if you have spaces in the nodevalues, those space sometimes dissapear when using getText(). Why is that? I wil work around it by not using spaces, but this really shouldn't happen.
#13
01/08/2007 (12:13 pm)
I just found out, that when i read an xml file, and I do %myXML.delete(); sometimes the xml file isn't closed. Becuase it isn't release I can no longer write to it. Should I do something specific to close the file? I tought delete(); would do the trick, but it looks like it doesn't.
#14
Please help, its the last thing to fix in my game... so if anyone can point me in the right direction, or tell me how to release the file again, please do.
01/09/2007 (9:40 am)
It looks like I can write files, even when overwriting existing files, no problem. But once I read and xml (using loadFile), the file locks up, and I can no longer write to it. Even when I delete the xmlDoc object (%myXML.delete();) Please help, its the last thing to fix in my game... so if anyone can point me in the right direction, or tell me how to release the file again, please do.
#15
01/09/2007 (1:08 pm)
Did you try closing the file?
#16
01/09/2007 (1:20 pm)
Well it looks like xmlDoc only supports clear(), reset() and delete().... sniffed around in the C++ files, but I don't know enough C++ to see what could be wrong.
#17
It should be:
When you have implemented this change, you should be able to load and save to the same file. I'll update the resource this weekend.
[edit]
I take it you know about the saveFile() method?
[/edit]
01/09/2007 (5:30 pm)
In TinyXML.cc the loadstream function should close the stream. I forgot to update this.It should be:
bool TiXmlDocument::LoadStream( FileStream& stream )
{
// Delete the existing data:
Clear();
U32 length = stream.getStreamSize();
char* data = new char[length + 1];
stream.read( length, data);
data[length] = 0;
Parse( data );
delete[] data;
stream.close(); //addon
if( Error() )
return false;
else
return true;
}When you have implemented this change, you should be able to load and save to the same file. I'll update the resource this weekend.
[edit]
I take it you know about the saveFile() method?
[/edit]
#18
01/09/2007 (10:40 pm)
Wohoo! thanks a lot. I'll try it when I get home tonight.
#20
It can be found here: XML Object - TGB/TGE
03/30/2007 (7:54 am)
For those looking for an XML SAX parser, I created a resource a while back that integrates Expat (The GNOME SAX Parser) into TGE and TGB (most likely TGEA friendly) ...It can be found here: XML Object - TGB/TGE
Torque Owner Hans Sjunnesson
--
Hans