@PuG: If i am not mistaken you can do a replace like
line = line.replace("<polygons>","<triangles> <p>").
Test for the triangle tag and replace it with
line = line.replace("</polygons>", "</p> </triangles>")
Code:
f = open("collada_refined.dae", "w")
print "Please wait.."
for line in open("collada.dae"):
line = line.replace("Z_UP", "Y_UP")
line = line.replace("<polygons>","<triangles> <p>")
line = line.replace("<p>", "")
line = line.replace("</p>", "")
line = line.replace("</polygons>", "</p> </triangles>")
f.write(line)
f.close()
print "Collada Refined."
If this has to be changed allot of times, it may be a good idea to simply use a replacement set. Something along the lines of:
Code:
# define our method
def replace_all(file, dic):
for i, j in dic.iteritems():
file = file.replace(i, j)
return file
# Replacement Set
repset = {'Z_UP':'Y_UP','<polygons>':'<triangles><p>','<p>':'', '</p>':'', '</polygons>':'</p></triangles>'}
# Call it
replace_all(my_file, repset)
Not tested!
If we need to replace a new set it's easy to simply create a new dictionary and run it. More advanced solutions can be used with regular expressions.
@Swiftcoder: I have not read the Collada spec in detail. Does the spec define the correct behavior? or is it left for the implementer? On standardization topics, following the spec is important, let's follow it and if others do not respect it then we have to correct their mistakes and hope that they will fix their exporters to be standard compliant.