Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

C# & XML

Tdata

Sponsor

I know that I keep asking questions here rather than at a site made to answer such questions, but you all are a lot nicer at explaining things than they are.

My question:
I plan to use xml files to store game data for a game I am currently working on to cut down on the SQL calls I have to make. My problem is that I can't seem to find a Tutorial that explains how to deal with a lot of nodes.

So, how would I read something like this:
XML:
<div class="xml" id="{CB}" style="font-family: monospace;"><ol> 

<span style="color: #009900;"><span style="font-weight: bold; color: black;"><?xml version="1.0" encoding="utf-8" <span style="font-weight: bold; color: black;">?>

<span style="color: #009900;"><span style="font-weight: bold; color: black;"><MechList<span style="font-weight: bold; color: black;">>

  <span style="color: #009900;"><span style="font-weight: bold; color: black;"><Mech<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><name<span style="font-weight: bold; color: black;">>WarMachine<span style="color: #009900;"><span style="font-weight: bold; color: black;"></name<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><type<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></type<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><id<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></id<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon1<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon1<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon2<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon2<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon3<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon3<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon4<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon4<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo1<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo1<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo2<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo2<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo3<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo3<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo4<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo4<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><head<span style="font-weight: bold; color: black;">>19<span style="color: #009900;"><span style="font-weight: bold; color: black;"></head<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><cTorso<span style="font-weight: bold; color: black;">>23<span style="color: #009900;"><span style="font-weight: bold; color: black;"></cTorso<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rTorso<span style="font-weight: bold; color: black;">>20<span style="color: #009900;"><span style="font-weight: bold; color: black;"></rTorso<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><lTorso<span style="font-weight: bold; color: black;">>20<span style="color: #009900;"><span style="font-weight: bold; color: black;"></lTorso<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rArm<span style="font-weight: bold; color: black;">>15<span style="color: #009900;"><span style="font-weight: bold; color: black;"></rArm<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><lArm<span style="font-weight: bold; color: black;">>15<span style="color: #009900;"><span style="font-weight: bold; color: black;"></lArm<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rLeg<span style="font-weight: bold; color: black;">>21<span style="color: #009900;"><span style="font-weight: bold; color: black;"></rLeg<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><lLeg<span style="font-weight: bold; color: black;">>21<span style="color: #009900;"><span style="font-weight: bold; color: black;"></lLeg<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><walk<span style="font-weight: bold; color: black;">>5<span style="color: #009900;"><span style="font-weight: bold; color: black;"></walk<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><run<span style="font-weight: bold; color: black;">>8<span style="color: #009900;"><span style="font-weight: bold; color: black;"></run<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><jump<span style="font-weight: bold; color: black;">>5<span style="color: #009900;"><span style="font-weight: bold; color: black;"></jump<span style="font-weight: bold; color: black;">>

  <span style="color: #009900;"><span style="font-weight: bold; color: black;"></Mech<span style="font-weight: bold; color: black;">>

  <span style="color: #009900;"><span style="font-weight: bold; color: black;"><Mech<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><name<span style="font-weight: bold; color: black;">>WarMachine - IIC<span style="color: #009900;"><span style="font-weight: bold; color: black;"></name<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><type<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></type<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><id<span style="font-weight: bold; color: black;">>2<span style="color: #009900;"><span style="font-weight: bold; color: black;"></id<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon1<span style="font-weight: bold; color: black;">>2<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon1<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon2<span style="font-weight: bold; color: black;">>2<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon2<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon3<span style="font-weight: bold; color: black;">>2<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon3<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon4<span style="font-weight: bold; color: black;">>2<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon4<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo1<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo1<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo2<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo2<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo3<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo3<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo4<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo4<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><head<span style="font-weight: bold; color: black;">>19<span style="color: #009900;"><span style="font-weight: bold; color: black;"></head<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><cTorso<span style="font-weight: bold; color: black;">>23<span style="color: #009900;"><span style="font-weight: bold; color: black;"></cTorso<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rTorso<span style="font-weight: bold; color: black;">>20<span style="color: #009900;"><span style="font-weight: bold; color: black;"></rTorso<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><lTorso<span style="font-weight: bold; color: black;">>20<span style="color: #009900;"><span style="font-weight: bold; color: black;"></lTorso<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rArm<span style="font-weight: bold; color: black;">>15<span style="color: #009900;"><span style="font-weight: bold; color: black;"></rArm<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><lArm<span style="font-weight: bold; color: black;">>15<span style="color: #009900;"><span style="font-weight: bold; color: black;"></lArm<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rLeg<span style="font-weight: bold; color: black;">>21<span style="color: #009900;"><span style="font-weight: bold; color: black;"></rLeg<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><lLeg<span style="font-weight: bold; color: black;">>21<span style="color: #009900;"><span style="font-weight: bold; color: black;"></lLeg<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><walk<span style="font-weight: bold; color: black;">>5<span style="color: #009900;"><span style="font-weight: bold; color: black;"></walk<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><run<span style="font-weight: bold; color: black;">>8<span style="color: #009900;"><span style="font-weight: bold; color: black;"></run<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><jump<span style="font-weight: bold; color: black;">>5<span style="color: #009900;"><span style="font-weight: bold; color: black;"></jump<span style="font-weight: bold; color: black;">>

  <span style="color: #009900;"><span style="font-weight: bold; color: black;"></Mech<span style="font-weight: bold; color: black;">>

  <span style="color: #009900;"><span style="font-weight: bold; color: black;"><Mech<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><name<span style="font-weight: bold; color: black;">>WarMachine - IIC II<span style="color: #009900;"><span style="font-weight: bold; color: black;"></name<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><type<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></type<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><id<span style="font-weight: bold; color: black;">>3<span style="color: #009900;"><span style="font-weight: bold; color: black;"></id<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon1<span style="font-weight: bold; color: black;">>3<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon1<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon2<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon2<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon3<span style="font-weight: bold; color: black;">>3<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon3<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon4<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon4<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo1<span style="font-weight: bold; color: black;">>2<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo1<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo2<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo2<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo3<span style="font-weight: bold; color: black;">>2<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo3<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo4<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo4<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><head<span style="font-weight: bold; color: black;">>19<span style="color: #009900;"><span style="font-weight: bold; color: black;"></head<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><cTorso<span style="font-weight: bold; color: black;">>23<span style="color: #009900;"><span style="font-weight: bold; color: black;"></cTorso<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rTorso<span style="font-weight: bold; color: black;">>20<span style="color: #009900;"><span style="font-weight: bold; color: black;"></rTorso<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><lTorso<span style="font-weight: bold; color: black;">>20<span style="color: #009900;"><span style="font-weight: bold; color: black;"></lTorso<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rArm<span style="font-weight: bold; color: black;">>15<span style="color: #009900;"><span style="font-weight: bold; color: black;"></rArm<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><lArm<span style="font-weight: bold; color: black;">>15<span style="color: #009900;"><span style="font-weight: bold; color: black;"></lArm<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rLeg<span style="font-weight: bold; color: black;">>21<span style="color: #009900;"><span style="font-weight: bold; color: black;"></rLeg<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><lLeg<span style="font-weight: bold; color: black;">>21<span style="color: #009900;"><span style="font-weight: bold; color: black;"></lLeg<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><walk<span style="font-weight: bold; color: black;">>5<span style="color: #009900;"><span style="font-weight: bold; color: black;"></walk<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><run<span style="font-weight: bold; color: black;">>8<span style="color: #009900;"><span style="font-weight: bold; color: black;"></run<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><jump<span style="font-weight: bold; color: black;">>5<span style="color: #009900;"><span style="font-weight: bold; color: black;"></jump<span style="font-weight: bold; color: black;">>

  <span style="color: #009900;"><span style="font-weight: bold; color: black;"></Mech<span style="font-weight: bold; color: black;">>

  <span style="color: #009900;"><span style="font-weight: bold; color: black;"><Mech<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><name<span style="font-weight: bold; color: black;">>MasterBlaster<span style="color: #009900;"><span style="font-weight: bold; color: black;"></name<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><type<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></type<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><id<span style="font-weight: bold; color: black;">>4<span style="color: #009900;"><span style="font-weight: bold; color: black;"></id<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon1<span style="font-weight: bold; color: black;">>2<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon1<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon2<span style="font-weight: bold; color: black;">>2<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon2<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon3<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon3<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><weapon4<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></weapon4<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo1<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo1<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo2<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo2<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo3<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo3<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><ammo4<span style="font-weight: bold; color: black;">>1<span style="color: #009900;"><span style="font-weight: bold; color: black;"></ammo4<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><head<span style="font-weight: bold; color: black;">>19<span style="color: #009900;"><span style="font-weight: bold; color: black;"></head<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><cTorso<span style="font-weight: bold; color: black;">>32<span style="color: #009900;"><span style="font-weight: bold; color: black;"></cTorso<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rTorso<span style="font-weight: bold; color: black;">>45<span style="color: #009900;"><span style="font-weight: bold; color: black;"></rTorso<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><lTorso<span style="font-weight: bold; color: black;">>32<span style="color: #009900;"><span style="font-weight: bold; color: black;"></lTorso<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rArm<span style="font-weight: bold; color: black;">>23<span style="color: #009900;"><span style="font-weight: bold; color: black;"></rArm<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><lArm<span style="font-weight: bold; color: black;">>23<span style="color: #009900;"><span style="font-weight: bold; color: black;"></lArm<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rLeg<span style="font-weight: bold; color: black;">>31<span style="color: #009900;"><span style="font-weight: bold; color: black;"></rLeg<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><lLeg<span style="font-weight: bold; color: black;">>31<span style="color: #009900;"><span style="font-weight: bold; color: black;"></lLeg<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><walk<span style="font-weight: bold; color: black;">>7<span style="color: #009900;"><span style="font-weight: bold; color: black;"></walk<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><run<span style="font-weight: bold; color: black;">>11<span style="color: #009900;"><span style="font-weight: bold; color: black;"></run<span style="font-weight: bold; color: black;">>

    <span style="color: #009900;"><span style="font-weight: bold; color: black;"><jump<span style="font-weight: bold; color: black;">>7<span style="color: #009900;"><span style="font-weight: bold; color: black;"></jump<span style="font-weight: bold; color: black;">>

  <span style="color: #009900;"><span style="font-weight: bold; color: black;"></Mech<span style="font-weight: bold; color: black;">>

<span style="color: #009900;"><span style="font-weight: bold; color: black;"></MechList<span style="font-weight: bold; color: black;">>

 

and insert them into this:
Code:
 

Mech[] MechList = new MechList[];

 
Without knowing for certain how many Items will be needed.
And the Struct being:
Code:
 

using System;

 

 

namespace UnnamedChaos_20.Client

{

    public struct Mech

    {

        #region

        public string name;

        public short type;

        public short id;

        public string icon;

        public short weapon1;

        public short weapon2;

        public short weapon3;

        public short weapon4;

        public short ammo1;

        public short ammo2;

        public short ammo3;

        public short ammo4;

        public short heada;

        public short ctorsoa;

        public short ltorsoa;

        public short rtorsoa;

        public short rarma;

        public short larma;

        public short rlega;

        public short llega;

        public short walk;

        public short run;

        public short jump;

        #endregion

 

 

        /*add whatever more you need, don't forget to add the atributes though or make the vars public public*/

        public Mech(string _name, short _type, short _id, string _icon, short _w1, short _w2, short _w3, short _w4, short _a1,

            short _a2, short _a3, short _a4, short _h, short _ct, short _lt, short _rt, short _ra, short _la, short _rl,

            short _ll, short _w, short _r, short _j)

        {

            name = _name;

            type = _type;

            id = _id;

            icon = _icon;

            weapon1 = _w1;

            weapon2 = _w2;

            weapon3 = _w3;

            weapon4 = _w4;

            ammo1 = _a1;

            ammo2 = _a2;

            ammo3 = _a3;

            ammo4 = _a4;

            heada = _h;

            ctorsoa = _ct;

            ltorsoa = _lt;

            rtorsoa = _rt;

            rarma = _ra;

            larma = _la;

            rlega = _rl;

            llega = _ll;

            walk = _w;

            run = _r;

            jump = _j;

        }

    }

}

 

 

 


And as an afterthought, if they are in a folder called Data and I set them to Compile, how would I access them. I've never really understood how you use embedded stuff...
 

OS

Sponsor

OK, so what you need is an XML parser. Using the XML namespace. It's really easy.

Go to CSharp Corner. This page will show you the most basic way, but there is a bit more to it.

Search that site. That is where I learned to make my XML Parser, which I used for Add Ons in one of my apps.

Don't know about the second question. I would search that site for that answer as well.

Good luck.

~Owen Sael
 

Tdata

Sponsor

My only real issue is with getting it to go from one Mech tag to the next. I can't seem to get it to go though all of them...

Oh, and I found the answer to my afterthought while looking for the answer to my main question.
 

OS

Sponsor

Code:
 

XmlDocument xmlDoc= new XmlDocument(); //* create an xml document object.

xmlDoc.Load("yourXMLFile.xml"); //* load the XML document from the specified file.

 

//* Get elements.

XmlNodeList girlAddress = xmlDoc.GetElementsByTagName("gAddress");

XmlNodeList girlAge = xmlDoc.GetElementsByTagName("gAge"); 

XmlNodeList girlCellPhoneNumber = xmlDoc.GetElementsByTagName("gPhone");

 

//* Display the results.

Console.WriteLine("Address: " + girlAddress[0].InnerText);

Console.WriteLine("Age: " + girlAge[0].InnerText);

Console.WriteLine("Phone Number: " + girlCellPhoneNumber[0].InnerText);

 

 

SOURCE

That seems pretty straight forward. Store all the nodes in lists and read them like you would from an Array or List<T>. That one has some other good tips too.
 

Tdata

Sponsor

I seemed to have missed the fact that they use NodeList. As it is a Array Form, you can go though it... Thank you. Although, my main issue was with the fact that every example I found to do it used 15+ lines of code with things like NextNode, or SecondChild... Unless they are explained, I never have a clue how to use them and expand them.


.::EDIT::.

Seems that I made .NET mad somehow.
Error_XML.png


And here is the Block It doesn't seem to like:
Code:
 

 

                Mech[] mList = new Mech[name.Count];

                while (x < name.Count)

                {

 

           [color=#FF0000] ----->[/color] mList[x] = new Mech(name[x].Value.ToString(), Convert.ToInt32(type[x].Value), Convert.ToInt32(id[x].Value), icon[x].Value.ToString(), Convert.ToInt32(weapon1[x].Value), Convert.ToInt32(weapon2[x].Value), Convert.ToInt32(weapon3[x].Value), 

                    Convert.ToInt32(weapon4[x].Value), Convert.ToInt32(ammo1[x].Value), Convert.ToInt32(ammo2[x].Value), Convert.ToInt32(ammo3[x].Value), Convert.ToInt32(ammo4[x].Value), Convert.ToInt32(head[x].Value), Convert.ToInt32(cTorso[x].Value), Convert.ToInt32(rTorso[x].Value), Convert.ToInt32(lTorso[x].Value),

                        Convert.ToInt32(rArm[x].Value), Convert.ToInt32(lArm[x].Value), Convert.ToInt32(rLeg[x].Value), Convert.ToInt32(lLeg[x].Value), Convert.ToInt32(walk[x].Value), Convert.ToInt32(run[x].Value), Convert.ToInt32(jump[x].Value));

                    x++;

                    

                }

                return mList;

 

 

Not quite sure what I did to piss it off...
 

OS

Sponsor

It is obviously not the mList object, which is initialized at the top there. However, you have several other objects in that one line that could not be initialized. Check each one and make sure that they have been created correctly. You might have missed one or two.

....!

Did you set x to anything? It looks like you just threw it out there without defining it before hand. Perhaps you should just use a FOR loop, so that this doesn't occur:

for (int x = 0; x < name.Length; x++)
 

Tdata

Sponsor

Code:
 

 

public class MechList

    {

        public Mech[] Mechlist()

        {

            

            try

            {

                XmlDocument xDoc = new XmlDocument();

                xDoc.Load(Assembly.GetExecutingAssembly().GetManifestResourceStream("UnnamedChaos_20.Data.MechList.xml")); //File is located in the "\bin\Debug" folder

 

                XmlNodeList name = xDoc.GetElementsByTagName("name");

                XmlNodeList type = xDoc.GetElementsByTagName("type");

                XmlNodeList id = xDoc.GetElementsByTagName("id");

                XmlNodeList icon = xDoc.GetElementsByTagName("icon");

                XmlNodeList weapon1 = xDoc.GetElementsByTagName("weapon1");

                XmlNodeList weapon2 = xDoc.GetElementsByTagName("weapon2");

                XmlNodeList weapon3 = xDoc.GetElementsByTagName("weapon3");

                XmlNodeList weapon4 = xDoc.GetElementsByTagName("weapon4");

                XmlNodeList ammo1 = xDoc.GetElementsByTagName("ammo1");

                XmlNodeList ammo2 = xDoc.GetElementsByTagName("ammo2");

                XmlNodeList ammo3 = xDoc.GetElementsByTagName("ammo3");

                XmlNodeList ammo4 = xDoc.GetElementsByTagName("ammo4");

                XmlNodeList head = xDoc.GetElementsByTagName("head");

                XmlNodeList cTorso = xDoc.GetElementsByTagName("cTorso");

                XmlNodeList rTorso = xDoc.GetElementsByTagName("rTorso");

                XmlNodeList lTorso = xDoc.GetElementsByTagName("lTorso");

                XmlNodeList rArm = xDoc.GetElementsByTagName("rArm");

                XmlNodeList lArm = xDoc.GetElementsByTagName("lArm");

                XmlNodeList rLeg = xDoc.GetElementsByTagName("rLeg");

                XmlNodeList lLeg = xDoc.GetElementsByTagName("lLeg");

                XmlNodeList walk = xDoc.GetElementsByTagName("walk"); 

                XmlNodeList run = xDoc.GetElementsByTagName("run"); 

                XmlNodeList jump = xDoc.GetElementsByTagName("jump");

 

                Mech[] mList = new Mech[name.Count];

                for (int x = 0; x < name.Count; x++)

                {

 

                    mList[x] = new Mech(name[x].Value.ToString(), Convert.ToInt32(type[x].Value), Convert.ToInt32(id[x].Value), icon[x].Value.ToString(), Convert.ToInt32(weapon1[x].Value), Convert.ToInt32(weapon2[x].Value), Convert.ToInt32(weapon3[x].Value), 

                    Convert.ToInt32(weapon4[x].Value), Convert.ToInt32(ammo1[x].Value), Convert.ToInt32(ammo2[x].Value), Convert.ToInt32(ammo3[x].Value), Convert.ToInt32(ammo4[x].Value), Convert.ToInt32(head[x].Value), Convert.ToInt32(cTorso[x].Value), Convert.ToInt32(rTorso[x].Value), Convert.ToInt32(lTorso[x].Value),

                        Convert.ToInt32(rArm[x].Value), Convert.ToInt32(lArm[x].Value), Convert.ToInt32(rLeg[x].Value), Convert.ToInt32(lLeg[x].Value), Convert.ToInt32(walk[x].Value), Convert.ToInt32(run[x].Value), Convert.ToInt32(jump[x].Value));

                    

                    

                }

                return mList;

 

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.ToString());

                Mech[] mList = new Mech[1];

                mList[0] = new Mech();

                return mList;

            }

            

        }

    }

 

Same Result. It doesn't seem to like the mList = new Mech(); itself. Is there anything extra I need to do to the Mech struct to use it as an array of itself?

.::Edit::.
I should have figured it out sooner. INNERTEXT!!! Works so far now.
 

OS

Sponsor

Oh, haha. I didn't even notice.

If you need any more C# help, lemme know.

Good luck.

~Owesome Scriptor
 
Hey,

Not really sure that its applicable as you seem to have solved things, but you can acctually do this a few other ways that may seem a bit daunting at first but would make things 10x easier for you to extend your DB caching via XML files...

If you are interested in taking a harder but better route, look at XMLSerialization and XMLContractSerializer (i think its called) there is a JSON version too... you basically make your class and then call a data contract serializer object and pass it an instance of your object and it pops out a serialized XML string... you can use custom attributes to customize the way it exports/imports your objects/xml.

http://msdn.microsoft.com/en-us/library ... lizer.aspx

I think the above should give you a taster of it... WCF uses it under the hood to serialize objects between server and client. I use this method (although its the JSON version) for serializing all my objects between my backend and frontend...

The other method is pretty much the same as your method but using the newer XDocument/XElement classes, which are alot nicer (i find) than using the normal XmlReader classes...
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top