Пример #1
0
        //
        // Internal properties
        //


        internal XmlWriter CreateWriter(Stream output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(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
                if (this.Indent)
                {
                    writer = new XmlUtf8RawTextWriterIndent(output, this);
                }
                else
                {
                    writer = new XmlUtf8RawTextWriter(output, this);
                }
            }
            else
            {
                // create raw writer for other encodings
                if (this.Indent)
                {
                    writer = new XmlEncodedRawTextWriterIndent(output, this);
                }
                else
                {
                    writer = new XmlEncodedRawTextWriter(output, this);
                }
            }

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

            if (_useAsync)
            {
                writer = new XmlAsyncCheckWriter(writer);
            }

            return(writer);
        }
        internal XmlWriter CreateWriter(Stream output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(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.Fail("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.Fail("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);

            if (_useAsync)
            {
                writer = new XmlAsyncCheckWriter(writer);
            }

            return(writer);
        }
        internal XmlWriter CreateWriter(Stream output) {
            if (output == null) {
                throw new ArgumentNullException("output");
            }

            XmlWriter writer;
            
            // create raw writer
#if SILVERLIGHT
            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
                if (this.Indent) {
                    writer = new XmlUtf8RawTextWriterIndent(output, this);
                }
                else {
                    writer = new XmlUtf8RawTextWriter(output, this);
                }
            }
            else {
                // create raw writer for other encodings
                if (this.Indent) {
                    writer = new XmlEncodedRawTextWriterIndent(output, this);
                }
                else {
                    writer = new XmlEncodedRawTextWriter(output, this);
                }
            }
#else
            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);
                }
            }
#endif // !SILVERLIGHT

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

#if ASYNC
            if (useAsync) {
                writer = new XmlAsyncCheckWriter(writer);
            }
#endif

            return writer;
        }
Пример #4
0
        private static XmlWriter CreateWriterImpl(Stream output, Encoding encoding, bool closeOutput, XmlWriterSettings settings) {
            Debug.Assert(output != null);
            Debug.Assert(encoding != null);
            Debug.Assert(settings != null);

            XmlWriter writer;

            if (encoding.CodePage == 65001) {
                // If the encoding is UTF-8, create a special-purpose writer
                switch (settings.OutputMethod) {
                    case XmlOutputMethod.Xml:
                        if (settings.Indent) {
                            writer = new XmlUtf8RawTextWriterIndent(output, encoding, settings, closeOutput);
                        }
                        else {
                            writer = new XmlUtf8RawTextWriter(output, encoding, settings, closeOutput);
                        }
                        break;
                    case XmlOutputMethod.Html:
                        if (settings.Indent) {
                            writer = new HtmlUtf8RawTextWriterIndent(output, encoding, settings, closeOutput);
                        }
                        else {
                            writer = new HtmlUtf8RawTextWriter(output, encoding, settings, closeOutput);
                        }
                        break;
                    case XmlOutputMethod.Text:
                        writer = new TextUtf8RawTextWriter(output, encoding, settings, closeOutput);
                        break;
                    case XmlOutputMethod.AutoDetect:
                        writer = new XmlAutoDetectWriter(output, encoding, settings);
                        break;
                    default:
                        Debug.Assert(false, "Invalid XmlOutputMethod setting.");
                        return null;
                }
            }
            else {
                // Otherwise, create a general-purpose writer than can do any encoding
                switch (settings.OutputMethod) {
                    case XmlOutputMethod.Xml:
                        if (settings.Indent) {
                            writer = new XmlEncodedRawTextWriterIndent(output, encoding, settings, closeOutput);
                        }
                        else {
                            writer = new XmlEncodedRawTextWriter(output, encoding, settings, closeOutput);
                        }
                        break;
                    case XmlOutputMethod.Html:
                        if (settings.Indent) {
                            writer = new HtmlEncodedRawTextWriterIndent(output, encoding, settings, closeOutput);
                        }
                        else {
                            writer = new HtmlEncodedRawTextWriter(output, encoding, settings, closeOutput);
                        }
                        break;
                    case XmlOutputMethod.Text:
                        writer = new TextEncodedRawTextWriter(output, encoding, settings, closeOutput);
                        break;
                    case XmlOutputMethod.AutoDetect:
                        writer = new XmlAutoDetectWriter(output, encoding, settings);
                        break;
                    default:
                        Debug.Assert(false, "Invalid XmlOutputMethod2 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 (settings.OutputMethod != XmlOutputMethod.AutoDetect) {
                if (settings.IsQuerySpecific) {
                    // Create QueryOutputWriter if CData sections or DocType need to be tracked
                    writer = new QueryOutputWriter((XmlRawWriter)writer, settings);
                }
            }

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

            return writer;
        }
        internal XmlWriter CreateWriter(Stream output)
        {
            XmlWriter writer;

            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (!(this.Encoding.WebName == "utf-8"))
            {
                switch (this.OutputMethod)
                {
                case XmlOutputMethod.Xml:
                    if (!this.Indent)
                    {
                        writer = new XmlEncodedRawTextWriter(output, this);
                    }
                    else
                    {
                        writer = new XmlEncodedRawTextWriterIndent(output, this);
                    }
                    goto Label_010B;

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

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

                case XmlOutputMethod.AutoDetect:
                    writer = new XmlAutoDetectWriter(output, this);
                    goto Label_010B;
                }
                return(null);
            }
            switch (this.OutputMethod)
            {
            case XmlOutputMethod.Xml:
                if (!this.Indent)
                {
                    writer = new XmlUtf8RawTextWriter(output, this);
                    break;
                }
                writer = new XmlUtf8RawTextWriterIndent(output, this);
                break;

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

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

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

            default:
                return(null);
            }
Label_010B:
            if ((this.OutputMethod != XmlOutputMethod.AutoDetect) && this.IsQuerySpecific)
            {
                writer = new QueryOutputWriter((XmlRawWriter)writer, this);
            }
            return(new XmlWellFormedWriter(writer, this));
        }
Пример #6
0
        private static XmlWriter CreateWriterImpl(Stream output, Encoding encoding, bool closeOutput, XmlWriterSettings settings)
        {
            Debug.Assert(output != null);
            Debug.Assert(encoding != null);
            Debug.Assert(settings != null);

            XmlWriter writer;

            if (encoding.CodePage == 65001)
            {
                // If the encoding is UTF-8, create a special-purpose writer
                switch (settings.OutputMethod)
                {
                case XmlOutputMethod.Xml:
                    if (settings.Indent)
                    {
                        writer = new XmlUtf8RawTextWriterIndent(output, encoding, settings, closeOutput);
                    }
                    else
                    {
                        writer = new XmlUtf8RawTextWriter(output, encoding, settings, closeOutput);
                    }
                    break;

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

                case XmlOutputMethod.Text:
                    writer = new TextUtf8RawTextWriter(output, encoding, settings, closeOutput);
                    break;

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

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

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

                case XmlOutputMethod.Text:
                    writer = new TextEncodedRawTextWriter(output, encoding, settings, closeOutput);
                    break;

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

                default:
                    Debug.Assert(false, "Invalid XmlOutputMethod2 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 (settings.OutputMethod != XmlOutputMethod.AutoDetect)
            {
                if (settings.IsQuerySpecific)
                {
                    // Create QueryOutputWriter if CData sections or DocType need to be tracked
                    writer = new QueryOutputWriter((XmlRawWriter)writer, settings);
                }
            }

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

            return(writer);
        }
Пример #7
0
        //
        // Internal properties
        //


        internal XmlWriter CreateWriter(Stream output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(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
                if (this.Indent)
                {
                    writer = new XmlUtf8RawTextWriterIndent(output, this);
                }
                else
                {
                    writer = new XmlUtf8RawTextWriter(output, this);
                }
            }
            else
            {
                // create raw writer for other encodings
                if (this.Indent)
                {
                    writer = new XmlEncodedRawTextWriterIndent(output, this);
                }
                else
                {
                    writer = new XmlEncodedRawTextWriter(output, this);
                }
            }

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

            if (_useAsync)
            {
                writer = new XmlAsyncCheckWriter(writer);
            }

            return writer;
        }