/// <summary>
 /// Writes the DOCTYPE declaration with the specified name and optional attributes.
 /// </summary>
 /// <param name="name">The name of the DOCTYPE. This must be non-empty.</param>
 /// <param name="pubid">If non-null it also writes PUBLIC "pubid" "sysid" where pubid and sysid are
 /// replaced with the value of the given arguments.</param>
 /// <param name="sysid">If pubid is null and sysid is non-null it writes SYSTEM "sysid" where sysid
 /// is replaced with the value of this argument.</param>
 /// <param name="subset">If non-null it writes [subset] where subset is replaced with the value of
 /// this argument.</param>
 public override void WriteDocType(string name, string pubid, string sysid, string subset)
 {
     _innerWriter.WriteDocType(name, pubid, sysid, subset);
     if (_tracingWriter != null)
     {
         _tracingWriter.WriteDocType(name, pubid, sysid, subset);
     }
 }
 public override void WriteDocType(string name, string pubid, string sysid, string subset)
 {
     _innerWriter.WriteDocType(name, pubid, sysid, subset);
 }
 public void WriteDocType()
 {
     w.WriteDocType(null, null, null, null);
 }
Example #4
0
        public static async Task WriteNodeAsync(XmlDictionaryWriter writer, XmlReader reader, bool defattr)
        {
            char[]    writeNodeBuffer     = null;
            const int WriteNodeBufferSize = 1024;

            if (null == reader)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            bool canReadChunk = reader.CanReadValueChunk;
            int  d            = reader.NodeType == XmlNodeType.None ? -1 : reader.Depth;

            do
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                    writer.WriteAttributes(reader, defattr);
                    if (reader.IsEmptyElement)
                    {
                        writer.WriteEndElement();
                        break;
                    }
                    break;

                case XmlNodeType.Text:
                    if (canReadChunk)
                    {
                        if (writeNodeBuffer == null)
                        {
                            writeNodeBuffer = new char[WriteNodeBufferSize];
                        }
                        int read;
                        while ((read = reader.ReadValueChunk(writeNodeBuffer, 0, WriteNodeBufferSize)) > 0)
                        {
                            writer.WriteChars(writeNodeBuffer, 0, read);
                        }
                    }
                    else
                    {
                        writer.WriteString(await reader.GetValueAsync());
                    }
                    break;

                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    writer.WriteWhitespace(await reader.GetValueAsync());
                    break;

                case XmlNodeType.CDATA:
                    writer.WriteCData(await reader.GetValueAsync());
                    break;

                case XmlNodeType.EntityReference:
                    writer.WriteEntityRef(reader.Name);
                    break;

                case XmlNodeType.XmlDeclaration:
                case XmlNodeType.ProcessingInstruction:
                    writer.WriteProcessingInstruction(reader.Name, await reader.GetValueAsync());
                    break;

                case XmlNodeType.DocumentType:
                    writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), await reader.GetValueAsync());
                    break;

                case XmlNodeType.Comment:
                    writer.WriteComment(await reader.GetValueAsync());
                    break;

                case XmlNodeType.EndElement:
                    writer.WriteFullEndElement();
                    break;
                }
            } while (await reader.ReadAsync() && (d < reader.Depth || (d == reader.Depth && reader.NodeType == XmlNodeType.EndElement)));
        }
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            try
            {
                do
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                        for (int i = 0; i < reader.AttributeCount; i++)
                        {
                            reader.MoveToAttribute(i);
                            writer.WriteAttributeString(reader.LocalName, reader.NamespaceURI, reader.Value.Replace(sourcePattern, targetPattern));
                        }
                        reader.MoveToElement();
                        if (reader.IsEmptyElement)
                        {
                            writer.WriteEndElement();
                        }
                        break;

                    case XmlNodeType.Text:
                        writer.WriteString(reader.Value.Replace(sourcePattern, targetPattern));
                        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;
                    }
                }while (reader.Read());
                writer.Flush();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
        }