Jump to content

XML


Arsilex

Recommended Posts

Posted

Hello guys i have this code:

local metaXML = xmlLoadFile(":"..path.."/meta.xml") 
    if metaXML then 
        for i, m in ipairs(xmlNodeGetChildren(metaXML)) do   
            local metaXMLName = xmlNodeGetName(m) 

but i have this error:

50346dd371f861db53a9e2899426a468.png

i'm sure that the "m" argument is a node-xml element.

Posted

Try using debugOutputString on metaXML and make,

xmlNodeGetChildren(metaXML) 

a seperate variable.

local metaXML = xmlLoadFile(":"..path.."/meta.xml") 
outputDebugString(tostring(metaXML)) 
    if (metaXML) then 
    local metaChildern = xmlNodeGetChildren(metaXML) 
    outputDebugString(tostring(metaChildern)) 
        for i, m in ipairs(metaChildern) do  
            local metaXMLName = xmlNodeGetName(m) 
  

Then tell me what's in your /debugscript 3

regards viruz

Posted

It returns a table of children, make a new for loop to loop through them. A table is not an XML Node.

local metaXML = xmlLoadFile(":"..path.."/meta.xml") 
if (metaXML) then 
local metaChildern = xmlNodeGetChildren(metaXML) 
    for i, m in ipairs(metaChildern) do 
        for k, v in ipairs(m) do 
            outputDebugString(tostring(xmlNodeGetName(v))) 
        end 
    end 
end 

Posted

67053eda2f3d9424ecd3309714547d5e

for i, m in ipairs(metaChildern) do

m return a node. if you dont see the outputDebugString is under

local metaChildern = xmlNodeGetChildren(metaXML)

so this need to return table if i will put the outputDebugString into a loop i will get a node and i get it but the script make a error.

Posted

i try to do this:

for i, m in ipairs(metaChildern) do 
            outputChatBox(tostring(xmlNodeGetName(m))) 

and i have this:

info 
false 
false 
false 
false 
false 

Posted

This script need to get the information from the meta.xml like script linked to they and download all that after whit loader load the code from .lua

Posted

Well, I suppose you've changed the meta.xml file you're trying to read since the first post - so I'll rather give you a working example based on a sample meta file.

 <meta> 
    <file src="song.mp3" /> 
    <script src="client.lua" type="client" /> 
    <info gamemodes="race" type="map" name="Example" /> 
    <map src="example.map" dimension="0" /> 
    <settings> 
        <setting name="#respawn" value='[ "none" ]' /> 
    </settings> 
</meta> 

local meta = xmlLoadFile(":"..resource.."/meta.xml") 
local nodes = xmlNodeGetChildren(meta) 
local files = {} 
local _settings = {} 
for i,v in ipairs(nodes) do 
    local attributes = xmlNodeGetAttributes(v) 
    local type = xmlNodeGetName(v) 
    if type == "file" then 
        table.insert(files, attributes.src) -- song.mp3 / any file 
    elseif type == "settings" then 
        local settings = xmlNodeGetChildren(v) -- As settings in this case contains sub-nodes, we retrieve and loop over them 
        for i,v in ipairs(settings) do 
            local attributes = xmlNodeGetAttributes(v) 
            if attributes.name == "#respawn" then 
                table.insert(_settings, {attributes.name, attributes.value}) -- #respawn, [ "none" ] / any node's attributes inside "settings" 
            end 
        end 
    end 
end 

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