Arsilex Posted January 16, 2015 Share Posted January 16, 2015 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: i'm sure that the "m" argument is a node-xml element. Link to comment
ViRuZGamiing Posted January 16, 2015 Share Posted January 16, 2015 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 Link to comment
Arsilex Posted January 16, 2015 Author Share Posted January 16, 2015 There is the return of the outputDebugString: meta: userdata: 0x100ff18 xmlNodeGetChildren: table: 0x1641870 Link to comment
Dealman Posted January 17, 2015 Share Posted January 17, 2015 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 Link to comment
ViRuZGamiing Posted January 17, 2015 Share Posted January 17, 2015 Yeah my bad, dealman Link to comment
Arsilex Posted January 17, 2015 Author Share Posted January 17, 2015 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. Link to comment
Arsilex Posted January 17, 2015 Author Share Posted January 17, 2015 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 Link to comment
ViRuZGamiing Posted January 17, 2015 Share Posted January 17, 2015 so your childern from metaChildern return false, Show your XML. Link to comment
Arsilex Posted January 17, 2015 Author Share Posted January 17, 2015 <?xml version="1.0"?> type="script" version="1.0.0" author="AsuS" name="Test"/> Link to comment
ViRuZGamiing Posted January 17, 2015 Share Posted January 17, 2015 BTW, If the file is in the current resource, only the file path is necessary, e.g. xmlLoadFile("settings.xml") Link to comment
Arsilex Posted January 17, 2015 Author Share Posted January 17, 2015 yes that works if the is the same script but i used this line to read the meta.xml from another resource. Link to comment
Et-win Posted January 17, 2015 Share Posted January 17, 2015 What do you want to do with the script? Link to comment
Arsilex Posted January 17, 2015 Author Share Posted January 17, 2015 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 Link to comment
novo Posted January 17, 2015 Share Posted January 17, 2015 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 Link to comment
Et-win Posted January 18, 2015 Share Posted January 18, 2015 Well, you can just use the example on the wiki (xmlNodeGetChildren) and change 'xmlNodeGetValue' to 'xmlNodeGetName'. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now