Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-16"?>
- <ChordType name="C Minor" priority="Important">
- <description>C minor</description>
- <abbreviations>
- <abbr category="General">m</abbr>
- <abbr category="Jazz">-</abbr>
- <abbr category="Full">min</abbr>
- </abbreviations>
- <intervals>
- <interval quality="Perfect" number="Unison" />
- <interval quality="Minor" number="Third" />
- <interval quality="Perfect" number="Fifth" />
- </intervals>
- </ChordType>
- public void ReadXml(XmlReader reader)
- {
- _Name = reader.GetAttribute("name");
- _Priority = (ChordTypePriority)Enum.Parse(typeof(ChordTypePriority), reader.GetAttribute("priority"));
- if (reader.ReadToFollowing("description"))
- _Description = reader.ReadElementContentAsString();
- if (reader.Name != "abbreviations")
- throw new InvalidOperationException("Abbreviations element missing.");
- if (!reader.ReadToDescendant("abbr"))
- throw new InvalidOperationException("At least one abbreviation element is required.");
- var abbreviations = new List<ChordTypeAbbreviation>();
- do
- {
- var abbr = new ChordTypeAbbreviation(
- category: reader.GetAttribute("category"),
- abbreviation: reader.ReadElementContentAsString()
- );
- abbreviations.Add(abbr);
- } while (reader.ReadToNextSibling("abbr"));
- _Abbreviations = abbreviations.ToArray();
- if (!reader.ReadToFollowing("intervals"))
- //here's where the code fails
- throw new InvalidOperationException("Intervals element missing.");
- var intervals = new List<Interval>();
- do
- {
- var interval = new Interval(reader.GetAttribute("quality"), reader.GetAttribute("number"));
- intervals.Add(interval);
- } while (reader.ReadToNextSibling("interval"));
- _Intervals = intervals.ToArray();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement