I load MusicXML files into my program. Problem: There are two “dialects”, temporary and separated, that have different root nodes (and a different structure):
<?xml version="1.0" encoding='UTF-8' standalone='no' ?> <!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 2.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd"> <score-partwise version="2.0"> <work>...</work> ... </score-partwise>
and
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE score-timewise PUBLIC "-//Recordare//DTD MusicXML 2.0 Timewise//EN" "http://www.musicxml.org/dtds/timewise.dtd"> <score-timewise version="2.0"> <work>...</work> ... </score-timewise>
My code for deserializing a partial score so far is:
using (var fileStream = new FileStream(openFileDialog.FileName, FileMode.Open)) { var xmlSerializer = new XmlSerializer(typeof(ScorePartwise)); var result = (ScorePartwise)xmlSerializer.Deserialize(fileStream); }
What would be the best way to distinguish between two dialects?
source share