Jump to content

yet another xml question (has child nodes?)


churchill

Recommended Posts

I know DP3 has functionality to return the child nodes of a given node, but I need a DP2 solution to checking whether a node has children or not. e.g. would xmlFindSubNode(node, "",0) return the first node that it came across regardless of what it was called? :)

Otherwise it means me re-working some code so that all the nodes are named something like "data" and then have the key as an attribute instead of the tag name, e.g instead of:

<data> 
     <someKey>value</someKey> 
</data> 

it would have to become:

<lotsOfData> 
     <data key="someKey">value</data> 
</lotsOfData> 

Which would make the script slower in other places, as I could no longer find the right node value simply using:

node = xmlFindSubNode(someXMLfile, "someKey", 0) 
if (node ~= false) then 
     nodevalue = xmlNodeGetValue(node) 
end 
  

I would have to do this instead, which will be a lot slower when using lots of data:

node = findNode(someXMLfile, "someKey") 
if (node ~= false) then 
     nodevalue = xmlNodeGetValue(node) 
end 
  
function findNode(parentnode, key) 
     i = 0 
     node = xmlFindSubNode(parentnode, "data", i) 
     while (node ~= false) do 
          nodeKey = xmlNodeGetAttribute(node, "key") 
          if (nodeKey == key) then 
               return node 
          end 
          i = i + 1 
          node = xmlFindSubNode (parentnode, "data", i) 
     end 
     return false 
end 

Link to comment

if your removing the child like we talked on msn, why dont you replace it with something else, then on a timer every 10 mins do a check through the file to remove anything, for instance say the xml was like this

  
<data> 
        <players name="joebloggs" status="active"/> 
</data>  
  

you could change the status to something like

  
<data> 
        <players name="joebloggs" status="remove"/> 
</data>  
  

then loop through the xml every 10 mins or so finding players with remove there and then deleate that node

i think this is what you mean, if not sorry :)

Link to comment

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