I'm trying to extract a list of X,Y,Z from xml file. A part of xml is:
<Data>
<TargetPosition X="57.23471787820652" Y="-26.04271457691532"
Z="9.988092935592704" Valid="1"/> #PosLang
<StartPosition X="0" Y="0" Z="0" Valid="0"/>
</Data>
</Object>
<Object Type="{aa99a9ec-4b85-442e-b914-de3579656eb5}">
<ParentTObject Valid="1">
<Translation X="0" Y="0" Z="0"/>
<Rotation W="1" X="0" Y="0" Z="0"/>
</ParentTObject>
<Data>
<TargetPosition X="58.81901290773406" Y="-20.09883392050945"
Z="16.53197054898237" Valid="1"/> #NegLang
<StartPosition X="0" Y="0" Z="0" Valid="0"/>
</Data>
</Object>
I need to extract X,Y,Z from all TargetPosition in file that have #PosLang comment
def targets(path='some.xml'):
try:
e = ET.parse(path).getroot()
except FileNotFoundError:
return list()
Position = namedtuple('float', ['x', 'y', 'z'])
for position in e.iter('TargetPosition'):
yield Position(
x=float(position.get('X')),
y=float(position.get('Y')),
z=float(position.get('Z'))
)
In y code i extract X,Y,Z of all TargetPosition, but i need only that have #PosLang comment
#and XML comments.