You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi I want to use Python to delete the specific tag in a xml file. Here is for example what I want to delete: <edge id="-28029380" from="444363583" to="307773297" priority="21" type="railway.highspeed" spreadType="center" shape="30808.38,22280.38 30815.34,22079.71 30818.81,21993.54 30825.20,21825.23 30834.10,21591.29 30834.28,21586.33" bidi="28029380" distance="58689.58"> <lane id="-28029380_0" index="0" allow="rail_fast" speed="55.56" length="691.54" shape="30808.43,22278.88 30815.34,22079.71 30818.81,21993.54 30825.20,21825.23 30834.10,21591.29 30834.23,21587.82"/> </edge>
and here is the python code:
`#!usr/bin/python
-- coding: utf-8 --
import xml.etree.ElementTree as ET
tree = ET.parse(r'C:\Users\zzj\Desktop\test\test.xml')
root = tree.getroot()
animNode = root.find('edge')
if animNode.attrib['type'] == 'railway.highspeed':
root.remove(animNode)
tree.write(r'C:\Users\zzj\Desktop\test\finish.xml')`
then I get the error of FileNotFoundError: [Errno 2] No such file or directory. I tried many time but the path doesn't work, could somebody help?
many thanks!
The text was updated successfully, but these errors were encountered:
Hi I want to use Python to delete the specific tag in a xml file.
Here is for example what I want to delete: <edge id="-28029380" from="444363583" to="307773297" priority="21" type="railway.highspeed" spreadType="center" shape="30808.38,22280.38 30815.34,22079.71 30818.81,21993.54 30825.20,21825.23 30834.10,21591.29 30834.28,21586.33" bidi="28029380" distance="58689.58"> <lane id="-28029380_0" index="0" allow="rail_fast" speed="55.56" length="691.54" shape="30808.43,22278.88 30815.34,22079.71 30818.81,21993.54 30825.20,21825.23 30834.10,21591.29 30834.23,21587.82"/> </edge>
and here is the python code:
`#!usr/bin/python
-- coding: utf-8 --
import xml.etree.ElementTree as ET
tree = ET.parse(r'C:\Users\zzj\Desktop\test\test.xml')
root = tree.getroot()
animNode = root.find('edge')
if animNode.attrib['type'] == 'railway.highspeed':
root.remove(animNode)
tree.write(r'C:\Users\zzj\Desktop\test\finish.xml')`
then I get the error of FileNotFoundError: [Errno 2] No such file or directory. I tried many time but the path doesn't work, could somebody help?
many thanks!
The text was updated successfully, but these errors were encountered: