Go Back   Champions of Regnum > English > The Inn

The Inn A place to gather around and chat about almost any subject

Reply
 
Thread Tools Display Modes
Old 11-26-2007, 05:52 PM   #31
ArcticWolf
Duke
 
ArcticWolf's Avatar
 
Join Date: Nov 2006
Location: 0x00CAFE
Posts: 3,366
ArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of light
Default

Quote:
Originally Posted by Yest
Nice! UML isn't required, but I think it will make developping easier.
This is a small, very small project, so I think UML isn't so vital... In fact, we developed the entire ROLGps project without a single diagram
__________________
I don't have a solution, but I admire the problem.
ArcticWolf no ha iniciado sesión   Reply With Quote
Old 01-14-2008, 08:06 AM   #32
ArcticWolf
Duke
 
ArcticWolf's Avatar
 
Join Date: Nov 2006
Location: 0x00CAFE
Posts: 3,366
ArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of light
Default

Quote:
Originally Posted by Xephandor
This is a small, very small project, so I think UML isn't so vital... In fact, we developed the entire ROLGps project without a single diagram
...And that's why ROLGps needs a complete rewrite now.

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;
    }
The XML file:
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>
The result for number one:

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.
ArcticWolf no ha iniciado sesión   Reply With Quote
Old 01-14-2008, 04:49 PM   #33
_dracus_
Count
 
_dracus_'s Avatar
 
Join Date: Jul 2007
Location: Toulouse
Posts: 1,335
_dracus_ is on a distinguished road
Default

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
_dracus_ no ha iniciado sesión   Reply With Quote
Old 01-14-2008, 05:10 PM   #34
arlick
Duke
 
arlick's Avatar
 
Join Date: Jan 2007
Posts: 3,939
arlick is a jewel in the rougharlick is a jewel in the rougharlick is a jewel in the rough
Default

Quote:
Originally Posted by gph
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.
hahaha

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
arlick no ha iniciado sesión   Reply With Quote
Old 01-14-2008, 05:24 PM   #35
_dracus_
Count
 
_dracus_'s Avatar
 
Join Date: Jul 2007
Location: Toulouse
Posts: 1,335
_dracus_ is on a distinguished road
Default

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
_dracus_ no ha iniciado sesión   Reply With Quote
Old 01-14-2008, 05:27 PM   #36
arlick
Duke
 
arlick's Avatar
 
Join Date: Jan 2007
Posts: 3,939
arlick is a jewel in the rougharlick is a jewel in the rougharlick is a jewel in the rough
Default

Quote:
Originally Posted by gph
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.
well your are right, do u wanna open a thread to discuss about programing languages?
__________________
"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
arlick no ha iniciado sesión   Reply With Quote
Old 01-14-2008, 06:22 PM   #37
ArcticWolf
Duke
 
ArcticWolf's Avatar
 
Join Date: Nov 2006
Location: 0x00CAFE
Posts: 3,366
ArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of light
Default

Quote:
Originally Posted by gph
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.
Please, PLEASE don't make a flame out of this post...

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.
ArcticWolf no ha iniciado sesión   Reply With Quote
Old 01-15-2008, 08:09 PM   #38
_dracus_
Count
 
_dracus_'s Avatar
 
Join Date: Jul 2007
Location: Toulouse
Posts: 1,335
_dracus_ is on a distinguished road
Default

Quote:
Originally Posted by Xephandor
Please, PLEASE don't make a flame out of this post...

I'm starting a new topic so you can tell me why it should be banned.
To get back on the topic, your idea is great. I hope NGD will have the time and ressource to answer to this request. After implementation language is just a tool (you can like it or not, it's up to you).
__________________
« Thanks all, you are right I'm great with the barbarian ... for killing mobs. » -- Athena Stillwater
_dracus_ no ha iniciado sesión   Reply With Quote
Old 01-15-2008, 09:56 PM   #39
ArcticWolf
Duke
 
ArcticWolf's Avatar
 
Join Date: Nov 2006
Location: 0x00CAFE
Posts: 3,366
ArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of lightArcticWolf is a glorious beacon of light
Default

Quote:
Originally Posted by gph
To get back on the topic, your idea is great. I hope NGD will have the time and ressource to answer to this request. After implementation language is just a tool (you can like it or not, it's up to you).
Thanks!! The idea is to improve the current rolgps and to make it more universal, so if we have to update or add something to the file it would be matter of minutes to adapt the program. I'm starting to think that DOM isn't the best idea, I should use SAX to make it faster.

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.
ArcticWolf no ha iniciado sesión   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:20 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
NGD Studios 2002-2024 © All rights reserved