nice to hear
here is another example for using this plugin. it's more documented and the same example as in the example folder in the download.
` Some Constants for an easy access of the XML-Nodes(Elements).
#CONSTANT xml_doc = 1
#CONSTANT xml_root = 1
#CONSTANT xml_work = 2
#CONSTANT xml_race = 100
#CONSTANT xml_enc = 200
#CONSTANT xml_prof = 300
#CONSTANT xml_base = 400
` Some Vars to store data
GLOBAL DIM race$(9)
GLOBAL DIM enc$(9)
GLOBAL DIM prof$(9)
GLOBAL DIM attrib$(11)
GLOBAL hero_desc$
GLOBAL enc_desc$
GLOBAL DIM hero_prob#(2, 11)
GLOBAL DIM enc_prob#(11)
` Open the XML-File.
XML OPEN DOCUMENT "rpg.xml", xml_doc
` File exists? ...
IF FILE EXIST ("rpg.xml")
` ... yes. Load Xml-File into memory.
XML LOAD DOCUMENT xml_doc
` Get the Root-Element and store it in constant xml_root.
XML GET ROOT ELEMENT xml_doc, xml_root
` Get 'Race'-Node and store it in constant xml_race
XML GET ELEMENT xml_root, "Creatures/Race", xml_race
` Get 'Encounter'-Node and store it in constant xml_enc
XML GET ELEMENT xml_root, "Creatures/Encounter", xml_enc
` Get 'Profesion'-Node and store it in constant xml_prof
XML GET ELEMENT xml_root, "Creatures/Profesion", xml_prof
` Get 'Base'-Node and store it in constant xml_base
XML GET ELEMENT xml_root, "Creatures/Base", xml_base
ENDIF
` if Element-ID 'xml_base' valid then fillup the attributes.
IF XML IS VALID ELEMENT (xml_base) THEN GetAttributes()
` if Element-ID 'xml_race' valid then Select the Race.
IF XML IS VALID ELEMENT(xml_race) THEN SelectRace()
SLEEP 250
` if Element-ID 'xml_prof' valid then Select the Profession.
IF XML IS VALID ELEMENT(xml_prof) THEN SelectProfession()
SLEEP 250
` if Element-ID 'xml_enc' valid then Select the Encounter.
IF XML IS VALID ELEMENT(xml_enc) THEN SelectEncounter()
SLEEP 250
` if Element-ID 'xml_base' valid then Print states.
IF XML IS VALID ELEMENT (xml_base) THEN OutputStates()
WAIT KEY
END
` Fillup var-array attrib$
FUNCTION GetAttributes()
` Get count of Attributes in Element 'Base'
numAttrib = XML COUNT ATTRIBUTES (xml_base)
FOR i=1 TO numAttrib
` Get Attribute-Name and store it (1 - numAtrib).
attrib$(i) = XML GET ATTRIBUTE NAME(xml_base, i)
NEXT i
ENDFUNCTION
` Printing Properties of selected Characters
FUNCTION OutputStates()
enc_level = RND(10) + 1
enc_desc$ = enc_desc$ + "(LEVEL: " + STR$(enc_level) + ")"
CLS
SET CURSOR 30, 30
PRINT "Hero: "; hero_desc$
SET CURSOR 344, 30
PRINT "Encounter: "; enc_desc$
FOR i=1 TO 11
` Get the integer attribute value. attrib$(i) = Attribute-Name
value = XML GET INTEGER ATTRIBUTE(xml_base, attrib$(i))
SET CURSOR 0, 30+i*10
PRINT attrib$(i); " :"; value * (hero_prob#(1, i) + hero_prob#(2, i))
SET CURSOR 320, 30+i*10
PRINT attrib$(i); " :"; value * (enc_prob#(i) * enc_level)
NEXT
ENDFUNCTION
` Select the race of your Hero.
FUNCTION SelectRace()
` Get the first child of the Element in xml_race.
XML GET CHILD ELEMENT xml_race, xml_work
count = 1
` Get the Name of the Element in xml_work
race$(count) = XML GET ELEMENT NAME(xml_work)
PRINT "Select a Race."
WHILE XML IS VALID ELEMENT (xml_work)
` Read the Text-Node out.
desc$ = XML GET TEXT (xml_work)
PRINT "[";count;"] ", race$(count)
PRINT " ", desc$
` Get the next Element and overwrites the current Element in xml_work.
XML GET NEXT ELEMENT xml_work, xml_work
INC count
` Get the Name of current Element in xml_work.
race$(count) = XML GET ELEMENT NAME (xml_work)
ENDWHILE
selection = 0
WHILE selection = 0
selection = ASC(INKEY$())
ENDWHILE
selection = selection - 48
IF selection >= count THEN selection = count - 1
IF selection <= 0 THEN selection = 1
SetRaceProbs(race$(selection))
PRINT "Selection: "; race$(selection)
PRINT
hero_desc$ = race$(selection)
ENDFUNCTION
` Select the Encounter. For linedescription show Function 'SelectRace'.
` Is the same way.
FUNCTION SelectEncounter()
XML GET CHILD ELEMENT xml_enc, xml_work
count = 1
enc$(count) = XML GET ELEMENT NAME(xml_work)
PRINT "Select a Encounter."
WHILE XML IS VALID ELEMENT (xml_work)
PRINT "[";count;"] ", enc$(count)
XML GET NEXT ELEMENT xml_work, xml_work
INC count
enc$(count) = XML GET ELEMENT NAME (xml_work)
ENDWHILE
selection = 0
WHILE selection = 0
selection = ASC(INKEY$())
ENDWHILE
selection = selection - 48
IF selection >= count THEN selection = count - 1
IF selection <= 0 THEN selection = 1
SetEncProbs(enc$(selection))
PRINT "Selection: "; enc$(selection)
PRINT
enc_desc$ = enc$(selection)
ENDFUNCTION
` Select the Profession of your Hero. For linedescription show Function
` 'SelectRace'. Is the same way.
FUNCTION SelectProfession()
XML GET CHILD ELEMENT xml_prof, xml_work
count = 1
prof$(count) = XML GET ELEMENT NAME(xml_work)
PRINT "Select a Profession."
WHILE XML IS VALID ELEMENT (xml_work)
PRINT "[";count;"] ", prof$(count)
XML GET NEXT ELEMENT xml_work, xml_work
INC count
prof$(count) = XML GET ELEMENT NAME (xml_work)
ENDWHILE
selection = 0
WHILE selection = 0
selection = ASC(INKEY$())
ENDWHILE
selection = selection - 48
IF selection >= count THEN selection = count - 1
IF selection <= 0 THEN selection = 1
SetProfProbs(prof$(selection))
PRINT "Selection: "; prof$(selection)
PRINT
hero_desc$ = hero_desc$ + "(" + prof$(selection) + ")"
ENDFUNCTION
` Set the selected Race-Properties of your Hero.
FUNCTION SetRaceProbs(_race$)
` Get the next child-Element with the given name.
XML GET CHILD ELEMENT xml_race, _race$, xml_work
FOR i=1 TO 11
` Get Attribute as float and store it in hero_prob.
hero_prob#(1, i) = XML GET FLOAT ATTRIBUTE(xml_work, attrib$(i))
NEXT
ENDFUNCTION
` Same as 'SetRaceProbs' but for Encounter.
FUNCTION SetEncProbs(_race$)
XML GET CHILD ELEMENT xml_enc, _race$, xml_work
FOR i=1 TO 11
enc_prob#(i) = XML GET FLOAT ATTRIBUTE(xml_work, attrib$(i))
NEXT
ENDFUNCTION
` Same as 'SetRaceProbs' but for Profession.
FUNCTION SetProfProbs(_prof$)
XML GET CHILD ELEMENT xml_prof, _prof$, xml_work
FOR i=1 TO 11
hero_prob#(2, i) = XML GET FLOAT ATTRIBUTE(xml_work, attrib$(i))
NEXT
ENDFUNCTION
With Computers you can solve Problems that you have never befor.
My English is so BAD ;(