public override void WriteStartElement(string prefix, string localName, string ns) { CheckContentStart(); //Is it exsl:document redirecting instruction? if (ns == RedirectNamespace && localName == RedirectElementName) { //Lazy stack of states if (_states == null) { _states = new Stack(); } //If we are redirecting already - push the current state into the stack if (_redirectState == RedirectState.Redirecting) { _states.Push(_state); } //Initialize new state _state = new OutputState(); _redirectState = RedirectState.WritingRedirectElementAttrs; } else { if (_redirectState == RedirectState.Redirecting) { if (_state.Method == OutputMethod.Text) { _state.Depth++; return; } //Write doctype before the first element if (_state.Depth == 0 && _state.SystemDoctype != null) { if (prefix != String.Empty) { _state.XmlWriter.WriteDocType(prefix + ":" + localName, _state.PublicDoctype, _state.SystemDoctype, null); } else { _state.XmlWriter.WriteDocType(localName, _state.PublicDoctype, _state.SystemDoctype, null); } } _state.XmlWriter.WriteStartElement(prefix, localName, ns); _state.Depth++; } else { base.WriteStartElement(prefix, localName, ns); } } }
internal void FinishRedirecting() { _state.CloseWriter(); //Pop previous state if it exists if (_states.Count != 0) { _state = (OutputState)_states.Pop(); _redirectState = RedirectState.Redirecting; } else { _state = null; _redirectState = RedirectState.Relaying; } }