Skip to content
Search

Musicxml-schemas

lastmod 2021-03-07created 2020-11-103 edits

MusicXML 2.0, 3.0, 3.1 XSD to C# autogenerated schemas with some documentation and pascal-cased names.

Categories

Example

using System;
using System.Xml.Serialization;
using System.IO;

namespace ExampleProgram
{
    static class Program
    {
        static void Main()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(MusicXmlSchema.ScorePartwise));

            // Uncompress the MusicXML file if it ends with a .mxl before passing it in
            string filename = "scherzo-no-2-opus-31.xml";

            // Your fully typed score
            var score = serializer.Deserialize(new FileStream(filename, FileMode.Open)) as MusicXmlSchema.ScorePartwise;

            Console.WriteLine(score.Credit[0].CreditWords.Value);
            // Output: Scherzo No. 2 in B♭ Minor
            Console.WriteLine(score.Part[0].Measure[0].Note[0].Pitch.Step);
            // Output: B

            Console.ReadKey();
        }
    }
}

MemoryStream example

var xmlBytes = GetAirplaneXml();
XmlSerializer serializer = new XmlSerializer(typeof(MusicXmlSchema.ScorePartwise));
using (var xmlStream = new MemoryStream(xmlBytes))
{
    var score = serializer.Deserialize(xmlStream) as MusicXmlSchema.ScorePartwise;
}

Troubleshooting

does not exist in the namespace System.ComponentModel

If you get the following error...

does not exist in the namespace System.ComponentModel

Add the following package with nuget.

dotnet add package System.ComponentModel.Annotations

Favorite site

author Zer0 sitemap