콘텐츠로 이동
Search

Musicxml-schemas

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

다음과 같은 에러가 뜬다면...

does not exist in the namespace System.ComponentModel

nuget으로 다음 패키지를 추가한다.

dotnet add package System.ComponentModel.Annotations

Favorite site

lastmod 2021-03-07created 2021-03-07author Zer0 sitemap