de-men / music_xml

A Dart package project to parse MusicXML.
https://pub.dev/packages/music_xml
BSD 3-Clause "New" or "Revised" License
7 stars 6 forks source link

List of score-part always One #7

Closed synchronisator closed 1 year ago

synchronisator commented 1 year ago

The parser for score-parts is always 1 because the filter is not working like it should.

lib/src/music_xml_document.dart:36

score
        .findAllElements('part-list')
        .where((element) => element.getElement('score-part') != null)
        .map((element) => element.getElement('score-part')!)
        .map((element) => ScorePart.parse(element))
        .forEach((element) => scoreParts[element.id] = element);

The tag 'part-list' only appears one-time in the xml and contains a list of score-part. I changed the Code to this: and it worked:

score
        .findAllElements('part-list').first
        .findAllElements('score-part')
        .map(ScorePart.parse)
        .forEach((ScorePart element) => scoreParts[element.id] = element);

Because the part-list is marked as "required" in the decumentation the call of "first" should be save. But it could lead to an exception with a bad xml file.

thaihuynhxyz commented 1 year ago

fixed at #9