Musicxml-schemas
MusicXML 2.0, 3.0, 3.1 XSD to C# autogenerated schemas with some documentation and pascal-cased names.
Categories
- MusicXML
- XmlSchemaClassGenerator (Dependency)
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
다음과 같은 에러가 뜬다면...
nuget으로 다음 패키지를 추가한다.