|
-
Feb 3rd, 2008, 12:35 PM
#1
[RESOLVED] [2008] XML file. Some help please
Hi,
I have a database with some data in it. My application reads this database and orders the data into a Treeview.
Now, I would like to stop using the database since the requirement of a database connection etc etc are a bit too much hassle for something that I'm sure can be done much easier.
Also, it is supposed to be read only, the user cannot edit it, so there is really no need for a database, right?
My idea was to use an XML file instead of the database.
Now, I know nothing about XML so I hope you guys could tell me if it was possible, and how I should start using it?
My data is order something like this:
First of all, there is a "Category" field. There are about 10 categories.
Then, in each of the categories, there are "Commands". Each command also has a "Description".
Something like this:
Code:
CATEGORY | COMMAND | DESCRIPTION
----------|-----------|-------------
Cat. 1 | Command 1 | This is command 1.
Cat. 1 | Command 2 | This is command 2.
Cat. 1 | Command 3 | And command 3.
Cat. 2 | Command 1 | This is command 1, in Cat 2
Cat. 2 | Command x | Blaa...
Cat. 3 | ... | ...
Could you show me roughly how this would look in XML?
Thanks!
Something I came up with, I have no idea if it's right:
Code:
<category CAT="Cat. 1">
<command COM="Command 1">
<descr>This is command 1.</descr>
<descr2>Some other description, also for Command 1</descr2>
</command>
<command COM="Command 2">
<descr>This is command 2.</descr>
<descr2>Some other descr. for command 2</descr2>
</command>
etc...
</category>
<category CAT="Cat. 2">
<command COM="Command 1">
<descr>This is command 1, in Cat 2</descr>
<descr2>Some other...</descr2>
</command>
etc...
</category>
etc...
EDIT
I have also found examples that handle it like this, what would be more easy to acces ?
Code:
<category>
<name>Cat. 1</name>
<command>
<name>Command 1</name>
<descr>This is command 1.</descr>
<descr2>Some other description, also for Command 1</descr2>
</command>
</category>
Last edited by NickThissen; Feb 3rd, 2008 at 12:58 PM.
-
Feb 3rd, 2008, 05:54 PM
#2
Re: [2008] XML file. Some help please
Just create a structure or a class and use serialization if you want to use XML.
Casey.
-
Feb 4th, 2008, 06:12 AM
#3
Re: [2008] XML file. Some help please
For the XML I would consider structuring it like this
Code:
<parent>
<category id="Cat. 1">
<commandDesc>
<command>Command 1</command>
<description>This is command 1</description>
</commandDesc>
<commandDesc>
<command>Command 2</command>
<description>This is command 2</description>
</commandDesc>
<commandDesc>
<command>Command 3</command>
<description>And command 3</description>
</commandDesc>
</category>
<category id="Cat. 2">
<commandDesc>
<command>Command 1</command>
<description>This is command 1</description>
</commandDesc>
<commandDesc>
<command>Command 2</command>
<description>This is command 2</description>
</commandDesc>
<commandDesc>
<command>Command 3</command>
<description>And command 3</description>
</commandDesc>
</category>
</parent>
I would use the <commandDesc> to store all the commands/descriptions for each category. That way, it should be easier to loop through when coding.
ps. Don’t forget when you use XML the tags are case sensitive unlike plain HTML.
Last edited by kevchadders; Feb 4th, 2008 at 06:16 AM.
-
Feb 4th, 2008, 07:32 AM
#4
Re: [2008] XML file. Some help please
Thanks.
Could you show me how I should loop through this to put it into a Treeview for example?
How can I distinguish between the first "commandDesc" or the third for example?
If I'm using "<command COM="command name">" then it looks easier to me, no? I could be completely wrong though, just a thought.
-
Feb 4th, 2008, 08:15 AM
#5
Re: [2008] XML file. Some help please
Could anyone show me how I could put the following XML file into a treeview? Or part of it... I have no idea how to start doing this... I've read some XML articles/tutorials but most are just about retrieving the number of elements etc... No help here I guess...
Code:
<?xml version="1.0" encoding="utf-8" ?>
<scriptcommands>
<category CAT="Level Interaction">
<command COM="setglobalfog 0">
<descr1>setglobalfog 0 [duration] [float:r] [float:g] [float:b] [float:depthForOpaque]</descr1>
<descr2>Changes the global fog in a map to a specific color and density.</descr2>
</command>
<command COM="setglobalfog 1">
<descr1>setglobalfog 1 [duration]</descr1>
<descr2>Changes the global fog in a map.</descr2>
</command>
<command COM="spawnrubble">
<descr1>spawnrubble [targetname]</descr1>
<descr2>Spawn rubble, use in combination with func_debris.</descr2>
</command>
</category>
<category CAT="Other">
<command COM="setautospawn">
<descr1>setautospawn [target_spawn] [team]</descr1>
<descr2>Set the autospawn of a team to 'target_spawn'. The 'target_spawn' string is the 'description' key on the team_WOLF_objective.</descr2>
</command>
<command COM="wm_allied_respawntime">
<descr1>wm_allied_respawntime [seconds]</descr1>
<descr2>Respawn time for the allied team.</descr2>
</command>
<command COM="wm_axis_respawntime">
<descr1>wm_axis_respawntime [seconds]</descr1>
<descr2>Respawn time for the axis team.</descr2>
</command>
</category>
</scriptcommands>
I don't need the descriptions (descr1 and descr2) in the treeview, they are for later access.
The treeview should look something like this:
Code:
[] Level Interaction
|--- setglobalfog 0
|--- setglobalfog 1
|--- spawnrubble
[] Other
|--- setautospawn
|--- wm_allied_respawntime
|--- wm_axis_respawntime
Last edited by NickThissen; Feb 4th, 2008 at 08:19 AM.
-
Feb 4th, 2008, 06:04 PM
#6
Re: [RESOLVED] [2008] XML file. Some help please
If you wish to just read the XML (not write), you can use the XMLNodeReader, or XMLText reader class. These will traverse the document in a hierachical(sp?) manner and more importantly indicate node name and depth.
This can then be used to determine where in the tree your data needs to go.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|