Problem with MusicXML -> Class

Apr 24, 2012 at 6:49 PM

Here is the schema doc : http://www.oxygenxml.com/samples/xml-schema-documentation/MusicXML-Schema/musicxml.html

The problem is, when I use Xsd2Code command-line to make the classes, get an error message about bad casting.

Type of choice identifier 'ItemsElementName' is inconsistent with type of 'Items'. Please use array of System.Collections.Generic.List`1[[MyApp.musicxml30.ItemsChoiceType, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].

Google ( http://goo.gl/Ecjan ) tells me that I gotta change some of the entries from List() to object[], but I'm still getting the cast message and I was hoping that I wouldn't have to continuously go into the generated code to fix it.

Apr 24, 2012 at 7:15 PM
Edited Apr 24, 2012 at 7:20 PM

namespace MyApp {
    public partial class frmMain : Form {
        public frmMain() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            try {

                var fs = new FileStream(@"C:\dev\test.xml", FileMode.Create);
                var s = new XmlSerializer(typeof(scorepartwise));

                var spw = new scorepartwise();
                spw.part.Add(new scorepartwisePart() {
                    id = "P1"
                });

                var m = new scorepartwisePartMeasure() {
                    number = "1"
                };

                m.Items.Add(new note() {
                    Items = new List<object>() {
                        new pitch() {
                            alter = 0,
                            octave = "4",
                            step = step.A
                        },
                        new pitch() {
                            alter = 0,
                            octave = "4",
                            step = step.A
                        },
                        4
                    },
                    ItemsElementName = new List<ItemsChoiceType1>() {
                        ItemsChoiceType1.pitch,
                        ItemsChoiceType1.pitch,
                        ItemsChoiceType1.duration
                    }
                });

                spw.part[0].measure.Add(m);
                spw.partlist.Items.Add(new scorepart() {
                    id = spw.part[0].id
                });


                s.Serialize(fs, spw);
                fs.Flush();
                fs.Close();

            } catch (Exception) {

                throw;
            }
        }