public virtual void WriteXml(System.Xml.XmlWriter writer) { writer.WriteStartElement("WriteAttributes"); using (StringReader sr = new StringReader(CommonUtilities.XmlStringForAttributes)) { using (XmlReader reader = new XmlTextReader(sr)) { bool found = false; while (reader.Read()) { if (reader.Name.Equals("attributeHolder")) { found = true; break; } } if (found == false) { throw new Exception("could not find the attributeHolder node"); } // reader.ReadElementString("attributeHolder"); //moves to the root node writer.WriteAttributes(reader, false); } } writer.WriteEndElement(); }
private static void WriteShallowNode(XmlReader reader, XmlWriter writer) { switch (reader.NodeType) { case XmlNodeType.Element: writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); writer.WriteAttributes(reader, true); if (reader.IsEmptyElement) { writer.WriteEndElement(); } return; case XmlNodeType.Text: writer.WriteString(reader.Value); return; case XmlNodeType.CDATA: writer.WriteCData(reader.Value); return; case XmlNodeType.ProcessingInstruction: writer.WriteProcessingInstruction(reader.Name, reader.Value); return; case XmlNodeType.Comment: writer.WriteComment(reader.Value); return; case XmlNodeType.DocumentType: writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value); return; case XmlNodeType.Whitespace: writer.WriteWhitespace(reader.Value); return; case XmlNodeType.SignificantWhitespace: writer.WriteWhitespace(reader.Value); return; case XmlNodeType.EndElement: writer.WriteFullEndElement(); return; case XmlNodeType.XmlDeclaration: writer.WriteProcessingInstruction(reader.Name, reader.Value); return; } throw new InvalidOperationException("Invalid node"); }
private static void CopyUntilEndOfChanges(XmlReader reader, XmlWriter writer) { Debug.Assert(writer != null); Debug.Assert(reader != null); reader.MoveToContent(); while (!(reader.EOF || reader.NodeType == XmlNodeType.EndElement && reader.Name == "Changes")) { if (reader.NodeType == XmlNodeType.Element) { writer.WriteStartElement(reader.Name); writer.WriteAttributes(reader, false); } else if (reader.NodeType == XmlNodeType.Text) { writer.WriteString(reader.Value); } else if (reader.NodeType == XmlNodeType.EndElement) { writer.WriteEndElement(); } reader.Read(); } }
// Writes the content (inner XML) of the current node into the provided XmlWriter. private async Task WriteNodeAsync(XmlWriter xtw, bool defattr) { int d = this.NodeType == XmlNodeType.None ? -1 : this.Depth; while (await this.ReadAsync().ConfigureAwait(false) && (d < this.Depth)) { switch (this.NodeType) { case XmlNodeType.Element: xtw.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceURI); xtw.WriteAttributes(this, defattr); if (this.IsEmptyElement) { xtw.WriteEndElement(); } break; case XmlNodeType.Text: xtw.WriteString(await this.GetValueAsync().ConfigureAwait(false)); break; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: xtw.WriteWhitespace(await this.GetValueAsync().ConfigureAwait(false)); break; case XmlNodeType.CDATA: xtw.WriteCData(this.Value); break; case XmlNodeType.EntityReference: xtw.WriteEntityRef(this.Name); break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: xtw.WriteProcessingInstruction(this.Name, this.Value); break; case XmlNodeType.DocumentType: xtw.WriteDocType(this.Name, this.GetAttribute("PUBLIC"), this.GetAttribute("SYSTEM"), this.Value); break; case XmlNodeType.Comment: xtw.WriteComment(this.Value); break; case XmlNodeType.EndElement: xtw.WriteFullEndElement(); break; } } if (d == this.Depth && this.NodeType == XmlNodeType.EndElement) { await ReadAsync().ConfigureAwait(false); } }
//copies from example private void PassNodeThrough(XmlReader reader, XmlWriter writer) { switch (reader.NodeType) { case XmlNodeType.Element: writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); writer.WriteAttributes(reader, true); if (reader.IsEmptyElement) { writer.WriteEndElement(); } break; case XmlNodeType.Text: writer.WriteString(reader.Value); break; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: writer.WriteWhitespace(reader.Value); break; case XmlNodeType.CDATA: writer.WriteCData(reader.Value); break; case XmlNodeType.EntityReference: writer.WriteEntityRef(reader.Name); break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: writer.WriteProcessingInstruction(reader.Name, reader.Value); break; case XmlNodeType.DocumentType: writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value); break; case XmlNodeType.Comment: writer.WriteComment(reader.Value); break; case XmlNodeType.EndElement: writer.WriteFullEndElement(); break; } }
// Writes the content (inner XML) of the current node into the provided XmlWriter. private void WriteNode(XmlWriter xtw, bool defattr) { #if !SILVERLIGHT Debug.Assert(xtw is XmlTextWriter); #endif int d = this.NodeType == XmlNodeType.None ? -1 : this.Depth; while (this.Read() && (d < this.Depth)) { switch (this.NodeType) { case XmlNodeType.Element: xtw.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceURI); #if !SILVERLIGHT // Removing dependency on XmlTextWriter ((XmlTextWriter)xtw).QuoteChar = this.QuoteChar; #endif xtw.WriteAttributes(this, defattr); if (this.IsEmptyElement) { xtw.WriteEndElement(); } break; case XmlNodeType.Text: xtw.WriteString(this.Value); break; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: xtw.WriteWhitespace(this.Value); break; case XmlNodeType.CDATA: xtw.WriteCData(this.Value); break; case XmlNodeType.EntityReference: xtw.WriteEntityRef(this.Name); break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: xtw.WriteProcessingInstruction(this.Name, this.Value); break; case XmlNodeType.DocumentType: xtw.WriteDocType(this.Name, this.GetAttribute("PUBLIC"), this.GetAttribute("SYSTEM"), this.Value); break; case XmlNodeType.Comment: xtw.WriteComment(this.Value); break; case XmlNodeType.EndElement: xtw.WriteFullEndElement(); break; } } if (d == this.Depth && this.NodeType == XmlNodeType.EndElement) { Read(); } }
// From http://blogs.msdn.com/b/mfussell/archive/2005/02/12/371546.aspx static void WriteShallowNode( XmlReader reader, XmlWriter writer ) { if ( reader == null ) { throw new ArgumentNullException("reader"); } if ( writer == null ) { throw new ArgumentNullException("writer"); } switch ( reader.NodeType ) { case XmlNodeType.Element: writer.WriteStartElement( reader.Prefix, reader.LocalName, reader.NamespaceURI ); writer.WriteAttributes( reader, true ); if ( reader.IsEmptyElement ) { writer.WriteEndElement(); } break; case XmlNodeType.Text: writer.WriteString( reader.Value ); break; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: writer.WriteWhitespace(reader.Value); break; case XmlNodeType.CDATA: writer.WriteCData( reader.Value ); break; case XmlNodeType.EntityReference: writer.WriteEntityRef(reader.Name); break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: writer.WriteProcessingInstruction( reader.Name, reader.Value ); break; case XmlNodeType.DocumentType: writer.WriteDocType( reader.Name, reader.GetAttribute( "PUBLIC" ), reader.GetAttribute( "SYSTEM" ), reader.Value ); break; case XmlNodeType.Comment: writer.WriteComment( reader.Value ); break; case XmlNodeType.EndElement: writer.WriteFullEndElement(); break; } }
public override void WriteAttributes(XmlReader reader, bool defattr) { CheckAsync(); _coreWriter.WriteAttributes(reader, defattr); }
/// <summary> /// This is used to write out the body content of a topic to the main document part /// </summary> /// <param name="writer">The writer for the main document part</param> /// <param name="reader">The reader for the topic body content</param> /// <remarks>Using a reader prevents unnecessary namespaces from appearing on the body content elements /// which happens if we convert the XElement content to a string and write it out as raw content.</remarks> private static void WriteTopic(XmlWriter writer, XmlReader reader) { while(!reader.EOF) { reader.Read(); switch(reader.NodeType) { case XmlNodeType.Element: writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); writer.WriteAttributes(reader, true); if(reader.IsEmptyElement) writer.WriteEndElement(); break; case XmlNodeType.Text: writer.WriteString(reader.Value); break; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: writer.WriteWhitespace(reader.Value); break; case XmlNodeType.CDATA: writer.WriteCData(reader.Value); break; case XmlNodeType.EntityReference: writer.WriteEntityRef(reader.Name); break; case XmlNodeType.Comment: writer.WriteComment(reader.Value); break; case XmlNodeType.EndElement: // Stop when the end of the body is reached if(reader.LocalName == "body") return; writer.WriteFullEndElement(); break; } } }
private void StreamToInsertionPoint(XmlReader reader, XmlWriter writer) { if ( reader == null ) { throw new ArgumentNullException("reader"); } if ( writer == null ) { throw new ArgumentNullException("writer"); } while (reader.Read()) { if(reader.LocalName == "notes" && reader.IsEmptyElement) { writer.WriteStartElement("notes"); writer.WriteAttributes(reader, false); return; } if(reader.LocalName == "notes" && !reader.IsStartElement()) { return; } StreamNode(reader, writer); } }
private static void ProcessElement(XmlReader reader, XmlWriter writer) { if (reader.Name == "entry") { string guid = reader.GetAttribute("guid"); if (String.IsNullOrEmpty(guid)) { guid = Guid.NewGuid().ToString(); writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); writer.WriteAttributes(reader, true); writer.WriteAttributeString("guid", guid); string s = reader.ReadInnerXml();//this seems to be enough to get the reader to the next element writer.WriteRaw(s); writer.WriteEndElement(); } else { writer.WriteNode(reader, true); } } else { WriteShallowNode(reader, writer); } }
protected void CopyNode(XmlReader reader, XmlWriter writer) { switch (reader.NodeType) { case XmlNodeType.Element: writer.WriteStartElement(reader.Name); writer.WriteAttributes(reader, false); if (reader.IsEmptyElement) { writer.WriteEndElement(); } break; case XmlNodeType.EndElement: writer.WriteEndElement(); break; case XmlNodeType.Text: writer.WriteValue(reader.Value); break; } }
private static void LimitHtmlOnWordBoundary(XmlWriter writer, XmlReader reader, int maxLength, out bool shouldWriteEllipses) { if (reader == null) { throw new ArgumentNullException("reader"); } if (writer == null) { throw new ArgumentNullException("writer"); } int elementCount = 0; int currentLength = 0; shouldWriteEllipses = false; int magicMinimumLength = Math.Min(5, (maxLength + 1) / 2); int num = (reader.NodeType == XmlNodeType.None) ? -1 : reader.Depth; do { bool done = false; switch (reader.NodeType) { case XmlNodeType.Element: elementCount++; writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); writer.WriteAttributes(reader, false); if (reader.IsEmptyElement) { elementCount--; writer.WriteEndElement(); } break; case XmlNodeType.Text: string value = reader.Value; int strLen = value.Length; if (currentLength + strLen > maxLength) { string almost = value.Substring(0, maxLength - currentLength + 1); int lastSpace = almost.LastIndexOf(' '); if (lastSpace < 0) { if (currentLength < magicMinimumLength) { value = value.Substring(0, maxLength - currentLength); } else { value = null; } } else if (lastSpace + currentLength < magicMinimumLength) { value = value.Substring(0, maxLength - currentLength); } else { value = value.Substring(0, lastSpace); } shouldWriteEllipses = true; done = true; } if (value != null) { writer.WriteString(value); currentLength += value.Length; } break; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: writer.WriteString(reader.Value); currentLength += reader.Value.Length; break; case XmlNodeType.EndElement: elementCount--; writer.WriteFullEndElement(); break; case XmlNodeType.CDATA: //writer.WriteCData(reader.Value); break; case XmlNodeType.EntityReference: writer.WriteEntityRef(reader.Name); currentLength++; break; case XmlNodeType.ProcessingInstruction: case XmlNodeType.XmlDeclaration: //writer.WriteProcessingInstruction(reader.Name, reader.Value); break; case XmlNodeType.Comment: //writer.WriteComment(reader.Value); break; case XmlNodeType.DocumentType: //writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value); break; } if (done) break; } while (reader.Read() && ((num < reader.Depth) || ((num == reader.Depth) && (reader.NodeType == XmlNodeType.EndElement)))); while (elementCount > 0) { writer.WriteFullEndElement(); elementCount--; } }
public static void WriteShallowNode(XmlReader reader, XmlWriter writer) { //Console.WriteLine("{0}: {1}", reader.NodeType, reader.Name); switch(reader.NodeType) { case XmlNodeType.Element: writer.WriteStartElement(reader.Prefix , reader.LocalName, reader.NamespaceURI); writer.WriteAttributes(reader, true); if(reader.IsEmptyElement) writer.WriteEndElement(); break; case XmlNodeType.Text: writer.WriteString(reader.Value); break; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: writer.WriteWhitespace(reader.Value); break; case XmlNodeType.CDATA: writer.WriteCData(reader.Value); break; case XmlNodeType.EntityReference: writer.WriteEntityRef(reader.Name); break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: writer.WriteProcessingInstruction(reader.Name, reader.Value); break; case XmlNodeType.DocumentType: writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value); break; case XmlNodeType.Comment: writer.WriteComment(reader.Value); break; case XmlNodeType.EndElement: writer.WriteFullEndElement(); break; } }
private void CopyUntilElement(XmlWriter writer, XmlReader reader, string elementName) { Debug.Assert(writer != null); Debug.Assert(reader != null); Debug.Assert(!string.IsNullOrEmpty(elementName)); if (reader.NodeType == XmlNodeType.None) { reader.Read(); } while (!reader.EOF && reader.NodeType != XmlNodeType.EndElement && (reader.NodeType != XmlNodeType.Element || LdmlNodeComparer.CompareElementNames(reader.Name, elementName) < 0)) { // XmlWriter.WriteNode doesn't do anything if the node type is Attribute if (reader.NodeType == XmlNodeType.Attribute) { writer.WriteAttributes(reader, false); } else { writer.WriteNode(reader, false); } } }
private void InvokeMethod(XmlWriter w, string methodName) { byte[] buffer = new byte[10]; switch (methodName) { case "WriteStartDocument": w.WriteStartDocument(); break; case "WriteStartElement": w.WriteStartElement("root"); break; case "WriteEndElement": w.WriteEndElement(); break; case "WriteStartAttribute": w.WriteStartAttribute("attr"); break; case "WriteEndAttribute": w.WriteEndAttribute(); break; case "WriteCData": w.WriteCData("test"); break; case "WriteComment": w.WriteComment("test"); break; case "WritePI": w.WriteProcessingInstruction("name", "test"); break; case "WriteEntityRef": w.WriteEntityRef("e"); break; case "WriteCharEntity": w.WriteCharEntity('c'); break; case "WriteSurrogateCharEntity": w.WriteSurrogateCharEntity('\uDC00', '\uDBFF'); break; case "WriteWhitespace": w.WriteWhitespace(" "); break; case "WriteString": w.WriteString("foo"); break; case "WriteChars": char[] charArray = new char[] { 'a', 'b', 'c', 'd' }; w.WriteChars(charArray, 0, 3); break; case "WriteRaw": w.WriteRaw("<foo>bar</foo>"); break; case "WriteBase64": w.WriteBase64(buffer, 0, 9); break; case "WriteBinHex": w.WriteBinHex(buffer, 0, 9); break; case "LookupPrefix": string str = w.LookupPrefix("foo"); break; case "WriteNmToken": w.WriteNmToken("foo"); break; case "WriteName": w.WriteName("foo"); break; case "WriteQualifiedName": w.WriteQualifiedName("foo", "bar"); break; case "WriteValue": w.WriteValue(Int32.MaxValue); break; case "WriteAttributes": XmlReader xr1 = ReaderHelper.Create(new StringReader("<root attr='test'/>")); xr1.Read(); w.WriteAttributes(xr1, false); break; case "WriteNodeReader": XmlReader xr2 = ReaderHelper.Create(new StringReader("<root/>")); xr2.Read(); w.WriteNode(xr2, false); break; case "Flush": w.Flush(); break; default: CError.Equals(false, "Unexpected param in testcase: {0}", methodName); break; } }
private void CopyToEndElement(XmlWriter writer, XmlReader reader) { Debug.Assert(writer != null); Debug.Assert(reader != null); while (!reader.EOF && reader.NodeType != XmlNodeType.EndElement) { // XmlWriter.WriteNode doesn't do anything if the node type is Attribute if (reader.NodeType == XmlNodeType.Attribute) { writer.WriteAttributes(reader, false); } else { writer.WriteNode(reader, false); } } // either read the end element or no-op if EOF reader.Read(); }
public override void WriteAttributes(XmlReader reader, bool defattr) { _writer.WriteAttributes(reader, defattr); }
// Writes the content (inner XML) of the current node into the provided XmlWriter. private async Task WriteNodeAsync(XmlWriter xtw, bool defattr) { #if !SILVERLIGHT Debug.Assert(xtw is XmlTextWriter); #endif int d = this.NodeType == XmlNodeType.None ? -1 : this.Depth; while (await this.ReadAsync().ConfigureAwait(false) && (d < this.Depth)) { switch (this.NodeType) { case XmlNodeType.Element: xtw.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceURI); #if !SILVERLIGHT // Removing dependency on XmlTextWriter ((XmlTextWriter)xtw).QuoteChar = this.QuoteChar; #endif xtw.WriteAttributes(this, defattr); if (this.IsEmptyElement) { xtw.WriteEndElement(); } break; case XmlNodeType.Text: xtw.WriteString(await this.GetValueAsync().ConfigureAwait(false)); break; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: xtw.WriteWhitespace(await this.GetValueAsync().ConfigureAwait(false)); break; case XmlNodeType.CDATA: xtw.WriteCData(this.Value); break; case XmlNodeType.EntityReference: xtw.WriteEntityRef(this.Name); break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: xtw.WriteProcessingInstruction(this.Name, this.Value); break; case XmlNodeType.DocumentType: xtw.WriteDocType(this.Name, this.GetAttribute("PUBLIC"), this.GetAttribute("SYSTEM"), this.Value); break; case XmlNodeType.Comment: xtw.WriteComment(this.Value); break; case XmlNodeType.EndElement: xtw.WriteFullEndElement(); break; } } if (d == this.Depth && this.NodeType == XmlNodeType.EndElement) { await ReadAsync().ConfigureAwait(false); } }
private void WriteNode(XmlWriter xtw, bool defattr) { int num = (this.NodeType == XmlNodeType.None) ? -1 : this.Depth; while (this.Read() && (num < this.Depth)) { switch (this.NodeType) { case XmlNodeType.Element: xtw.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceURI); ((XmlTextWriter) xtw).QuoteChar = this.QuoteChar; xtw.WriteAttributes(this, defattr); if (this.IsEmptyElement) { xtw.WriteEndElement(); } break; case XmlNodeType.Text: xtw.WriteString(this.Value); break; case XmlNodeType.CDATA: xtw.WriteCData(this.Value); break; case XmlNodeType.EntityReference: xtw.WriteEntityRef(this.Name); break; case XmlNodeType.ProcessingInstruction: case XmlNodeType.XmlDeclaration: xtw.WriteProcessingInstruction(this.Name, this.Value); break; case XmlNodeType.Comment: xtw.WriteComment(this.Value); break; case XmlNodeType.DocumentType: xtw.WriteDocType(this.Name, this.GetAttribute("PUBLIC"), this.GetAttribute("SYSTEM"), this.Value); break; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: xtw.WriteWhitespace(this.Value); break; case XmlNodeType.EndElement: xtw.WriteFullEndElement(); break; } } if ((num == this.Depth) && (this.NodeType == XmlNodeType.EndElement)) { this.Read(); } }
/// <summary> /// Preprocesses and copies an Xml document from a reader into a writer. /// </summary> /// <param name="xmlReader">The Xml reader.</param> /// <param name="xmlWriter">The Xml writer.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="xmlReader"/> /// or <paramref name="xmlWriter"/> is null.</exception> /// <exception cref="InvalidOperationException">Thrown if the input Xml is malformed /// such as if it contains unbalanced ifdef/endif pairs.</exception> public void Preprocess(XmlReader xmlReader, XmlWriter xmlWriter) { if (xmlReader == null) throw new ArgumentNullException("xmlReader"); if (xmlWriter == null) throw new ArgumentNullException("xmlWriter"); // Tracks whether a given block has been included or excluded. Stack<bool> blockStack = new Stack<bool>(); blockStack.Push(true); while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.ProcessingInstruction) { switch (xmlReader.Name) { case "define": if (blockStack.Peek()) Define(xmlReader.Value.Trim()); continue; case "ifdef": blockStack.Push(blockStack.Peek() && IsDefined(xmlReader.Value.Trim())); continue; case "ifndef": blockStack.Push(blockStack.Peek() && !IsDefined(xmlReader.Value.Trim())); continue; case "else": if (blockStack.Count == 1) throw new InvalidOperationException( "Found <?else?> instruction without enclosing <?ifdef?> or <?ifndef?> block."); blockStack.Push(!blockStack.Pop() && blockStack.Peek()); // order matters continue; case "endif": if (blockStack.Count == 1) throw new InvalidOperationException( "Found <?endif?> instruction without matching <?ifdef?> or <?ifndef?>."); blockStack.Pop(); continue; } } if (!blockStack.Peek()) continue; switch (xmlReader.NodeType) { case XmlNodeType.Element: xmlWriter.WriteStartElement(xmlReader.Prefix, xmlReader.LocalName, xmlReader.NamespaceURI); xmlWriter.WriteAttributes(xmlReader, true); if (xmlReader.IsEmptyElement) xmlWriter.WriteEndElement(); break; case XmlNodeType.Text: xmlWriter.WriteValue(xmlReader.Value); break; case XmlNodeType.CDATA: xmlWriter.WriteCData(xmlReader.Value); break; case XmlNodeType.EntityReference: xmlWriter.WriteEntityRef(xmlReader.Name); break; case XmlNodeType.Comment: xmlWriter.WriteComment(xmlReader.Value); break; case XmlNodeType.DocumentType: xmlWriter.WriteDocType(xmlReader.Name, xmlReader.GetAttribute("PUBLIC"), xmlReader.GetAttribute("SYSTEM"), xmlReader.Value); break; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: xmlWriter.WriteWhitespace(xmlReader.Value); break; case XmlNodeType.EndElement: xmlWriter.WriteFullEndElement(); break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: xmlWriter.WriteProcessingInstruction(xmlReader.Name, xmlReader.Value); break; } } if (blockStack.Count != 1) throw new InvalidOperationException("Missing <?endif?> instruction."); xmlWriter.Flush(); }