Exemplo n.º 1
0
        public QueryOutputWriter(XmlRawWriter writer, XmlWriterSettings settings)
        {
            _wrapped = writer;

            _systemId = settings.DocTypeSystem;
            _publicId = settings.DocTypePublic;

            if (settings.OutputMethod == XmlOutputMethod.Xml)
            {
                // Xml output method shouldn't output doc-type-decl if system ID is not defined (even if public ID is)
                // Only check for well-formed document if output method is xml
                if (_systemId != null)
                {
                    _outputDocType      = true;
                    _checkWellFormedDoc = true;
                }

                // Check for well-formed document if standalone="yes" in an auto-generated xml declaration
                if (settings.AutoXmlDeclaration && settings.Standalone == XmlStandalone.Yes)
                {
                    _checkWellFormedDoc = true;
                }

                if (settings.CDataSectionElements.Count > 0)
                {
                    _bitsCData        = new BitStack();
                    _lookupCDataElems = new Dictionary <XmlQualifiedName, int>();
                    _qnameCData       = new XmlQualifiedName();

                    // Add each element name to the lookup table
                    foreach (XmlQualifiedName name in settings.CDataSectionElements)
                    {
                        _lookupCDataElems[name] = 0;
                    }

                    _bitsCData.PushBit(false);
                }
            }
            else if (settings.OutputMethod == XmlOutputMethod.Html)
            {
                // Html output method should output doc-type-decl if system ID or public ID is defined
                if (_systemId != null || _publicId != null)
                {
                    _outputDocType = true;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Check well-formedness, possibly output doc-type-decl, and determine whether this element is a
        /// CData section element.
        /// </summary>
        public override void WriteStartElement(string prefix, string localName, string ns)
        {
            EndCDataSection();

            if (_checkWellFormedDoc)
            {
                // Don't allow multiple document elements
                if (_depth == 0 && _hasDocElem)
                {
                    throw new XmlException(ResXml.Xml_NoMultipleRoots, string.Empty);
                }

                _depth++;
                _hasDocElem = true;
            }

            // Output doc-type declaration immediately before first element is output
            if (_outputDocType)
            {
                _wrapped.WriteDocType(
                    prefix.Length != 0 ? prefix + ":" + localName : localName,
                    _publicId,
                    _systemId,
                    null);

                _outputDocType = false;
            }

            _wrapped.WriteStartElement(prefix, localName, ns);

            if (_lookupCDataElems != null)
            {
                // Determine whether this element is a CData section element
                _qnameCData.Init(localName, ns);
                _bitsCData.PushBit(_lookupCDataElems.ContainsKey(_qnameCData));
            }
        }