Drakath Posted March 14, 2014 Posted March 14, 2014 Is it possible to xmlDestroyNode if I know the tagName and its value but no index?
JR10 Posted March 14, 2014 Posted March 14, 2014 How about xmlFindChild? Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Vector Posted March 14, 2014 Posted March 14, 2014 -- iterate over all the xml nodes and find those whose value and tag name matches... local children = xmlNodeGetChildren(root); for _, child in ipairs(children) do if (xmlNodeGetName(child) == tagName) and (xmlNodeGetValue(child) == someValue) then xmlDestroyNode(child); end; end; there are two kinds of people: those who know C++ and those who don´t. .)
JR10 Posted March 14, 2014 Posted March 14, 2014 That requires to define index. index: This is the 0-based index of the node you wish to find. For example, to find the 5th subnode with a particular name, you would use 4 as the index value. To find the first occurence, use 0. This is a different index than what you mean. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Drakath Posted March 14, 2014 Author Posted March 14, 2014 Well it only returns the first line. While for the Vector's code, I tried this: local xmlFile = xmlLoadFile("blocks.xml") local children = xmlNodeGetChildren(xmlFile) outputChatBox(playername) for _, child in ipairs(children) do outputChatBox(xmlNodeGetValue(child)) if (xmlNodeGetValue(child) == playername) then xmlDestroyNode(child) outputChatBox("deleted") playername outputted correctly but xmlNodeGetValue(child) outputted nil. Why?
JR10 Posted March 14, 2014 Posted March 14, 2014 Post the xml file. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Drakath Posted March 14, 2014 Author Posted March 14, 2014 <blocked> <blocked blocked="Drakath"></blocked> <blocked blocked="player"></blocked> <blocked blocked="lol"></blocked> <blocked blocked="user"></blocked> </blocked>
JR10 Posted March 14, 2014 Posted March 14, 2014 xmlNodeGetValue will return 'Drakath' if: <blocked>Drakath</blocked> Use xmlNodeGetAttribute(child, 'blocked') Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Drakath Posted March 14, 2014 Author Posted March 14, 2014 It worked but seems like xmlDestroyNode(child) doesn't do anything. It didn't delete anything from blocks.xml
JR10 Posted March 14, 2014 Posted March 14, 2014 You need xmlSaveFile and xmlUnloadFile at the end of the script. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
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