예제 #1
0
        internal XmlWriter CreateWriter(TextWriter output)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            XmlWriter writer;

            // create raw writer
            switch (this.OutputMethod)
            {
            case XmlOutputMethod.Xml:
                if (this.Indent)
                {
                    writer = new XmlEncodedRawTextWriterIndent(output, this);
                }
                else
                {
                    writer = new XmlEncodedRawTextWriter(output, this);
                }
                break;

            case XmlOutputMethod.Html:
                if (this.Indent)
                {
                    writer = new HtmlEncodedRawTextWriterIndent(output, this);
                }
                else
                {
                    writer = new HtmlEncodedRawTextWriter(output, this);
                }
                break;

            case XmlOutputMethod.Text:
                writer = new TextEncodedRawTextWriter(output, this);
                break;

            case XmlOutputMethod.AutoDetect:
                writer = new XmlAutoDetectWriter(output, this);
                break;

            default:
                Debug.Assert(false, "Invalid XmlOutputMethod setting.");
                return(null);
            }

            // XmlOutputMethod.AutoDetect writer does this lazily when it creates the underlying Xml or Html writer.
            if (this.OutputMethod != XmlOutputMethod.AutoDetect)
            {
                if (this.IsQuerySpecific)
                {
                    // Create QueryOutputWriter if CData sections or DocType need to be tracked
                    writer = new QueryOutputWriter((XmlRawWriter)writer, this);
                }
            }

            // wrap with well-formed writer
            writer = new XmlWellFormedWriter(writer, this);

            return(writer);
        }
예제 #2
0
        internal XmlWriter CreateWriter(Stream output)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            XmlWriter writer;

            // create raw writer

            Debug.Assert(Encoding.UTF8.WebName == "utf-8");
            if (this.Encoding.WebName == "utf-8")
            { // Encoding.CodePage is not supported in Silverlight
                // create raw UTF-8 writer
                switch (this.OutputMethod)
                {
                case XmlOutputMethod.Xml:
                    if (this.Indent)
                    {
                        writer = new XmlUtf8RawTextWriterIndent(output, this);
                    }
                    else
                    {
                        writer = new XmlUtf8RawTextWriter(output, this);
                    }
                    break;

                case XmlOutputMethod.Html:
                    if (this.Indent)
                    {
                        writer = new HtmlUtf8RawTextWriterIndent(output, this);
                    }
                    else
                    {
                        writer = new HtmlUtf8RawTextWriter(output, this);
                    }
                    break;

                case XmlOutputMethod.Text:
                    writer = new TextUtf8RawTextWriter(output, this);
                    break;

                case XmlOutputMethod.AutoDetect:
                    writer = new XmlAutoDetectWriter(output, this);
                    break;

                default:
                    Debug.Assert(false, "Invalid XmlOutputMethod setting.");
                    return(null);
                }
            }
            else
            {
                // Otherwise, create a general-purpose writer than can do any encoding
                switch (this.OutputMethod)
                {
                case XmlOutputMethod.Xml:
                    if (this.Indent)
                    {
                        writer = new XmlEncodedRawTextWriterIndent(output, this);
                    }
                    else
                    {
                        writer = new XmlEncodedRawTextWriter(output, this);
                    }
                    break;

                case XmlOutputMethod.Html:
                    if (this.Indent)
                    {
                        writer = new HtmlEncodedRawTextWriterIndent(output, this);
                    }
                    else
                    {
                        writer = new HtmlEncodedRawTextWriter(output, this);
                    }
                    break;

                case XmlOutputMethod.Text:
                    writer = new TextEncodedRawTextWriter(output, this);
                    break;

                case XmlOutputMethod.AutoDetect:
                    writer = new XmlAutoDetectWriter(output, this);
                    break;

                default:
                    Debug.Assert(false, "Invalid XmlOutputMethod setting.");
                    return(null);
                }
            }

            // Wrap with Xslt/XQuery specific writer if needed;
            // XmlOutputMethod.AutoDetect writer does this lazily when it creates the underlying Xml or Html writer.
            if (this.OutputMethod != XmlOutputMethod.AutoDetect)
            {
                if (this.IsQuerySpecific)
                {
                    // Create QueryOutputWriter if CData sections or DocType need to be tracked
                    writer = new QueryOutputWriter((XmlRawWriter)writer, this);
                }
            }

            // wrap with well-formed writer
            writer = new XmlWellFormedWriter(writer, this);

            return(writer);
        }