public XQueryDocumentBuilder(XQueryDocument doc) { m_document = doc; if (doc.pagefile == null) { m_pageFile = new PageFile(false); m_pageFile.HasSchemaInfo = true; doc.pagefile = m_pageFile; } else m_pageFile = doc.pagefile; NameTable = doc.nameTable; xmlns = NameTable.Get(XmlReservedNs.NsXmlNs); _state = WriteState.Start; if (doc.input == null) { _normalize = true; hs = new HashSet<object>(); NamespaceManager = new XmlNamespaceManager(NameTable); } SchemaInfo = null; DocumentRoot = new DmRoot(); _parent = DocumentRoot; _text = null; }
public override void Close() { if (!this.closed) { this.closed = true; this.state = WriteState.Closed; this.rawWritingEnabled = false; } }
public RawXmlWriter(Stream stream) { if (stream == null) { throw new ArgumentNullException("Stream"); } this.stream = stream; this.state = WriteState.Start; }
public override void WriteEndDocument() { CloseOpenAttributeAndElements(); switch (state) { case WriteState.Start: throw new InvalidOperationException("Document has not started."); case WriteState.Prolog: throw new ArgumentException("This document does not have a root element."); } state = WriteState.Start; }
public override void WriteString(string text) { CheckState(); if (state == WriteState.Start) { throw new InvalidOperationException("Top-level content string is not allowed in this XmlDictionaryWriter"); } if (state == WriteState.Element) { CloseStartElement(); state = WriteState.Content; } if (state == WriteState.Attribute) { attr_value += text; } else if (text == null) { no_string_yet = false; is_null = true; OutputString("null"); } else { switch (element_kinds.Peek()) { case ElementType.String: if (no_string_yet) { OutputAsciiChar('"'); no_string_yet = false; } break; case ElementType.Number: case ElementType.Boolean: break; default: throw new XmlException(String.Format("Simple content string is allowed only for string, number and boolean types and not for {0} type", element_kinds.Peek())); } OutputString(EscapeStringLiteral(text)); } }
/// <summary> /// /// </summary> /// <param name="prefix"></param> /// <param name="localName"></param> /// <param name="ns"></param> public override void WriteStartElement(string prefix, string localName, string ns) { if (localName != "GED") { Console.WriteLine(WriteState); if (WriteState != WriteState.Start) { _writer.Write("\n"); } _writer.Write("{0:d} {1}", _level, localName); _level++; _writeState = WriteState.Element; } }
public override void WriteStartAttribute(string prefix, string localName, string ns) { if (this.state != WriteState.Element) { throw new InvalidOperationException("Invalid document state for attribute: " + this.state); } this.state = WriteState.Attribute; if (ns == "http://www.w3.org/2000/xmlns/") { this.ProcessNamespace((prefix != null && !(prefix == string.Empty)) ? localName : string.Empty, string.Empty); } else { this.ProcessAttribute(prefix, localName, ns, string.Empty); } }
/// <summary> /// Creates an System.Xml.XmlComment node. /// </summary> public override void WriteComment(string text) { if (state == WriteState.Attribute || state == WriteState.Element) { state = WriteState.Content; } if (state != WriteState.Content && state != WriteState.Prolog && state != WriteState.Start) { throw new InvalidOperationException("Writer is in the state '" + this.WriteState.ToString() + "' which is not valid for writing comments"); } current.AppendChild(owner.CreateComment(text)); if (state == WriteState.Start) { state = WriteState.Prolog; } }
/// <summary> /// Create a System.Xml.XmlWhitespace node. /// </summary> public override void WriteWhitespace(string ws) { if (state == WriteState.Attribute || state == WriteState.Element) { state = WriteState.Content; } if (state != WriteState.Content && state != WriteState.Prolog && state != WriteState.Start) { throw new InvalidOperationException("Writer is not in the right state to be writing whitespace nodes"); } current.AppendChild(owner.CreateWhitespace(ws)); if (state == WriteState.Start) { state = WriteState.Prolog; } }
protected void SetOutput(XmlStreamNodeWriter writer) { _inList = false; _writer = writer; _nodeWriter = writer; _writeState = WriteState.Start; _documentState = DocumentState.None; _nsMgr.Clear(); if (_depth != 0) { _elements = null; _depth = 0; } _attributeLocalName = null; _attributeValue = null; }
public Task EnqueueAsync(string id, EventState state, JObject data, JObject metadata) { AssertValidState(); var item = new WriteState { Data = data, State = state, Metadata = metadata, Id = id }; itemsToWrite.Enqueue(item); hasItems.Set(); return(item.TaskCompletionSource.Task); }
public void Close() { if (this.m_writer != null) { this.m_writer.Close(); this.m_writer = null; } if (this.tempMdat != null) { this.tempMdat.Close(); } if (string.IsNullOrEmpty(tempMdatFilePath) == false && File.Exists(tempMdatFilePath)) { File.Delete(tempMdatFilePath); } state = WriteState.Closed; }
/// <summary> /// InitializeForWriting /// Setup moov boxes, except ctts, stco, stsc, stss, stsz, and stts boxes /// </summary> /// <param name="tracksInfo">input media tracks</param> public override void InitializeForWriting(List <IsochronousTrackInfo> mediaTracksInfo) { string[] brands; if (mediaTracksInfo[0].Brands != null) { brands = mediaTracksInfo[0].Brands.Split(','); } else { brands = new string[3]; brands[0] = "mp42"; brands[1] = "isom"; brands[2] = "mp42"; } this.ftb = new FileTypeBox(brands); uint[] matrix = new uint[9]; matrix[0] = 0x10000; // 1.0 matrix[4] = 0x10000; // 1.0 matrix[8] = 0x40000000; // 1.0 (see description of RenderMatrix class) RawVideoTrackInfo rvti = (RawVideoTrackInfo)mediaTracksInfo.FirstOrDefault(ti => ti is RawVideoTrackInfo); //RawVideoTrackInfo rvti = (RawVideoTrackInfo)tracksInfo.First(info => info.HandlerType == "Video"); this.mmb = new MovieMetadataBox(mediaTracksInfo, 1.0f, 1.0f, matrix); if (rvti != null) { if (rvti.ObjectDescriptor != null) { this.mmb.ObjectDescriptorBox = new ObjectDescriptorBox(rvti.ObjectDescriptor); } if (rvti.UserData != null) { this.mmb.UserDataBox = new UserDataBox(rvti.UserData); } } if (!IsMediaStreamFragmented) { CreateTracksForWriting <MP4TrackFormat>(mediaTracksInfo); } state = WriteState.MoovReady; base.InitializeForWriting(mediaTracksInfo); }
public override void WriteBase64(byte[] buffer, int index, int count) { if (buffer == null) { throw new ArgumentNullException("buffer"); } ThrowIfClosed(); if (!this.rawWritingEnabled) { throw new InvalidOperationException("XmlWriter not in Element"); } this.stream.Write(buffer, index, count); this.state = WriteState.Content; }
private void WriteAttribute(Action <XmlWriter> action, WriteState entryState, WriteState exitState) { try { if (IsInChild) { action(ChildWriter); } else // is in root (or prolog) { RequireState(entryState); action(RootWriter); state = exitState; } } catch { Reset(WriteState.Error); throw; } }
private void CloseStartElement() { if (!open_start_element) { return; } if (state == WriteState.Attribute) { WriteEndAttribute(); } AddMissingElementXmlns(); state = WriteState.Content; open_start_element = false; }
public override void WriteEndAttribute() { CheckState (); if (state != WriteState.Attribute) throw new XmlException ("Cannot close attribute, as this XmlDictionaryWriter is not at attribute state"); if (attr_name == "type") { switch (attr_value) { case "object": element_kinds.Pop (); element_kinds.Push (ElementType.Object); OutputAsciiChar ('{'); break; case "array": element_kinds.Pop (); element_kinds.Push (ElementType.Array); OutputAsciiChar ('['); break; case "number": element_kinds.Pop (); element_kinds.Push (ElementType.Number); break; case "boolean": element_kinds.Pop (); element_kinds.Push (ElementType.Boolean); break; case "string": element_kinds.Pop (); element_kinds.Push (ElementType.String); break; case "null": element_kinds.Pop (); element_kinds.Push (ElementType.Null); OutputString ("null"); break; default: throw new XmlException (String.Format ("Unexpected type attribute value '{0}'", attr_value)); } } else runtime_type = attr_value; state = WriteState.Element; attr_value = null; }
public virtual void PrepareWrite(NpgsqlBuffer buf, object value) { Contract.Assert(_readState == ReadState.NeedPrepare); if (_writeState != WriteState.NeedPrepare) // Checks against recursion and bugs { throw new InvalidOperationException("Started reading a value before completing a previous value"); } _buf = buf; var asArray = value as Array; _writeValue = (IList)value; _dimensions = asArray != null ? asArray.Rank : 1; _index = 0; _wroteElementLen = false; _writeState = WriteState.WroteNothing; }
public void WriteNullArray() { ValidateNotDisposed(); if (WriteState == WriteState.Closed) { throw new InvalidOperationException(); } _current.Write("*-1\r\n"); _currentLength++; if (_ancestors.Count == 0) { WriteState = WriteState.Start; } }
public override void WriteStartAttribute(string prefix, string localName, string ns) { if (state != WriteState.Element) { throw new InvalidOperationException("Invalid document state for attribute: " + state); } state = WriteState.Attribute; if (ns == XmlNamespaces.XMLNS) { ProcessNamespace((prefix == null || prefix == String.Empty) ? "" : localName, String.Empty); // dummy: Value should be completed } else { ProcessAttribute(prefix, localName, ns, String.Empty); // dummy: Value should be completed } }
internal void AutoComplete(JsonToken tokenBeingWritten) { int num; switch (tokenBeingWritten) { case JsonToken.Integer: case JsonToken.Float: case JsonToken.String: case JsonToken.Boolean: case JsonToken.Null: case JsonToken.Undefined: case JsonToken.Date: case JsonToken.Bytes: num = 7; break; default: num = (int)tokenBeingWritten; break; } JsonWriter.State state = JsonWriter.stateArray[num][(int)this._currentState]; if (state == JsonWriter.State.Error) { throw new JsonWriterException("Token {0} in state {1} would result in an invalid JavaScript object.".FormatWith(CultureInfo.InvariantCulture, new object[] { tokenBeingWritten.ToString(), this._currentState.ToString() })); } if ((this._currentState == JsonWriter.State.Object || this._currentState == JsonWriter.State.Array || this._currentState == JsonWriter.State.Constructor) && tokenBeingWritten != JsonToken.Comment) { this.WriteValueDelimiter(); } else if (this._currentState == JsonWriter.State.Property && this._formatting == Formatting.Indented) { this.WriteIndentSpace(); } WriteState writeState = this.WriteState; if ((tokenBeingWritten == JsonToken.PropertyName && writeState != WriteState.Start) || writeState == WriteState.Array || writeState == WriteState.Constructor) { this.WriteIndent(); } this._currentState = state; }
public override void WriteEndElement() { CheckState(); if (state == WriteState.Attribute) { throw new XmlException("Cannot end element when an attribute is being written"); } if (state == WriteState.Element) { CloseStartElement(); } if (element_kinds.Count == 0) { throw new XmlException("There is no open element to close"); } switch (element_kinds.Pop()) { case ElementType.String: if (!is_null) { if (no_string_yet) { OutputAsciiChar('"'); } OutputAsciiChar('"'); } no_string_yet = true; is_null = false; break; case ElementType.Array: OutputAsciiChar(']'); break; case ElementType.Object: OutputAsciiChar('}'); break; } // not sure if it is correct though ... state = WriteState.Content; first_content_flags.Pop(); }
/// <summary> /// Creates a System.Xml.XmlEntityReference node. /// </summary> /// <param name="name">The name of the entity reference</param> public override void WriteEntityRef(string name) { if (state == WriteState.Element) { state = WriteState.Content; } XmlNode n = current; if (state == WriteState.Attribute) { n = ca; } else if (state != WriteState.Content) { throw new InvalidOperationException("Invalid state '" + WriteState.ToString() + "' for entity reference"); } n.AppendChild(owner.CreateEntityReference(name)); }
protected void SetOutput(XmlStreamNodeWriter writer) { this.inList = false; this.writer = writer; this.nodeWriter = writer; this.writeState = WriteState.Start; this.documentState = DocumentState.None; this.nsMgr.Clear(); if (this.depth != 0) { this.elements = null; this.depth = 0; } this.attributeLocalName = null; this.attributeValue = null; this.oldWriter = null; this.oldStream = null; }
public override void Close() { if (this.currentState == WriteState.Closed) { return; } try { this.builder.endDocument(); this.builder.close(); } catch { this.currentState = WriteState.Error; throw; } this.currentState = WriteState.Closed; this.document = (XdmNode)XdmValue.Wrap(this.builder.getCurrentRoot()); }
public override void WriteXmlnsAttribute(string prefix, string namespaceUri) { if (namespaceUri == null) { throw new ArgumentNullException("namespaceUri"); } if (String.IsNullOrEmpty(prefix)) { prefix = CreateNewPrefix(); } CheckStateForAttribute(); AddNamespaceChecked(prefix, namespaceUri); state = WriteState.Element; }
private void WriteEndElement(Action <XmlWriter> action) { try { if (IsInChild) { action(ChildWriter); state = WriteState.Content; } else // is in root (or prolog) { RequireState(WriteState.Element, WriteState.Content); state = WriteState.Prolog; } depth--; } catch { Reset(WriteState.Error); throw; } }
public object Visit(TextRun run) { if (string.IsNullOrEmpty(run.Text)) { return(null); } var prefix = run.Style.HasFlag(RunStyle.Code) ? "`" : ((run.Style.HasFlag(RunStyle.Bold) ? "**" : "") + (run.Style.HasFlag(RunStyle.Italic) ? "*" : "")); if (string.IsNullOrEmpty(prefix) || string.IsNullOrWhiteSpace(run.Text)) { _writer.Write(run.Text); } else { var firstNonWhitespace = 0; while (char.IsWhiteSpace(run.Text[firstNonWhitespace])) { firstNonWhitespace++; } var lastNonWhitespace = run.Text.Length - 1; while (char.IsWhiteSpace(run.Text[lastNonWhitespace])) { lastNonWhitespace--; } if (firstNonWhitespace > 0) { _writer.Write(run.Text.Substring(0, firstNonWhitespace)); } _writer.Write(prefix); _writer.Write(run.Text.Substring(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1)); _writer.Write(prefix); if (lastNonWhitespace < run.Text.Length - 1) { _writer.Write(run.Text.Substring(lastNonWhitespace + 1)); } } _state = WriteState.Text; return(this); }
internal void AutoComplete(JsonToken tokenBeingWritten) { int num; switch (tokenBeingWritten) { case JsonToken.Integer: case JsonToken.Float: case JsonToken.String: case JsonToken.Boolean: case JsonToken.Null: case JsonToken.Undefined: case JsonToken.Date: case JsonToken.Bytes: num = 7; break; default: num = (int)tokenBeingWritten; break; } State state = stateArray[num][(int)this._currentState]; if (state == State.Error) { throw new Exception("Token {0} in state {1} would result in an invalid JavaScript object."); } if ((((this._currentState == State.Object) || (this._currentState == State.Array)) || (this._currentState == State.Constructor)) && (tokenBeingWritten != JsonToken.Comment)) { this.WriteValueDelimiter(); } else if ((this._currentState == State.Property) && (this._formatting == Formatting.Indented)) { this.WriteIndentSpace(); } WriteState writeState = this.WriteState; if (((tokenBeingWritten == JsonToken.PropertyName) && (writeState != WriteState.Start)) || ((writeState == WriteState.Array) || (writeState == WriteState.Constructor))) { this.WriteIndent(); } this._currentState = state; }
public async Task WriteStartArrayAsync() { ValidateNotDisposed(); if (WriteState == WriteState.Closed) { throw new InvalidOperationException(); } await _current.WriteAsync('*'); _ancestors.Push(_current); _ancestorLengths.Push(_currentLength); _current = new StreamWriter(new MemoryStream(), _encoding); _currentLength = 0L; WriteState = WriteState.Array; }
private static WriteState setMode(WriteState newState, WriteState fromState, StringBuilder sb) { if (newState == fromState) return newState; if (fromState != WriteState.Normal) { // needs to close the old state sb.Append(@"\X0\"); } if (newState == WriteState.TwoBytes) { sb.Append(@"\X2\"); } else if (newState == WriteState.FourBytes) { sb.Append(@"\X4\"); } return newState; }
public override void Close() { // close all open elements while (element_kinds.Count > 0) { WriteEndElement(); } if (close_output) { output.Close(); } else { output.Flush(); } state = WriteState.Closed; }
internal void AutoComplete(JsonToken tokenBeingWritten) { if (tokenBeingWritten != JsonToken.StartObject && tokenBeingWritten != JsonToken.StartArray && tokenBeingWritten != JsonToken.StartConstructor) { UpdateScopeWithFinishedValue(); } // gets new state based on the current state and what is being written State newState = StateArray[(int)tokenBeingWritten][(int)_currentState]; if (newState == State.Error) { throw JsonWriterException.Create(this, "Token {0} in state {1} would result in an invalid JSON object.".FormatWith(CultureInfo.InvariantCulture, tokenBeingWritten.ToString(), _currentState.ToString()), null); } if ((_currentState == State.Object || _currentState == State.Array || _currentState == State.Constructor) && tokenBeingWritten != JsonToken.Comment) { WriteValueDelimiter(); } else if (_currentState == State.Property) { if (_formatting == Formatting.Indented) { WriteIndentSpace(); } } if (_formatting == Formatting.Indented) { WriteState writeState = WriteState; // don't indent a property when it is the first token to be written (i.e. at the start) if ((tokenBeingWritten == JsonToken.PropertyName && writeState != WriteState.Start) || writeState == WriteState.Array || writeState == WriteState.Constructor) { WriteIndent(); } } _currentState = newState; }
private void Init(XmlNode root, bool clearCurrentContents) { this.root = root; if (clearCurrentContents) { this.root.RemoveAll(); } if (root is XmlDocument) { owner = (XmlDocument)root; state = WriteState.Start; } else { owner = root.OwnerDocument; state = WriteState.Content; } current = root; }
public void Init() { this.atomicStringPool[0] = (this.nonAtomicStringPool[0] = string.Empty); this.atomicStringPool[1] = (this.nonAtomicStringPool[1] = null); this.atomicStringPool[2] = (this.nonAtomicStringPool[2] = "http://www.w3.org/XML/1998/namespace"); this.atomicStringPool[3] = (this.nonAtomicStringPool[3] = "http://www.w3.org/2000/xmlns/"); this.atomicIndex = (this.nonAtomicIndex = 4); this.AddNode(0, 0, 0, XPathNodeType.All, string.Empty, false, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, 0, 0, 0); this.nodeIndex++; this.AddAttribute(0, string.Empty, string.Empty, string.Empty, string.Empty, 0, 0); this.AddNsNode(0, string.Empty, string.Empty, 0); this.nsIndex++; this.AddNsNode(1, "xml", "http://www.w3.org/XML/1998/namespace", 0); this.AddNode(0, 0, 0, XPathNodeType.Root, string.Empty, false, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, 1, 0, 0); this.nodeIndex = 1; this.lastNsInScope = 1; this.parentStack[0] = this.nodeIndex; this.state = WriteState.Content; }
public override void WriteStartElement(string prefix, string localName, string ns) { try { if (IsInRoot) { ChildWriter.WriteStartElement(prefix, localName, ns); state = WriteState.Content; } else // is in prolog { RequireState(WriteState.Start, WriteState.Prolog); node.Clear(); state = WriteState.Element; } depth++; } catch { Reset(WriteState.Error); throw; } }
/// <summary> /// Closes the previous WriteStartElement call. /// </summary> public override void WriteEndElement() { if (current == root) throw new InvalidOperationException("Too many WriteEndElement calls have been made"); current = current.ParentNode; state = WriteState.Content; }
/// <summary> /// Closes any open elements and puts the writer back in the Start state. /// </summary> public override void WriteEndDocument() { current = root; state = WriteState.Start; }
/// <summary> /// Closes the previous WriteStartAttribute call. /// </summary> public override void WriteEndAttribute() { if (state != WriteState.Attribute) throw new InvalidOperationException("Writer is not in the Attribute state"); state = WriteState.Element; }
/// <summary> /// Creates an System.Xml.XmlDocumentType node. /// </summary> public override void WriteDocType(string name, string pubid, string sysid, string subset) { if (state != WriteState.Prolog && state != WriteState.Start) throw new InvalidOperationException("Writer is not in the Start or Prolog state, or root node is not an XmlDocument object"); if (owner.DocumentType != null) owner.RemoveChild(owner.DocumentType); owner.XmlResolver = null; current.AppendChild(owner.CreateDocumentType(name, pubid, sysid, subset)); state = WriteState.Prolog; }
/// <summary> /// Creates an System.Xml.XmlComment node. /// </summary> public override void WriteComment(string text) { if (state == WriteState.Attribute || state == WriteState.Element) state = WriteState.Content; if (state != WriteState.Content && state != WriteState.Prolog && state != WriteState.Start) throw new InvalidOperationException("Writer is in the state '" + this.WriteState.ToString() + "' which is not valid for writing comments"); current.AppendChild(owner.CreateComment(text)); if (state == WriteState.Start) state = WriteState.Prolog; }
/// <summary> /// This auto-closes any open elements and puts the writer in the WriteState.Closed state. /// </summary> public override void Close() { current = root; state = WriteState.Closed; }
/// <summary> /// Creates a System.Xml.XmlText node. If the current node is already an XmlText /// node it appends the text to that node. /// </summary> public override void WriteString(string text) { XmlNode parent = current; if (state == WriteState.Attribute) { parent = ca; } else if (state == WriteState.Element) { state = WriteState.Content; } if (state != WriteState.Attribute && state != WriteState.Content) throw new InvalidOperationException("Writer is in the wrong state to be writing text content"); XmlNode last = parent.LastChild; if (last == null || !(last is XmlText)) { last = owner.CreateTextNode(text); parent.AppendChild(last); } else { XmlText t = last as XmlText; t.AppendData(text); } }
/// <summary> /// Writes the XmlDeclaration node with a standalone attribute. This is only allowed when the /// writer is in the Start state, which only happens if the writer was constructed with an /// XmlDocument object. /// </summary> /// <param name="standalone">If true, standalone attribute has value "yes" otherwise it has the value "no".</param> public override void WriteStartDocument(bool standalone) { if (state != WriteState.Start) throw new InvalidOperationException("Writer is not in the Start state or root node is not an XmlDocument object"); current.AppendChild(owner.CreateXmlDeclaration("1.0", null, standalone ? "yes" : "no")); state = WriteState.Prolog; }
public override void WriteEndAttribute () { if (state != WriteState.Attribute) throw new InvalidOperationException ("Current state is not inside attribute. Cannot close attribute."); document.AttributeUpdate (element, element.SetAttributeNode (attribute), attribute); attribute = null; state = WriteState.Content; }
public override void WriteStartAttribute (string prefix, string name, string ns) { if (state != WriteState.Content) throw new InvalidOperationException ("Current state is not inside element. Cannot start attribute."); attribute = element.OwnerDocument.CreateAttribute (prefix, name, ns); state = WriteState.Attribute; }
protected override void Dispose(bool disposing) { if (!IsClosed) { try { WriteEndDocument(); } finally { try { _nodeWriter.Flush(); _nodeWriter.Close(); } finally { _writeState = WriteState.Closed; if (_depth != 0) { _depth = 0; } } } } base.Dispose(disposing); }
private void InitializeWriter() { _nodeType = JsonNodeType.None; _dataType = JsonDataType.None; _isWritingDataTypeAttribute = false; _wroteServerTypeAttribute = false; _isWritingServerTypeAttribute = false; _serverTypeValue = null; _attributeText = null; if (_depth != 0) { _depth = 0; } if ((_scopes != null) && (_scopes.Length > JsonGlobals.maxScopeSize)) { _scopes = null; } // Can't let writeState be at Closed if reinitializing. _writeState = WriteState.Start; _endElementBuffer = false; _indentLevel = 0; }
/// <summary> /// Creates a System.Xml.XmlEntityReference node. /// </summary> /// <param name="name">The name of the entity reference</param> public override void WriteEntityRef(string name) { if (state == WriteState.Element) state = WriteState.Content; XmlNode n = current; if (state == WriteState.Attribute) { n = ca; } else if (state != WriteState.Content) { throw new InvalidOperationException("Invalid state '"+WriteState.ToString()+"' for entity reference"); } n.AppendChild(owner.CreateEntityReference(name)); }
/// <summary> /// WriteRaw writes out the given string "unescaped", in other words it better be well formed XML markup. /// So for the XmlNodeWriter we parse this string and build the resulting tree, so it maps to setting the /// InnerXml property. /// </summary> /// <param name="data"></param> public override void WriteRaw(string data) { if (data.IndexOf("<")<0) { WriteString(data); return; } switch (state) { case WriteState.Start: goto case WriteState.Content; case WriteState.Prolog: goto case WriteState.Content; case WriteState.Element: state = WriteState.Content; goto case WriteState.Content; case WriteState.Attribute: { ArrayList saved = new ArrayList(); if (ca.HasChildNodes) { while (ca.FirstChild != null) { saved.Add(ca.FirstChild); ca.RemoveChild(ca.FirstChild); } } ca.InnerXml = data; for (int i = saved.Count-1; i>=0; i--) { ca.PrependChild((XmlNode)saved[i]); } } break; case WriteState.Content: { ArrayList saved = new ArrayList(); if (current.HasChildNodes) { while (current.FirstChild != null) { saved.Add(current.FirstChild); current.RemoveChild(current.FirstChild); } } current.InnerXml = data; for (int i = saved.Count-1; i>=0; i--) { current.PrependChild((XmlNode)saved[i]); } state = WriteState.Content; } break; case WriteState.Closed: throw new InvalidOperationException("Writer is closed"); } }
/// <summary> /// Creates a System.Xml.XmlProcessingInstruction node. /// </summary> public override void WriteProcessingInstruction(string name, string text) { if (state == WriteState.Attribute || state == WriteState.Element) state = WriteState.Content; if (state != WriteState.Content && state != WriteState.Prolog && state != WriteState.Start) throw new InvalidOperationException("Writer is in the state '" + this.WriteState.ToString() + "' which is not valid for writing processing instructions"); if (name == "xml") { XmlDocument doc2 = new XmlDocument(); doc2.InnerXml = "<?xml " + text + "?><root/>"; current.AppendChild(owner.ImportNode(doc2.FirstChild, true)); } else { current.AppendChild(owner.CreateProcessingInstruction(name, text)); } if (state == WriteState.Start) state = WriteState.Prolog; }
private void Init(XmlNode root, bool clearCurrentContents) { this.root = root; if (clearCurrentContents) this.root.RemoveAll(); if (root is XmlDocument) { owner = (XmlDocument)root; state = WriteState.Start; } else { owner = root.OwnerDocument; state = WriteState.Content; } current = root; }
/// <summary> /// Creates a System.Xml.XmlAttribute node. /// </summary> public override void WriteStartAttribute(string prefix, string localName, string ns) { /* applied fixes from www.gotdotnet.com if (state == WriteState.Attribute) state = WriteState.Element; if (state != WriteState.Element) throw new InvalidOperationException("Writer is not in a start tag, so it cannot write attributes."); ca = owner.CreateAttribute(prefix, localName, ns); current.Attributes.Append(ca); state = WriteState.Attribute; */ if (state == WriteState.Attribute) state = WriteState.Element; if (state != WriteState.Element) throw new InvalidOperationException("Writer is not in a start tag, so it cannot write attributes."); if (prefix == "xmlns" && ns == null) { ns = "http://www.w3.org/2000/xmlns/"; } ca = owner.CreateAttribute(prefix, localName, ns); current.Attributes.Append(ca); state = WriteState.Attribute; }
public override void WriteEndAttribute () { if (state != WriteState.Attribute) throw StateError ("End of attribute"); if (writer.Wrapped == preserver) { writer = writer.PreviousWrapper ?? new TextWriterWrapper (source, this); string value = preserver.ToString (); if (is_preserved_xmlns) { if (preserved_name.Length > 0 && value.Length == 0) throw ArgumentError ("Non-empty prefix must be mapped to non-empty namespace URI."); string existing = nsmanager.LookupNamespace (preserved_name, false); explicit_nsdecls.Add (preserved_name); if (open_count > 0) { if (v2 && elements [open_count - 1].Prefix == preserved_name && elements [open_count - 1].NS != value) throw new XmlException (String.Format ("Cannot redefine the namespace for prefix '{0}' used at current element", preserved_name)); if (elements [open_count - 1].NS != String.Empty || elements [open_count - 1].Prefix != preserved_name) { if (existing != value) nsmanager.AddNamespace (preserved_name, value); } } } else { switch (preserved_name) { case "lang": if (open_count > 0) elements [open_count - 1].XmlLang = value; break; case "space": switch (value) { case "default": if (open_count > 0) elements [open_count - 1].XmlSpace = XmlSpace.Default; break; case "preserve": if (open_count > 0) elements [open_count - 1].XmlSpace = XmlSpace.Preserve; break; default: throw ArgumentError ("Invalid value for xml:space."); } break; } } writer.Write (value); } writer.Write (formatSettings.QuoteChar); if (writer.InBlock) { writer.MarkBlockEnd (); if (writer.Column > TextPolicy.FileWidth) { WriteIndentAttribute (); writer.WriteBlock (true); writer.AttributesPerLine++; } else { writer.WriteBlock (false); } } state = WriteState.Element; }
/// <summary> /// Creates a System.Xml.XmlElement node. /// </summary> public override void WriteStartElement(string prefix, string localName, string ns) { /* applied fixes from www.gotdotnet.com if (state == WriteState.Attribute || state == WriteState.Element || state == WriteState.Start || state == WriteState.Prolog) state = WriteState.Content; if (state != WriteState.Content) throw new InvalidOperationException("Writer is in the wrong state for writing element content"); XmlElement e = owner.CreateElement(prefix, localName, ns); current.AppendChild(e); current = e; // push this element on the stack so to speak. state = WriteState.Element; */ if (state == WriteState.Attribute || state == WriteState.Element || state == WriteState.Start || state == WriteState.Prolog) state = WriteState.Content; if (state != WriteState.Content) throw new InvalidOperationException("Writer is in the wrong state for writing element content"); if (prefix == null) { prefix = current.GetPrefixOfNamespace(ns); } XmlElement e = owner.CreateElement(prefix, localName, ns); current.AppendChild(e); current = e; // push this element on the stack so to speak. state = WriteState.Element; }
void InitializeWriter() { nodeType = JsonNodeType.None; dataType = JsonDataType.None; isWritingDataTypeAttribute = false; wroteServerTypeAttribute = false; isWritingServerTypeAttribute = false; serverTypeValue = null; attributeText = null; if (depth != 0) { depth = 0; } if ((scopes != null) && (scopes.Length > JsonGlobals.maxScopeSize)) { scopes = null; } // Can't let writeState be at Closed if reinitializing. writeState = WriteState.Start; endElementBuffer = false; indentLevel = 0; }
/// <summary> /// Create a System.Xml.XmlWhitespace node. /// </summary> public override void WriteWhitespace(string ws) { if (state == WriteState.Attribute || state == WriteState.Element) state = WriteState.Content; if (state != WriteState.Content && state != WriteState.Prolog && state != WriteState.Start) throw new InvalidOperationException("Writer is not in the right state to be writing whitespace nodes"); current.AppendChild(owner.CreateWhitespace(ws)); if (state == WriteState.Start) state = WriteState.Prolog; }
public override void Close() { if (!IsClosed) { try { WriteEndDocument(); } finally { try { nodeWriter.Flush(); nodeWriter.Close(); } finally { writeState = WriteState.Closed; if (depth != 0) { depth = 0; } } } } }
private void InitiateCommand(MemcachedCommand command) { WriteCommandHeader(command); _writeState = new WriteState(command); }
internal virtual void Close( WriteState currentState ) { Close(); }