TheIceman1 Posted April 10, 2013 Posted April 10, 2013 Why this dont delete clan from "clans.xml"? function destroyclan () local clan = getElementData ( source, "clan" ) removeElementData ( source, "clan" ) local clans = xmlLoadFile ("clans.xml") local clansroot = xmlFindChild (clans,"clans",0) if ( clansroot ) then for i,v in ipairs (xmlNodeGetChildren(clansroot)) do local xmlnumber = xmlNodeGetAttribute (v,"clan") xmlDestroyNode ( v ) xmlSaveFile ( clans ) xmlUnloadFile ( clans ) end end end addEvent ( "destroyclan", true ) addEventHandler ( "destroyclan", root, destroyclan ) XML "FBI"> Need paid scripter just pm me i will accept every job!
DiSaMe Posted April 10, 2013 Posted April 10, 2013 The root node of XML file is the one which xmlLoadFile returns. -
TheIceman1 Posted April 10, 2013 Author Posted April 10, 2013 The root node of XML file is the one which xmlLoadFile returns. I dont understand Need paid scripter just pm me i will accept every job!
TheIceman1 Posted April 10, 2013 Author Posted April 10, 2013 Nobody will help me? Need paid scripter just pm me i will accept every job!
DiSaMe Posted April 10, 2013 Posted April 10, 2013 You're trying to delete the children of this node: clan="FBI">> Since it contains no children, nothing is deleted. It happens this way because xmlFileLoad returns this node: >...> And then you're getting its first child (FBI clan) as 'clansroot', then looping through its children (which don't exist, therefore nothing is removed). You're supposed to loop through the children of 'clans' instead. In addition, you're saving and unloading the XML file inside the loop - that's wrong. You should do this after the loop. If you unload the file inside the loop, it won't be available for the next iteration, causing an error. Saving the file repeatedly will have no effect on the result, but doing so will needlessly reduce the performance. -
TheIceman1 Posted April 10, 2013 Author Posted April 10, 2013 You're trying to delete the children of this node: clan="FBI">> Since it contains no children, nothing is deleted. It happens this way because xmlFileLoad returns this node: >...> And then you're getting its first child (FBI clan) as 'clansroot', then looping through its children (which don't exist, therefore nothing is removed). You're supposed to loop through the children of 'clans' instead. In addition, you're saving and unloading the XML file inside the loop - that's wrong. You should do this after the loop. If you unload the file inside the loop, it won't be available for the next iteration, causing an error. Saving the file repeatedly will have no effect on the result, but doing so will needlessly reduce the performance. I absolutely dont understand... Need paid scripter just pm me i will accept every job!
فاّرس Posted April 10, 2013 Posted April 10, 2013 Do not make file ! use xmlCreateFile to make file... Sha67 سابقاً
TheIceman1 Posted April 10, 2013 Author Posted April 10, 2013 But i want delete only this: "FBI"> in this: "FBI"> Need paid scripter just pm me i will accept every job!
50p Posted April 10, 2013 Posted April 10, 2013 Don't make as a child of . This is confusing. <clans> <clan name="FBI"></clan> </clans> - 1 the most important thing you do but should not do is close the file inside a loop which was opened outside the loop. Do xmlSaveFile and xmlUnloadFile after you've done your operations. - You're trying to delete all the children. - Why do you use getElementData at the 2nd line if you don't even use the returned value anywhere in the code? - Check if the clan node (a child of ) is the same name as the clan you're trying to delete/destroy. - MTA Script Editor - Ask your scripting questions properly, please. - 50p's public resources - Meta.xml - what is it for? How is it possible LOL
TheIceman1 Posted April 10, 2013 Author Posted April 10, 2013 Why this dont delete clan from "clans.xml"? function destroyclan () local clan = getElementData ( source, "clan" ) removeElementData ( source, "clan" ) local clans = xmlLoadFile ("clans.xml") local clansroot = xmlFindChild (clans,"clans",0) if (clansroot) then for i,v in ipairs (xmlNodeGetChildren(clansroot)) do local xmlnumber = xmlNodeGetAttribute (v,"name") if ( xmlnumber == clan ) then xmlDestroyNode ( v ) end xmlSaveFile ( clans ) xmlUnloadFile ( clans ) end end end addEvent ( "destroyclan", true ) addEventHandler ( "destroyclan", root, destroyclan ) Need paid scripter just pm me i will accept every job!
Castillo Posted April 10, 2013 Posted April 10, 2013 Any errors on debugscript? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
TheIceman1 Posted April 11, 2013 Author Posted April 11, 2013 No Need paid scripter just pm me i will accept every job!
DakiLLa Posted April 11, 2013 Posted April 11, 2013 xmlLoadFile already returns pointer to the root of the xml file, so you don't need to search 'clans' node again with xmlFindChild. Try to comment the 5th line and rename 'clans' variable to 'clansroot' in the 4th line and see if that helps.
TheIceman1 Posted April 11, 2013 Author Posted April 11, 2013 xmlLoadFile already returns pointer to the root of the xml file, so you don't need to search 'clans' node again with xmlFindChild. Try to comment the 5th line and rename 'clans' variable to 'clansroot' in the 4th line and see if that helps. Working,Thanks! Need paid scripter just pm me i will accept every job!
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