|
|
The Inn A place to gather around and chat about almost any subject |
|
Thread Tools | Display Modes |
11-26-2007, 05:52 PM | #31 | |
Duke
Join Date: Nov 2006
Location: 0x00CAFE
Posts: 3,366
|
Quote:
__________________
I don't have a solution, but I admire the problem. |
|
01-14-2008, 08:06 AM | #32 | |
Duke
Join Date: Nov 2006
Location: 0x00CAFE
Posts: 3,366
|
Quote:
I'm being serious on that. The old program used plain text files which were hard as hell to update massively, and that's why I'm trying to implement XML. As you may noticed, this sounds a little bit offtopic. Well, this introduction is just a mere excuse to post the code of a simple file parser I made to test the new engine (it's working pretty fast for a parser). THIS IS JUST A ROOKIE'S EXAMPLE: Java: Code:
public static Vector questData(String id){ Vector result = new Vector(); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder docbuild = factory.newDocumentBuilder(); Document doc = docbuild.parse("quests.xml"); Element root = doc.getDocumentElement(); NodeList quests = root.getElementsByTagName("quest"); for(int x=0; x < quests.getLength(); x++){ Element quest = (Element)quests.item(x); if(id.equals(quest.getAttribute("id"))){ result.addElement("tag:name"); NodeList nombre = quest.getElementsByTagName("nombre"); result.addElement(nombre.item(0).getTextContent()); result.addElement("tag:description"); NodeList descripcion = quest.getElementsByTagName("descripcion"); result.addElement(descripcion.item(0).getTextContent()); NodeList npcs = quest.getElementsByTagName("npc"); result.addElement("tag:npcs"); for (int z = 0 ; z < npcs.getLength(); z++){ result.addElement(npcs.item(z).getTextContent()); } result.addElement("tag:rewards"); NodeList recompensas = quest.getElementsByTagName("recompensa"); for (int z = 0 ; z < recompensas.getLength(); z++){ result.addElement(recompensas.item(z).getTextContent()); } break; } } } catch (SAXException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } catch (ParserConfigurationException ex) { ex.printStackTrace(); } return result; } Code:
<?xml version="1.0" encoding="ISO-8859-1"?> <quests> <quest id="1"> <nombre>Aguas envenenadas</nombre> <npc>Tipo uno</npc> <npc>Tipo dos</npc> <npc>Tipo tres</npc> <recompensa>Mil de oro</recompensa> <recompensa>Espada vieja</recompensa> <descripcion>breve descripción</descripcion> </quest> <quest id="2"> <nombre>Aguas envenenadas2</nombre> <npc>Tipo uno2</npc> <npc>Tipo dos2</npc> <npc>Tipo tres2</npc> <recompensa>Mil de oro2</recompensa> <recompensa>Espada vieja2</recompensa> <descripcion>breve descripción2</descripcion> </quest> <quest id="3"> <nombre>Aguas envenenadas3</nombre> <npc>Tipo uno3</npc> <npc>Tipo dos3</npc> <npc>Tipo tres3</npc> <recompensa>Mil de oro3</recompensa> <recompensa>Espada vieja3</recompensa> <descripcion>breve descripción3</descripcion> </quest> </quests> Code:
tag:name Aguas envenenadas tag:description breve descripcion tag:npcs Tipo uno Tipo dos Tipo tres tag:rewards Mil de oro Espada vieja NOTE: The "tag:" thing is just an internal code thingie, used just for parsing the Vector inside the code. Mind the details. Why did I used an element as the name and not as an attribute? AVOID attributes, they're ugly. I just used them for the index (again, an internal code thing). So... Why am I posting this? Just because I couldn't find any other example on this forum about xml parsing, and you could find it interesting for any kind of app. I'm using the DOM standard, and it's quite similar to the php examples... Of course you would need to rewrite your app, but this may be helpful if you do so. For the sake of completeness I'm going to say that the ID will be a hidden field to the user and it will be used like the primary key field on a MySQL database. I recommend you to keep this in mind if you think you may replace your xml files with a database on the future. It makes things easier. Now back to the topic. Having this code as a "Proof of Concept" example, when do we begin coding? I bought a PHP book. It's simple, but I think it will help me to understand what you're doing while I play with java :P
__________________
I don't have a solution, but I admire the problem. |
|
01-14-2008, 04:49 PM | #33 |
Count
Join Date: Jul 2007
Location: Toulouse
Posts: 1,335
|
Oh god no! Please stop showing Java code to me, it's so bad for my mental sanity. I think Java should be a banned language in schools.
__________________
« Thanks all, you are right I'm great with the barbarian ... for killing mobs. » -- Athena Stillwater
|
01-14-2008, 05:10 PM | #34 | |
Duke
Join Date: Jan 2007
Posts: 3,939
|
Quote:
why? java is really easy, i think...
__________________
"Nunca un científico ha quemado a un religioso por afirmar a Dios sin pruebas". Manuel Toharia "uno empieza a darse cuenta que eso de no hacer ejercicio, comer y beber como si fuese la ultima cena y mantener la figura ya no existe...". Maryan |
|
01-14-2008, 05:24 PM | #35 |
Count
Join Date: Jul 2007
Location: Toulouse
Posts: 1,335
|
Java is not very functional
In fact I don't like the Objects paradigm. It's just my humble opinion on the subject, and I don't think it's the good place to discuss about that.
__________________
« Thanks all, you are right I'm great with the barbarian ... for killing mobs. » -- Athena Stillwater
|
01-14-2008, 05:27 PM | #36 | |
Duke
Join Date: Jan 2007
Posts: 3,939
|
Quote:
__________________
"Nunca un científico ha quemado a un religioso por afirmar a Dios sin pruebas". Manuel Toharia "uno empieza a darse cuenta que eso de no hacer ejercicio, comer y beber como si fuese la ultima cena y mantener la figura ya no existe...". Maryan |
|
01-14-2008, 06:22 PM | #37 | |
Duke
Join Date: Nov 2006
Location: 0x00CAFE
Posts: 3,366
|
Quote:
I'm starting a new topic so you can tell me why it should be banned.
__________________
I don't have a solution, but I admire the problem. |
|
01-15-2008, 08:09 PM | #38 | |
Count
Join Date: Jul 2007
Location: Toulouse
Posts: 1,335
|
Quote:
__________________
« Thanks all, you are right I'm great with the barbarian ... for killing mobs. » -- Athena Stillwater
|
|
01-15-2008, 09:56 PM | #39 | |
Duke
Join Date: Nov 2006
Location: 0x00CAFE
Posts: 3,366
|
Quote:
It takes 4 seconds to parse, search, fill the vectors and display the information. Totally unacceptable for me, because DOM iterates over the file several times.
__________________
I don't have a solution, but I admire the problem. |
|
Thread Tools | |
Display Modes | |
|
|