Jump to content

Reading XML


robhol

Recommended Posts

Okay, i have an XML config file that looks like this:

<gpconf> 
    <locations> 
        <gploc x="0" y="0" z="0" clue="This is clue 1" /> 
        <gploc x="1" y="1" z="1" clue="This is clue 2" /> 
    </locations> 
    <gptime beforestart="2" duration="5" beforenext="5" /> 
    <gpcash minimumcash = "50000" maximumcash = "99999" /> 
</gpconf> 

The meaning is that all the attrbs in the gptime and gpcash nodes should end up in their own var, and that I should be able to choose ONE gploc at random. Can anybody help me with this? Is there a way to know how many subnodes of a specific type there is inside a node? How would i "get amount" of gplocs in ?

Can anybody help me with this?

Link to comment

To count child nodes use xmlFindSubNode() with an increasing index. Once this function returns false, you've found all your subnodes i.e. start with index 0 and keep calling this function with 0,1,2,3 ... etc. until it fails.

Link to comment

hm... i just recognized that tma and norby already answered while writing this post but anyway here's an example:

node = true 
index = 0 
  
function count () 
    while node ~= false do  
        node = xmlFindSubNode (xml, "gploc", index) 
        index = index + 1 
    end 
    outputChatBox ("There are "..tostring(index).." subnodes") 
end --note that you'll have to set node = true and index = 0 if you want to call the function again 

Maybe there are easier ways to do this but thats how i got it working ;)

Edited by Guest
Link to comment
  • 4 weeks later...
Spatial data (i.e. locations) should be stored in .map files so that they can be edited using a map editor.

Maybe you have forgeted it, the map editor is not availible. So why specially in .map files, i store all my positions in an table. Tables are faster then loading from a xml files (inclusive .map files)

And i don't use the map editor for example spawn positions, vehicle's, moving objects, objects hell eveything.

Why not:

You can't use the objects and can't do something with them, you can't set in a map file in what dimision the object will be or the pickup. You CAN'T do that. (for my knows)

So you can better store it in a costum xml file, and you can load it and put them directly in the dimision you want!

Or just build them in to an table (tables are faster then loading from xml, put the xml data into an array). Even loading from an xml uses much memory usage!

Link to comment

XML is versatile, all the things you told actually ARE possible...

Read this topic: http://development.mtasa.com/index.php? ... lementByID

Dimension can be set with normal scripting functions and the help of the link above.

About the custom XML, I quite agree because you can put in any argument you want. But it actually also is possible with a normal .map file.

And what's the problem with that? In the resourcestart you just load all of the XML data and store it in tables.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...