I am working a lot with MusicXML files and am trying to compile a list of the bars in which there are key changes in a number of pieces. I am in need of some help using python to first identify where the <key>
tags occur in the XML file, and then extracting the number from the <measure number ='*'>
tag above. Here is an example of a measure I am working with:
<measure number='30' implicit='yes'>
<print new-page='yes'/>
<barline location='left'>
<bar-style>heavy-light</bar-style>
<repeat direction='forward'/>
</barline>
<attributes>
<key>
<fifths>-1</fifths>
<mode>major</mode>
</key>
</attributes>
<direction>
<direction-type>
<dynamics default-y='-82'>
<p/>
</dynamics>
</direction-type>
<staff>1</staff>
</direction>
<direction>
<direction-type>
<words default-y='15' relative-x='4'>
</direction-type>
<staff>1</staff>
</direction>
<note>
<pitch>
<step>F</step>
<octave>5</octave>
</pitch>
<duration>768</duration>
<voice>1</voice>
<type>quarter</type>
<stem>down</stem>
<staff>1</staff>
<notations>
<ornaments>
<trill-mark default-y='20'/>
<wavy-line type='start' number='1'/>
<wavy-line type='stop' number='1'/>
</ornaments>
</notations>
</note>
</measure>
How can I extract the '30'
bit? Is there a quick and easy way to do this with music21?