/// <summary> /// Writes the XML representation of the node to an XmlWriter /// </summary> /// <param name="writer"></param> public void WriteTo(System.Xml.XmlWriter writer) { writer.WriteStartElement(this.Name); foreach (string name in this.Attributes.Keys) { writer.WriteAttributeString(name, Attributes[name]); } if (this.TextContent != null) { writer.WriteChars(this.TextContent.ToCharArray(), 0, this.TextContent.Length); } foreach (XmlNode node in this.ChildNodes) { node.WriteTo(writer); } writer.WriteEndElement(); }
void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer) { // This is the chunking code. // ASP.NET buffering must be turned off for this to work. int bufferSize = 4096; char[] songBytes = new char[bufferSize]; FileStream inFile = File.Open(this.filePath, FileMode.Open, FileAccess.Read); long length = inFile.Length; // Write the file name. writer.WriteElementString("fileName", ns, Path.GetFileNameWithoutExtension(this.filePath)); // Write the size. writer.WriteElementString("size", ns, length.ToString()); // Write the song bytes. writer.WriteStartElement("song", ns); StreamReader sr = new StreamReader(inFile, true); int readLen = sr.Read(songBytes, 0, bufferSize); while (readLen > 0) { writer.WriteStartElement("chunk", ns); writer.WriteChars(songBytes, 0, readLen); writer.WriteEndElement(); writer.Flush(); readLen = sr.Read(songBytes, 0, bufferSize); } writer.WriteEndElement(); inFile.Close(); }