/// <summary> /// Replay all cached events to an XmlWriter. /// </summary> public void EventsToWriter(XmlWriter writer) { XmlEvent[] page; int idxPage, idxEvent; byte[] bytes; char[] chars; XmlRawWriter rawWriter; // Special-case single text node at the top-level if (_singleText.Length != 0) { writer.WriteString(_singleText.ToString()); return; } rawWriter = writer as XmlRawWriter; // Loop over set of pages for (idxPage = 0; idxPage < _pages.Count; idxPage++) { page = _pages[idxPage]; // Loop over events in each page for (idxEvent = 0; idxEvent < page.Length; idxEvent++) { switch (page[idxEvent].EventType) { case XmlEventType.Unknown: // No more events Debug.Assert(idxPage + 1 == _pages.Count); return; case XmlEventType.DocType: writer.WriteDocType(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3, (string)page[idxEvent].Object); break; case XmlEventType.StartElem: writer.WriteStartElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3); break; case XmlEventType.StartAttr: writer.WriteStartAttribute(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3); break; case XmlEventType.EndAttr: writer.WriteEndAttribute(); break; case XmlEventType.CData: writer.WriteCData(page[idxEvent].String1); break; case XmlEventType.Comment: writer.WriteComment(page[idxEvent].String1); break; case XmlEventType.PI: writer.WriteProcessingInstruction(page[idxEvent].String1, page[idxEvent].String2); break; case XmlEventType.Whitespace: writer.WriteWhitespace(page[idxEvent].String1); break; case XmlEventType.String: writer.WriteString(page[idxEvent].String1); break; case XmlEventType.Raw: writer.WriteRaw(page[idxEvent].String1); break; case XmlEventType.EntRef: writer.WriteEntityRef(page[idxEvent].String1); break; case XmlEventType.CharEnt: writer.WriteCharEntity((char)page[idxEvent].Object); break; case XmlEventType.SurrCharEnt: chars = (char[])page[idxEvent].Object; writer.WriteSurrogateCharEntity(chars[0], chars[1]); break; case XmlEventType.Base64: bytes = (byte[])page[idxEvent].Object; writer.WriteBase64(bytes, 0, bytes.Length); break; case XmlEventType.BinHex: bytes = (byte[])page[idxEvent].Object; writer.WriteBinHex(bytes, 0, bytes.Length); break; case XmlEventType.XmlDecl1: if (rawWriter != null) { rawWriter.WriteXmlDeclaration((XmlStandalone)page[idxEvent].Object); } break; case XmlEventType.XmlDecl2: if (rawWriter != null) { rawWriter.WriteXmlDeclaration(page[idxEvent].String1); } break; case XmlEventType.StartContent: if (rawWriter != null) { rawWriter.StartElementContent(); } break; case XmlEventType.EndElem: if (rawWriter != null) { rawWriter.WriteEndElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3); } else { writer.WriteEndElement(); } break; case XmlEventType.FullEndElem: if (rawWriter != null) { rawWriter.WriteFullEndElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3); } else { writer.WriteFullEndElement(); } break; case XmlEventType.Nmsp: if (rawWriter != null) { rawWriter.WriteNamespaceDeclaration(page[idxEvent].String1, page[idxEvent].String2); } else { writer.WriteAttributeString("xmlns", page[idxEvent].String1, XmlReservedNs.NsXmlNs, page[idxEvent].String2); } break; case XmlEventType.EndBase64: if (rawWriter != null) { rawWriter.WriteEndBase64(); } break; case XmlEventType.Close: writer.Close(); break; case XmlEventType.Flush: writer.Flush(); break; case XmlEventType.Dispose: ((IDisposable)writer).Dispose(); break; default: Debug.Assert(false, "Unknown event: " + page[idxEvent].EventType); break; } } } Debug.Assert(false, "Unknown event should be added to end of event sequence."); }
// Saves the node to the specified XmlWriter. public override void WriteTo(XmlWriter w) { w.WriteStartAttribute(Prefix, LocalName, NamespaceURI); WriteContentTo(w); w.WriteEndAttribute(); }
public override void WriteStartAttribute(string prefix, string localName, string ns) { writer.WriteStartAttribute(prefix, localName, ns); }