Results 1 to 6 of 6

Thread: [RESOLVED] [2008] XML file. Some help please

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Resolved [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.

  2. #2
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: [2008] XML file. Some help please

    Just create a structure or a class and use serialization if you want to use XML.

    Casey.

  3. #3
    Hyperactive Member
    Join Date
    Jan 2008
    Location
    Merseyside
    Posts
    456

    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.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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.

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width