private Reviewer reviewerParser(XmlNodeReader reader) { Reviewer r = new Reviewer(reader.GetAttribute("id")); reader.Read(); reader.Read(); r.setName(reader.Value); reader.Read(); reader.Read(); //name - end tag if (reader.NodeType == XmlNodeType.EndElement) return r; reader.Read(); r.setCompany(reader.Value); return r; }
public void writeXML(Band[] bands, Reviewer[] reviewers) { if (!File.Exists(filePath)) using(File.Create(filePath)); using (XmlWriter writer = XmlWriter.Create(filePath)) { writer.WriteStartDocument(); // start document writer.WriteStartElement("root", "http://www.w3.org/2001/XMLSchema-instance"); //start root foreach (Band b in bands) { writer.WriteStartElement("band"); // start band writer.WriteAttributeString("name", b.getName()); writer.WriteAttributeString("size", b.getSize()); foreach (Member m in b.getMembers()) { writer.WriteStartElement("member"); //start member writer.WriteAttributeString("name", m.getName()); writer.WriteAttributeString("instrument", m.getInstrument()); writer.WriteElementString("join-date", m.getJoinDate()); writer.WriteEndElement(); // end memeber } foreach (Album a in b.getAlbums()) { writer.WriteStartElement("album"); //start album writer.WriteAttributeString("name", a.getName()); foreach (Song s in a.getSongs()) { writer.WriteStartElement("song"); //start song writer.WriteElementString("name", s.getName()); writer.WriteElementString("tracklength", s.getlength()); writer.WriteEndElement(); //end song } foreach (Review r in a.getReviews()) { writer.WriteStartElement("reviewer"); // start review writer.WriteAttributeString("ref", r.getReviewerId()); writer.WriteString(r.getReview()); writer.WriteEndElement(); // end review } writer.WriteEndElement(); // end album } if (b.getShows().Length > 0) { writer.WriteStartElement("show"); foreach (Show s in b.getShows()) { writer.WriteElementString("date", s.getDate()); writer.WriteElementString("venue", s.getVenue()); } writer.WriteEndElement(); //end show } writer.WriteEndElement(); //end band } foreach (Reviewer r in reviewers) { writer.WriteStartElement("reviewer"); // start reviewer writer.WriteAttributeString("id", r.getId()); if (r.getName().Length > 0) writer.WriteElementString("name", r.getName()); if (r.getCompany().Length > 0) writer.WriteElementString("company", r.getCompany()); writer.WriteEndElement(); //end reviewer } writer.WriteEndElement(); //end root writer.WriteEndDocument(); //end document } }