TheIceman1 Posted April 10, 2013 Share 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"> Link to comment
DiSaMe Posted April 10, 2013 Share Posted April 10, 2013 The root node of XML file is the one which xmlLoadFile returns. Link to comment
TheIceman1 Posted April 10, 2013 Author Share Posted April 10, 2013 The root node of XML file is the one which xmlLoadFile returns. I dont understand Link to comment
TheIceman1 Posted April 10, 2013 Author Share Posted April 10, 2013 Nobody will help me? Link to comment
DiSaMe Posted April 10, 2013 Share 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. Link to comment
TheIceman1 Posted April 10, 2013 Author Share 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... Link to comment
فاّرس Posted April 10, 2013 Share Posted April 10, 2013 Do not make file ! use xmlCreateFile to make file... Link to comment
TheIceman1 Posted April 10, 2013 Author Share Posted April 10, 2013 But i want delete only this: "FBI"> in this: "FBI"> Link to comment
50p Posted April 10, 2013 Share 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. Link to comment
TheIceman1 Posted April 10, 2013 Author Share 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 ) Link to comment
Castillo Posted April 10, 2013 Share Posted April 10, 2013 Any errors on debugscript? Link to comment
DakiLLa Posted April 11, 2013 Share 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. Link to comment
TheIceman1 Posted April 11, 2013 Author Share 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! 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