python mini.dom question
Learning to program and I'm hitting some road blocks. Having trouble looking up an answer due to not knowing what the thing I'm looking for is called.
I'm using mini.dom to read an xml config file and I want to search for a tag name and write the "position id" to a variable. not sure what the position id is really called... getElementsByTagName('tag')[0] <--- that 0 which means it was found first would be a 1 if found 2nd What is the proper name of this and how could I do something like this Code:
for element in node.getElementsByTagName('sometag'): |
It would probably help if you gave an example of the xml (or at least a sample that would explain your problem).
Looking at the code you gave var = element.firstChild.data shoudl be sufficient but I'm prepared to accept that in a more complex scenario that might not answer your needs. Another approach if you need the index, then add a counter outside of the loop, initialised to 0, and increment by 1 at the end of the loop. Often it is possible to avoid such looping by using xpath (and the functions) |
Index is what that number is called? I tried googling "mini.dom index" but didn't turn up with anything. So is there a function to grab the index for a search result?
Here is an example of how the xml might look. Code:
<stuff>. |
using xpath you can get the two nodes (using your example) as follows:
Code:
//path[@pathversion='1'] and to get the category tag use this xpath Code:
//path[@pathversion='1']//../sometag |
Great I'll play with this for a while. Thanks for pointing me in the right direction.
|
All times are GMT -5. The time now is 02:27 AM. |