示例#1
0
 internal XDocumentType(XmlReader r)
 {
     this.name           = r.Name;
     this.publicId       = r.GetAttribute("PUBLIC");
     this.systemId       = r.GetAttribute("SYSTEM");
     this.internalSubset = r.Value;
     this.dtdInfo        = r.DtdInfo;
     r.Read();
 }
 internal XDocumentType(XmlReader r)
 {
     this.name = r.Name;
     this.publicId = r.GetAttribute("PUBLIC");
     this.systemId = r.GetAttribute("SYSTEM");
     this.internalSubset = r.Value;
     this.dtdInfo = r.DtdInfo;
     r.Read();
 }
示例#3
0
 private void ParseDtdFromParserContext()
 {
     if ((this.parserContext.DocTypeName != null) && (this.parserContext.DocTypeName.Length != 0))
     {
         IDtdParser parser = DtdParser.Create();
         XmlTextReaderImpl.DtdParserProxy adapter = new XmlTextReaderImpl.DtdParserProxy(this.coreReaderImpl);
         IDtdInfo newDtdInfo = parser.ParseFreeFloatingDtd(this.parserContext.BaseURI, this.parserContext.DocTypeName, this.parserContext.PublicId, this.parserContext.SystemId, this.parserContext.InternalSubset, adapter);
         this.coreReaderImpl.SetDtdInfo(newDtdInfo);
         this.ValidateDtd();
     }
 }
 public XDocumentType(XDocumentType other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     this.name = other.name;
     this.publicId = other.publicId;
     this.systemId = other.systemId;
     this.internalSubset = other.internalSubset;
     this.dtdInfo = other.dtdInfo;
 }
示例#5
0
 public XDocumentType(XDocumentType other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     this.name           = other.name;
     this.publicId       = other.publicId;
     this.systemId       = other.systemId;
     this.internalSubset = other.internalSubset;
     this.dtdInfo        = other.dtdInfo;
 }
示例#6
0
#pragma warning disable 618
        // Creates a XmlValidatingReader suitable for parsing InnerXml strings
        private XmlReader CreateInnerXmlReader(String xmlFragment, XmlNodeType nt, XmlParserContext context, XmlDocument doc)
        {
            XmlNodeType contentNT = nt;

            if (contentNT == XmlNodeType.Entity || contentNT == XmlNodeType.EntityReference)
            {
                contentNT = XmlNodeType.Element;
            }

            XmlTextReaderImpl tr = new XmlTextReaderImpl(xmlFragment, contentNT, context);

            tr.XmlValidatingReaderCompatibilityMode = true;
            if (doc.HasSetResolver)
            {
                tr.XmlResolver = doc.GetResolver();
            }
            if (!(doc.ActualLoadingStatus))
            {
                tr.DisableUndeclaredEntityCheck = true;
            }
            Debug.Assert(tr.EntityHandling == EntityHandling.ExpandCharEntities);

            XmlDocumentType dtdNode = doc.DocumentType;

            if (dtdNode != null)
            {
                tr.Namespaces = dtdNode.ParseWithNamespaces;
                if (dtdNode.DtdSchemaInfo != null)
                {
                    tr.SetDtdInfo(dtdNode.DtdSchemaInfo);
                }
                else
                {
                    IDtdParser dtdParser = DtdParser.Create();
                    XmlTextReaderImpl.DtdParserProxy proxy = new XmlTextReaderImpl.DtdParserProxy(tr);

                    IDtdInfo dtdInfo = dtdParser.ParseFreeFloatingDtd(context.BaseURI, context.DocTypeName, context.PublicId, context.SystemId, context.InternalSubset, proxy);

                    // TODO: Change all of XmlDocument to IDtdInfo interfaces
                    dtdNode.DtdSchemaInfo = dtdInfo as SchemaInfo;
                    tr.SetDtdInfo(dtdInfo);
                }
            }

            if (nt == XmlNodeType.Entity || nt == XmlNodeType.EntityReference)
            {
                tr.Read(); //this will skip the first element "wrapper"
                tr.ResolveEntity();
            }
            return(tr);
        }
示例#7
0
        private XmlReader CreateInnerXmlReader(string xmlFragment, XmlNodeType nt, XmlParserContext context, XmlDocument doc)
        {
            XmlNodeType fragType = nt;

            switch (fragType)
            {
            case XmlNodeType.Entity:
            case XmlNodeType.EntityReference:
                fragType = XmlNodeType.Element;
                break;
            }
            XmlTextReaderImpl reader = new XmlTextReaderImpl(xmlFragment, fragType, context)
            {
                XmlValidatingReaderCompatibilityMode = true
            };

            if (doc.HasSetResolver)
            {
                reader.XmlResolver = doc.GetResolver();
            }
            if (!doc.ActualLoadingStatus)
            {
                reader.DisableUndeclaredEntityCheck = true;
            }
            XmlDocumentType documentType = doc.DocumentType;

            if (documentType != null)
            {
                reader.Namespaces = documentType.ParseWithNamespaces;
                if (documentType.DtdSchemaInfo != null)
                {
                    reader.SetDtdInfo(documentType.DtdSchemaInfo);
                }
                else
                {
                    IDtdParser parser = DtdParser.Create();
                    XmlTextReaderImpl.DtdParserProxy adapter = new XmlTextReaderImpl.DtdParserProxy(reader);
                    IDtdInfo newDtdInfo = parser.ParseFreeFloatingDtd(context.BaseURI, context.DocTypeName, context.PublicId, context.SystemId, context.InternalSubset, adapter);
                    documentType.DtdSchemaInfo = newDtdInfo as SchemaInfo;
                    reader.SetDtdInfo(newDtdInfo);
                }
            }
            if ((nt == XmlNodeType.Entity) || (nt == XmlNodeType.EntityReference))
            {
                reader.Read();
                reader.ResolveEntity();
            }
            return(reader);
        }
 public void CreateIdTables(IDtdInfo dtdInfo)
 {
     foreach (IDtdAttributeListInfo info in dtdInfo.GetAttributeLists())
     {
         IDtdAttributeInfo idAttribute = info.LookupIdAttribute();
         if (idAttribute != null)
         {
             if (this.elemIdMap == null)
             {
                 this.elemIdMap = new Hashtable();
             }
             this.elemIdMap.Add(new XmlQualifiedName(info.LocalName, info.Prefix), new XmlQualifiedName(idAttribute.LocalName, idAttribute.Prefix));
         }
     }
 }
        //
        // Private implementation methods
        //

        private async Task ParseDtdFromParserContextAsync()
        {
            Debug.Assert(_parserContext != null);
            Debug.Assert(_coreReaderImpl.DtdInfo == null);

            if (_parserContext.DocTypeName == null || _parserContext.DocTypeName.Length == 0)
            {
                return;
            }

            IDtdParser dtdParser = DtdParser.Create();

            XmlTextReaderImpl.DtdParserProxy proxy = new XmlTextReaderImpl.DtdParserProxy(_coreReaderImpl);
            IDtdInfo dtdInfo = await dtdParser.ParseFreeFloatingDtdAsync(_parserContext.BaseURI, _parserContext.DocTypeName, _parserContext.PublicId, _parserContext.SystemId, _parserContext.InternalSubset, proxy).ConfigureAwait(false);

            _coreReaderImpl.SetDtdInfo(dtdInfo);

            ValidateDtd();
        }
示例#10
0
        private void ParseDocumentType(XmlDocumentType dtNode, bool bUseResolver, XmlResolver resolver)
        {
            this.doc = dtNode.OwnerDocument;
            XmlParserContext  context = new XmlParserContext(null, new XmlNamespaceManager(this.doc.NameTable), null, null, null, null, this.doc.BaseURI, string.Empty, XmlSpace.None);
            XmlTextReaderImpl reader  = new XmlTextReaderImpl("", XmlNodeType.Element, context)
            {
                Namespaces = dtNode.ParseWithNamespaces
            };

            if (bUseResolver)
            {
                reader.XmlResolver = resolver;
            }
            IDtdParser parser = DtdParser.Create();

            XmlTextReaderImpl.DtdParserProxy adapter = new XmlTextReaderImpl.DtdParserProxy(reader);
            IDtdInfo dtdInfo = parser.ParseFreeFloatingDtd(this.doc.BaseURI, dtNode.Name, dtNode.PublicId, dtNode.SystemId, dtNode.InternalSubset, adapter);

            this.LoadDocumentType(dtdInfo, dtNode);
        }
示例#11
0
        //-----------------------------------------------
        // Custom Build Helper Methods
        //-----------------------------------------------

        /// <summary>
        /// Build ID lookup tables from the XSD schema or DTD.
        /// </summary>
        public void CreateIdTables(IDtdInfo dtdInfo)
        {
            // Extract the elements which has attribute defined as ID from the element declarations
            foreach (IDtdAttributeListInfo attrList in dtdInfo.GetAttributeLists())
            {
                IDtdAttributeInfo idAttribute = attrList.LookupIdAttribute();
                if (idAttribute != null)
                {
                    if (_elemIdMap == null)
                    {
                        _elemIdMap = new Hashtable();
                    }

                    // Id was defined in DTD and DTD doesn't have notion of namespace so we should
                    // use prefix instead of namespace here.  Schema already does this for us.
                    _elemIdMap.Add(new XmlQualifiedName(attrList.LocalName, attrList.Prefix),
                                   new XmlQualifiedName(idAttribute.LocalName, idAttribute.Prefix));
                }
            }
        }
//
// Private implementation methods
//

        private void ParseDtdFromParserContext()
        {
            Debug.Assert(parserContext != null);
            Debug.Assert(coreReaderImpl.DtdInfo == null);

            if (parserContext.DocTypeName == null || parserContext.DocTypeName.Length == 0)
            {
                return;
            }

            IDtdParser dtdParser = DtdParser.Create();

            XmlTextReaderImpl.DtdParserProxy proxy = new XmlTextReaderImpl.DtdParserProxy(coreReaderImpl);
            IDtdInfo dtdInfo = dtdParser.ParseFreeFloatingDtd(parserContext.BaseURI, parserContext.DocTypeName, parserContext.PublicId,
                                                              parserContext.SystemId, parserContext.InternalSubset, proxy);

            coreReaderImpl.SetDtdInfo(dtdInfo);

            ValidateDtd();
        }
示例#13
0
        private void ParseDocumentType(XmlDocumentType dtNode, bool bUseResolver, XmlResolver resolver)
        {
            _doc = dtNode.OwnerDocument;
            XmlParserContext  pc = new XmlParserContext(null, new XmlNamespaceManager(_doc.NameTable), null, null, null, null, _doc.BaseURI, string.Empty, XmlSpace.None);
            XmlTextReaderImpl tr = new XmlTextReaderImpl("", XmlNodeType.Element, pc);

            tr.Namespaces = dtNode.ParseWithNamespaces;
            if (bUseResolver)
            {
                tr.XmlResolver = resolver;
            }

            IDtdParser dtdParser = DtdParser.Create();

            XmlTextReaderImpl.DtdParserProxy proxy = new XmlTextReaderImpl.DtdParserProxy(tr);

            IDtdInfo dtdInfo = dtdParser.ParseFreeFloatingDtd(_doc.BaseURI, dtNode.Name, dtNode.PublicId, dtNode.SystemId, dtNode.InternalSubset, proxy);

            LoadDocumentType(dtdInfo, dtNode);
        }
        private void ValidateDtd()
        {
            IDtdInfo dtdInfo = coreReaderImpl.DtdInfo;

            if (dtdInfo != null)
            {
                switch (validationType)
                {
#pragma warning disable 618
                case ValidationType.Auto:
                    SetupValidation(ValidationType.DTD);
                    goto case ValidationType.DTD;

#pragma warning restore 618
                case ValidationType.DTD:
                case ValidationType.None:
                    validator.DtdInfo = dtdInfo;
                    break;
                }
            }
        }
示例#15
0
        private XmlDocumentType LoadDocumentTypeNode()
        {
            string publicId       = null;
            string systemId       = null;
            string internalSubset = this.reader.Value;
            string localName      = this.reader.LocalName;

            while (this.reader.MoveToNextAttribute())
            {
                string name = this.reader.Name;
                if (name != null)
                {
                    if (!(name == "PUBLIC"))
                    {
                        if (name == "SYSTEM")
                        {
                            goto Label_005A;
                        }
                    }
                    else
                    {
                        publicId = this.reader.Value;
                    }
                }
                continue;
Label_005A:
                systemId = this.reader.Value;
            }
            XmlDocumentType dtNode  = this.doc.CreateDocumentType(localName, publicId, systemId, internalSubset);
            IDtdInfo        dtdInfo = this.reader.DtdInfo;

            if (dtdInfo != null)
            {
                this.LoadDocumentType(dtdInfo, dtNode);
                return(dtNode);
            }
            this.ParseDocumentType(dtNode);
            return(dtNode);
        }
示例#16
0
        private XmlDocumentType LoadDocumentTypeNode()
        {
            Debug.Assert(_reader.NodeType == XmlNodeType.DocumentType);

            String publicId       = null;
            String systemId       = null;
            String internalSubset = _reader.Value;
            String localName      = _reader.LocalName;

            while (_reader.MoveToNextAttribute())
            {
                switch (_reader.Name)
                {
                case "PUBLIC":
                    publicId = _reader.Value;
                    break;

                case "SYSTEM":
                    systemId = _reader.Value;
                    break;
                }
            }

            XmlDocumentType dtNode = _doc.CreateDocumentType(localName, publicId, systemId, internalSubset);

            IDtdInfo dtdInfo = _reader.DtdInfo;

            if (dtdInfo != null)
            {
                LoadDocumentType(dtdInfo, dtNode);
            }
            else
            {
                //construct our own XmlValidatingReader to parse the DocumentType node so we could get Entities and notations information
                ParseDocumentType(dtNode);
            }

            return(dtNode);
        }
示例#17
0
        private void ValidateDtd()
        {
            IDtdInfo dtdInfo = this.coreReaderImpl.DtdInfo;

            if (dtdInfo != null)
            {
                switch (this.validationType)
                {
                case System.Xml.ValidationType.None:
                case System.Xml.ValidationType.DTD:
                    break;

                case System.Xml.ValidationType.Auto:
                    this.SetupValidation(System.Xml.ValidationType.DTD);
                    break;

                default:
                    return;
                }
                this.validator.DtdInfo = dtdInfo;
            }
        }
示例#18
0
        /// <summary>
        /// Create a writer that can be used to create nodes in this document.  The root node will be assigned "baseUri", and flags
        /// can be passed to indicate that names should be atomized by the builder and/or a fragment should be created.
        /// </summary>
        internal void LoadFromReader(XmlReader reader, XmlSpace space)
        {
            XPathDocumentBuilder builder;
            IXmlLineInfo         lineInfo;
            string xmlnsUri;
            bool   topLevelReader;
            int    initialDepth;

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

            // Determine line number provider
            lineInfo = reader as IXmlLineInfo;
            if (lineInfo == null || !lineInfo.HasLineInfo())
            {
                lineInfo = null;
            }
            _hasLineInfo = (lineInfo != null);

            _nameTable = reader.NameTable;
            builder    = new XPathDocumentBuilder(this, lineInfo, reader.BaseURI, LoadFlags.None);

            try
            {
                // Determine whether reader is in initial state
                topLevelReader = (reader.ReadState == ReadState.Initial);
                initialDepth   = reader.Depth;

                // Get atomized xmlns uri
                Debug.Assert((object)_nameTable.Get(string.Empty) == (object)string.Empty, "NameTable must contain atomized string.Empty");
                xmlnsUri = _nameTable.Get(XmlReservedNs.NsXmlNs);

                // Read past Initial state; if there are no more events then load is complete
                if (topLevelReader && !reader.Read())
                {
                    return;
                }

                // Read all events
                do
                {
                    // If reader began in intermediate state, return when all siblings have been read
                    if (!topLevelReader && reader.Depth < initialDepth)
                    {
                        return;
                    }

                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                    {
                        bool isEmptyElement = reader.IsEmptyElement;

                        builder.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.BaseURI);

                        // Add attribute and namespace nodes to element
                        while (reader.MoveToNextAttribute())
                        {
                            string namespaceUri = reader.NamespaceURI;

                            if ((object)namespaceUri == (object)xmlnsUri)
                            {
                                if (reader.Prefix.Length == 0)
                                {
                                    // Default namespace declaration "xmlns"
                                    Debug.Assert(reader.LocalName == "xmlns");
                                    builder.WriteNamespaceDeclaration(string.Empty, reader.Value);
                                }
                                else
                                {
                                    Debug.Assert(reader.Prefix == "xmlns");
                                    builder.WriteNamespaceDeclaration(reader.LocalName, reader.Value);
                                }
                            }
                            else
                            {
                                builder.WriteStartAttribute(reader.Prefix, reader.LocalName, namespaceUri);
                                builder.WriteString(reader.Value, TextBlockType.Text);
                                builder.WriteEndAttribute();
                            }
                        }

                        if (isEmptyElement)
                        {
                            builder.WriteEndElement(true);
                        }
                        break;
                    }

                    case XmlNodeType.EndElement:
                        builder.WriteEndElement(false);
                        break;

                    case XmlNodeType.Text:
                    case XmlNodeType.CDATA:
                        builder.WriteString(reader.Value, TextBlockType.Text);
                        break;

                    case XmlNodeType.SignificantWhitespace:
                        if (reader.XmlSpace == XmlSpace.Preserve)
                        {
                            builder.WriteString(reader.Value, TextBlockType.SignificantWhitespace);
                        }
                        else
                        {
                            // Significant whitespace without xml:space="preserve" is not significant in XPath/XQuery data model
                            goto case XmlNodeType.Whitespace;
                        }
                        break;

                    case XmlNodeType.Whitespace:
                        // We intentionally ignore the reader.XmlSpace property here and blindly trust
                        //   the reported node type. If the reported information is not in sync
                        //   (in this case if the reader.XmlSpace == Preserve) then we make the choice
                        //   to trust the reported node type. Since we have no control over the input reader
                        //   we can't even assert here.

                        // Always filter top-level whitespace
                        if (space == XmlSpace.Preserve && (!topLevelReader || reader.Depth != 0))
                        {
                            builder.WriteString(reader.Value, TextBlockType.Whitespace);
                        }
                        break;

                    case XmlNodeType.Comment:
                        builder.WriteComment(reader.Value);
                        break;

                    case XmlNodeType.ProcessingInstruction:
                        builder.WriteProcessingInstruction(reader.LocalName, reader.Value, reader.BaseURI);
                        break;

                    case XmlNodeType.EntityReference:
                        reader.ResolveEntity();
                        break;

                    case XmlNodeType.DocumentType:
                        // Create ID tables
                        IDtdInfo info = reader.DtdInfo;
                        if (info != null)
                        {
                            builder.CreateIdTables(info);
                        }
                        break;

                    case XmlNodeType.EndEntity:
                    case XmlNodeType.None:
                    case XmlNodeType.XmlDeclaration:
                        break;
                    }
                }while (reader.Read());
            }
            finally
            {
                builder.Close();
            }
        }
示例#19
0
        //-----------------------------------------------
        // Custom Build Helper Methods
        //-----------------------------------------------

        /// <summary>
        /// Build ID lookup tables from the XSD schema or DTD.
        /// </summary>
        public void CreateIdTables(IDtdInfo dtdInfo)
        {
            // Extract the elements which has attribute defined as ID from the element declarations
            foreach (IDtdAttributeListInfo attrList in dtdInfo.GetAttributeLists())
            {
                IDtdAttributeInfo idAttribute = attrList.LookupIdAttribute();
                if (idAttribute != null)
                {
                    if (_elemIdMap == null)
                        _elemIdMap = new Hashtable();

                    // Id was defined in DTD and DTD doesn't have notion of namespace so we should
                    // use prefix instead of namespace here.  Schema already does this for us.
                    _elemIdMap.Add(new XmlQualifiedName(attrList.LocalName, attrList.Prefix),
                                       new XmlQualifiedName(idAttribute.LocalName, idAttribute.Prefix));
                }
            }
        }
示例#20
0
 internal void SetDtdSchemaInfo(IDtdInfo dtdSchemaInfo)
 {
     _dtdSchemaInfo = dtdSchemaInfo;
     _checkEntity = true;
 }
示例#21
0
        internal void SetDtdInfo(IDtdInfo newDtdInfo)
        {
            Debug.Assert(_dtdInfo == null);

            _dtdInfo = newDtdInfo;
            if (_dtdInfo != null)
            {
                if ((_validatingReaderCompatFlag || !_v1Compat) && (_dtdInfo.HasDefaultAttributes || _dtdInfo.HasNonCDataAttributes))
                {
                    _addDefaultAttributesAndNormalize = true;
                }
            }
        }
示例#22
0
        private void ParseDtdFromParserContext()
        {
            Debug.Assert(_dtdInfo == null && _fragmentParserContext != null && _fragmentParserContext.HasDtdInfo);

            IDtdParser dtdParser = DtdParser.Create();

            // Parse DTD
            _dtdInfo = dtdParser.ParseFreeFloatingDtd(_fragmentParserContext.BaseURI, _fragmentParserContext.DocTypeName, _fragmentParserContext.PublicId,
                                                     _fragmentParserContext.SystemId, _fragmentParserContext.InternalSubset, new DtdParserProxy(this));

            if ((_validatingReaderCompatFlag || !_v1Compat) && (_dtdInfo.HasDefaultAttributes || _dtdInfo.HasNonCDataAttributes))
            {
                _addDefaultAttributesAndNormalize = true;
            }
        }
示例#23
0
        private void ParseDtd()
        {
            IDtdParser dtdParser = DtdParser.Create();

            _dtdInfo = dtdParser.ParseInternalDtd(new DtdParserProxy(this), true);

            if ((_validatingReaderCompatFlag || !_v1Compat) && (_dtdInfo.HasDefaultAttributes || _dtdInfo.HasNonCDataAttributes))
            {
                _addDefaultAttributesAndNormalize = true;
            }

            _curNode.SetNamedNode(XmlNodeType.DocumentType, _dtdInfo.Name.ToString(), string.Empty, null);
            _curNode.SetValue(_dtdInfo.InternalDtdSubset);
        }
示例#24
0
        private void ParseDtdFromParserContext() {
            Debug.Assert( dtdInfo == null && fragmentParserContext != null && fragmentParserContext.HasDtdInfo );

            IDtdParser dtdParser = DtdParser.Create();

            // Parse DTD
            dtdInfo = dtdParser.ParseFreeFloatingDtd(fragmentParserContext.BaseURI, fragmentParserContext.DocTypeName, fragmentParserContext.PublicId,
                                                     fragmentParserContext.SystemId, fragmentParserContext.InternalSubset, new DtdParserProxy( this ) );

#if SILVERLIGHT // Needed only for XmlTextReader or XmlValidatingReader
            if (dtdInfo.HasDefaultAttributes || dtdInfo.HasNonCDataAttributes) {
#else
            if ( ( validatingReaderCompatFlag || !v1Compat ) && ( dtdInfo.HasDefaultAttributes || dtdInfo.HasNonCDataAttributes ) ) {
#endif
                addDefaultAttributesAndNormalize = true;
            }
        }

        bool InitReadContentAsBinary() {
            Debug.Assert( parsingFunction != ParsingFunction.InReadContentAsBinary );

            if ( parsingFunction == ParsingFunction.InReadValueChunk ) {
                throw new InvalidOperationException( Res.GetString( Res.Xml_MixingReadValueChunkWithBinary ) );
            }
            if ( parsingFunction == ParsingFunction.InIncrementalRead ) {
                throw new InvalidOperationException( Res.GetString( Res.Xml_MixingV1StreamingWithV2Binary ) );
            }

            if ( !XmlReader.IsTextualNode( curNode.type ) ) {
                if ( !MoveToNextContentNode( false ) ) {
                    return false;
                }
            }

            SetupReadContentAsBinaryState( ParsingFunction.InReadContentAsBinary );
            incReadLineInfo.Set( curNode.LineNo, curNode.LinePos );
            return true;
        }

        bool InitReadElementContentAsBinary() {
            Debug.Assert( parsingFunction != ParsingFunction.InReadElementContentAsBinary );
            Debug.Assert( curNode.type == XmlNodeType.Element );

            bool isEmpty = curNode.IsEmptyElement;

            // move to content or off the empty element
            outerReader.Read();
            if ( isEmpty ) {
                return false;
            }

            // make sure we are on a content node
            if ( !MoveToNextContentNode( false ) ) {
                if ( curNode.type != XmlNodeType.EndElement ) {
                    Throw( Res.Xml_InvalidNodeType, curNode.type.ToString() );
                }
                // move off end element
                outerReader.Read();
                return false;
            }
            SetupReadContentAsBinaryState( ParsingFunction.InReadElementContentAsBinary );
            incReadLineInfo.Set( curNode.LineNo, curNode.LinePos );
            return true;
        }

        bool MoveToNextContentNode( bool moveIfOnContentNode ) {
            do {
                switch ( curNode.type ) {
                    case XmlNodeType.Attribute:
                        return !moveIfOnContentNode;
                    case XmlNodeType.Text:
                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                    case XmlNodeType.CDATA:
                        if ( !moveIfOnContentNode ) {
                            return true;
                        }
                        break;
                    case XmlNodeType.ProcessingInstruction:
                    case XmlNodeType.Comment:
                    case XmlNodeType.EndEntity:
                        // skip comments, pis and end entity nodes
                        break;
                    case XmlNodeType.EntityReference:
                        outerReader.ResolveEntity();
                        break;
                    default:
                        return false;
                }
                moveIfOnContentNode = false;
            } while ( outerReader.Read() );
            return false;
        }

        void SetupReadContentAsBinaryState( ParsingFunction inReadBinaryFunction ) {
            if ( parsingFunction == ParsingFunction.PartialTextValue ) {
                incReadState = IncrementalReadState.ReadContentAsBinary_OnPartialValue;
            }
            else {
                incReadState = IncrementalReadState.ReadContentAsBinary_OnCachedValue;
                nextNextParsingFunction = nextParsingFunction;
                nextParsingFunction = parsingFunction;
            }
            readValueOffset = 0;
            parsingFunction = inReadBinaryFunction;
        }

        void SetupFromParserContext( XmlParserContext context, XmlReaderSettings settings ) {
            Debug.Assert( context != null );

            // setup nameTable
            XmlNameTable nt = settings.NameTable;
            nameTableFromSettings = ( nt != null );

            // get name table from namespace manager in XmlParserContext, if available; 
            if ( context.NamespaceManager != null ) {
                // must be the same as XmlReaderSettings.NameTable, or null
                if ( nt != null && nt != context.NamespaceManager.NameTable ) {
                    throw new XmlException( Res.Xml_NametableMismatch );
                }
                // get the namespace manager from context
                namespaceManager = context.NamespaceManager;
                xmlContext.defaultNamespace = namespaceManager.LookupNamespace( string.Empty );

                // get the nametable from ns manager
                nt = namespaceManager.NameTable;

                Debug.Assert( nt != null );
                Debug.Assert( context.NameTable == null || context.NameTable == nt, "This check should have been done in XmlParserContext constructor." );
            } 
            // get name table directly from XmlParserContext
            else if ( context.NameTable != null ) {
                // must be the same as XmlReaderSettings.NameTable, or null
                if ( nt != null && nt != context.NameTable ) {
                    throw new XmlException( Res.Xml_NametableMismatch, string.Empty );
                }
                nt = context.NameTable;
            }
            // no nametable provided -> create a new one
            else if ( nt == null ) {
                nt = new NameTable();
                Debug.Assert( nameTableFromSettings == false );
            }
            nameTable = nt;

            // make sure we have namespace manager
            if ( namespaceManager == null ) {
                namespaceManager = new XmlNamespaceManager( nt );
            }

            // copy xml:space and xml:lang
            xmlContext.xmlSpace = context.XmlSpace;
            xmlContext.xmlLang = context.XmlLang;
        }
示例#25
0
        private void ParseDtd() {
            IDtdParser dtdParser = DtdParser.Create();

            dtdInfo = dtdParser.ParseInternalDtd(new DtdParserProxy(this), true);

#if SILVERLIGHT // Needed only for XmlTextReader and XmlValidatingReader
            if (dtdInfo.HasDefaultAttributes || dtdInfo.HasNonCDataAttributes) {
#else
                if ( ( validatingReaderCompatFlag || !v1Compat ) && ( dtdInfo.HasDefaultAttributes || dtdInfo.HasNonCDataAttributes ) ) {
#endif
                addDefaultAttributesAndNormalize = true;
            }

            curNode.SetNamedNode(XmlNodeType.DocumentType, dtdInfo.Name.ToString(), string.Empty, null);
            curNode.SetValue(dtdInfo.InternalDtdSubset);
        }

        private void SkipDtd() {
            int colonPos;

            // parse dtd name
            int pos = ParseQName( out colonPos );
            ps.charPos = pos;

            // check whitespace
            EatWhitespaces( null );

            // PUBLIC Id
            if ( ps.chars[ps.charPos] == 'P' ) {
                // make sure we have enough characters
                while ( ps.charsUsed - ps.charPos < 6 ) {
                    if ( ReadData() == 0 ) {
                        Throw( Res.Xml_UnexpectedEOF1 );
                    }
                }
                // check 'PUBLIC'
                if ( !XmlConvert.StrEqual( ps.chars, ps.charPos, 6, "PUBLIC" ) ) {
                    ThrowUnexpectedToken( "PUBLIC" );
                }   
                ps.charPos += 6;

                // check whitespace
                if ( EatWhitespaces( null ) == 0 ) {
                    ThrowExpectingWhitespace( ps.charPos );
                }

                // parse PUBLIC value
                SkipPublicOrSystemIdLiteral();

                // check whitespace
                if ( EatWhitespaces( null ) == 0 ) {
                    ThrowExpectingWhitespace( ps.charPos );
                }

                // parse SYSTEM value
                SkipPublicOrSystemIdLiteral();

                EatWhitespaces( null );
            }
            else if ( ps.chars[ps.charPos] == 'S' ) {
                // make sure we have enough characters
                while ( ps.charsUsed - ps.charPos < 6 ) {
                    if ( ReadData() == 0 ) {
                        Throw( Res.Xml_UnexpectedEOF1 );
                    }
                }
                // check 'SYSTEM'
                if ( !XmlConvert.StrEqual( ps.chars, ps.charPos, 6, "SYSTEM" ) ) {
                    ThrowUnexpectedToken( "SYSTEM" );
                }   
                ps.charPos += 6;

                // check whitespace
                if ( EatWhitespaces( null ) == 0 ) {
                    ThrowExpectingWhitespace( ps.charPos );
                }

                // parse SYSTEM value
                SkipPublicOrSystemIdLiteral();

                EatWhitespaces( null );
            }
            else if ( ps.chars[ps.charPos] != '[' && ps.chars[ps.charPos] != '>' ) {
                Throw(Res.Xml_ExpectExternalOrClose);
            }

            // internal DTD
            if ( ps.chars[ps.charPos] == '[' ) {
                ps.charPos++;

                SkipUntil( ']', true );

                EatWhitespaces( null );
                if ( ps.chars[ps.charPos] != '>' ) {
                    ThrowUnexpectedToken( ">" );
                }
            }
            else if ( ps.chars[ps.charPos] == '>' ) {
                curNode.SetValue( string.Empty );
            }
            else {
                Throw( Res.Xml_ExpectSubOrClose );
            }
            ps.charPos++;
        }

        void SkipPublicOrSystemIdLiteral() {
            // check quote char
            char quoteChar = ps.chars[ps.charPos];
            if ( quoteChar != '"' && quoteChar != '\'' ) {
                ThrowUnexpectedToken( "\"", "'" );
            }

            ps.charPos++;
            SkipUntil( quoteChar, false );
        }

        void SkipUntil( char stopChar, bool recognizeLiterals ) {
            bool inLiteral = false;
            bool inComment = false;
            bool inPI = false;
            char literalQuote = '"';

            char[] chars = ps.chars;
            int pos = ps.charPos;

            for (; ; ) {
                char ch;

#if SILVERLIGHT
                while ( xmlCharType.IsAttributeValueChar( ch = chars[pos] ) && ch != stopChar && ch != '-' && ch != '?') {
                    pos++;
                }
#else // Optimization due to the lack of inlining when a method uses byte*
                unsafe {
                    while ( ( ( xmlCharType.charProperties[ch = chars[pos]] & XmlCharType.fAttrValue ) != 0 ) && chars[pos] != stopChar && ch != '-' && ch != '?') {
                        pos++;
                    }
                }
#endif

                // closing stopChar outside of literal and ignore/include sections -> save value & return
                if ( ch == stopChar && !inLiteral ) {
                    ps.charPos = pos + 1;
                    return;
                }

                // handle the special character
                ps.charPos = pos;
                switch ( ch ) {
                    // eol
                    case (char)0xA:
                        pos++;
                        OnNewLine( pos );
                        continue;
                    case (char)0xD:
                        if ( chars[pos+1] == (char)0xA ) {
                            pos += 2;
                        }
                        else if ( pos+1 < ps.charsUsed || ps.isEof ) { 
                            pos++;
                        } 
                        else {
                            goto ReadData;
                        }
                        OnNewLine( pos );
                        continue;

                    // comment, PI
                    case '<':
                        // processing instruction
                        if ( chars[pos + 1] == '?' ) {
                            if ( recognizeLiterals && !inLiteral && !inComment ) {
                                inPI = true;
                                pos += 2;
                                continue;
                            }
                        }
                        // comment
                        else if ( chars[pos + 1] == '!' ) {
                            if ( pos + 3 >= ps.charsUsed && !ps.isEof ) {
                                goto ReadData;
                            }
                            if ( chars[pos+2] == '-' && chars[pos+3] == '-' ) {
                                if ( recognizeLiterals && !inLiteral && !inPI ) {
                                    inComment = true;
                                    pos += 4;
                                    continue;
                                }
                            }
                        }
                        // need more data
                        else if ( pos + 1 >= ps.charsUsed && !ps.isEof ) {
                            goto ReadData;
                        }
                        pos++;
                        continue;
                    case '-':
                        // end of comment
                        if ( inComment ) {
                            if ( pos + 2 >= ps.charsUsed && !ps.isEof ) {
                                goto ReadData;
                            }
                            if ( chars[pos + 1] == '-' && chars[pos + 2] == '>' ) {
                                inComment = false;
                                pos += 2;
                                continue;
                            }
                        }
                        pos++;
                        continue;

                    case '?':
                        // end of processing instruction
                        if (inPI) {
                            if (pos + 1 >= ps.charsUsed && !ps.isEof) {
                                goto ReadData;
                            }
                            if (chars[pos + 1] == '>') {
                                inPI = false;
                                pos += 1;
                                continue;
                            }
                        }
                        pos++;
                        continue;

                    case (char)0x9:
                    case '>':
                    case ']':
                    case '&':
                        pos++;
                        continue;
                    case '"':
                    case '\'':
                        if ( inLiteral ) {
                            if ( literalQuote == ch ) {
                                inLiteral = false;
                            }
                        }
                        else {
                            if ( recognizeLiterals && !inComment && !inPI ) {
                                inLiteral = true;
                                literalQuote = ch;
                            }
                        }
                        pos++;
                        continue;
                    default:
                        // end of buffer
                        if ( pos == ps.charsUsed ) {
                            goto ReadData;
                        }
                        // surrogate chars
                        else { 
                            char tmpCh = chars[pos];
                            if ( XmlCharType.IsHighSurrogate( tmpCh ) ) {
                                if ( pos + 1 == ps.charsUsed ) {
                                    goto ReadData;
                                }
                                pos++;
                                if ( XmlCharType.IsLowSurrogate( chars[pos] ) ) {
                                    pos++;
                                    continue;
                                }
                            }
                            ThrowInvalidChar( chars, ps.charsUsed, pos );
                            break;
                        }
                }
            
            ReadData:
                // read new characters into the buffer
                if ( ReadData() == 0 ) {
                    if ( ps.charsUsed - ps.charPos > 0 ) {
                        if ( ps.chars[ps.charPos] != (char)0xD ) {
                            Debug.Assert( false, "We should never get to this point." );
                            Throw( Res.Xml_UnexpectedEOF1 );
                        }
                        Debug.Assert( ps.isEof );
                    }
                    else {
                        Throw( Res.Xml_UnexpectedEOF1 );
                    }
                }
                chars = ps.chars;
                pos = ps.charPos;
            }
        }
 internal void SetDtdSchemaInfo(IDtdInfo dtdSchemaInfo)
 {
     this.dtdSchemaInfo = dtdSchemaInfo;
     this.checkEntity = true;
 }
 public void CreateIdTables(IDtdInfo dtdInfo)
 {
     foreach (IDtdAttributeListInfo info in dtdInfo.GetAttributeLists())
     {
         IDtdAttributeInfo idAttribute = info.LookupIdAttribute();
         if (idAttribute != null)
         {
             if (this.elemIdMap == null)
             {
                 this.elemIdMap = new Hashtable();
             }
             this.elemIdMap.Add(new XmlQualifiedName(info.LocalName, info.Prefix), new XmlQualifiedName(idAttribute.LocalName, idAttribute.Prefix));
         }
     }
 }
示例#28
0
        private void LoadDocumentType(IDtdInfo dtdInfo, XmlDocumentType dtNode)
        {
            SchemaInfo schInfo = dtdInfo as SchemaInfo;
            if (schInfo == null)
            {
                throw new XmlException(SR.Xml_InternalError, string.Empty);
            }

            dtNode.DtdSchemaInfo = schInfo;
            if (schInfo != null)
            {
                //set the schema information into the document
                _doc.DtdSchemaInfo = schInfo;

                // Notation hashtable
                if (schInfo.Notations != null)
                {
                    foreach (SchemaNotation scNot in schInfo.Notations.Values)
                    {
                        dtNode.Notations.SetNamedItem(new XmlNotation(scNot.Name.Name, scNot.Pubid, scNot.SystemLiteral, _doc));
                    }
                }

                // Entity hashtables
                if (schInfo.GeneralEntities != null)
                {
                    foreach (SchemaEntity scEnt in schInfo.GeneralEntities.Values)
                    {
                        XmlEntity ent = new XmlEntity(scEnt.Name.Name, scEnt.Text, scEnt.Pubid, scEnt.Url, scEnt.NData.IsEmpty ? null : scEnt.NData.Name, _doc);
                        ent.SetBaseURI(scEnt.DeclaredURI);
                        dtNode.Entities.SetNamedItem(ent);
                    }
                }

                if (schInfo.ParameterEntities != null)
                {
                    foreach (SchemaEntity scEnt in schInfo.ParameterEntities.Values)
                    {
                        XmlEntity ent = new XmlEntity(scEnt.Name.Name, scEnt.Text, scEnt.Pubid, scEnt.Url, scEnt.NData.IsEmpty ? null : scEnt.NData.Name, _doc);
                        ent.SetBaseURI(scEnt.DeclaredURI);
                        dtNode.Entities.SetNamedItem(ent);
                    }
                }
                _doc.Entities = dtNode.Entities;

                //extract the elements which has attribute defined as ID from the element declarations
                IDictionaryEnumerator elementDecls = schInfo.ElementDecls.GetEnumerator();
                if (elementDecls != null)
                {
                    elementDecls.Reset();
                    while (elementDecls.MoveNext())
                    {
                        SchemaElementDecl elementDecl = (SchemaElementDecl)elementDecls.Value;
                        if (elementDecl.AttDefs != null)
                        {
                            IDictionaryEnumerator attDefs = elementDecl.AttDefs.GetEnumerator();
                            while (attDefs.MoveNext())
                            {
                                SchemaAttDef attdef = (SchemaAttDef)attDefs.Value;
                                if (attdef.Datatype.TokenizedType == XmlTokenizedType.ID)
                                {
                                    //we only register the XmlElement based on their Prefix/LocalName and skip the namespace
                                    _doc.AddIdInfo(
                                        _doc.AddXmlName(elementDecl.Prefix, elementDecl.Name.Name, string.Empty, null),
                                        _doc.AddAttrXmlName(attdef.Prefix, attdef.Name.Name, string.Empty, null));
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#29
0
        private void LoadDocumentType(IDtdInfo dtdInfo, XmlDocumentType dtNode)
        {
            SchemaInfo info = dtdInfo as SchemaInfo;

            if (info == null)
            {
                throw new XmlException("Xml_InternalError", string.Empty);
            }
            dtNode.DtdSchemaInfo = info;
            if (info != null)
            {
                this.doc.DtdSchemaInfo = info;
                if (info.Notations != null)
                {
                    foreach (SchemaNotation notation in info.Notations.Values)
                    {
                        dtNode.Notations.SetNamedItem(new XmlNotation(notation.Name.Name, notation.Pubid, notation.SystemLiteral, this.doc));
                    }
                }
                if (info.GeneralEntities != null)
                {
                    foreach (SchemaEntity entity in info.GeneralEntities.Values)
                    {
                        XmlEntity node = new XmlEntity(entity.Name.Name, entity.Text, entity.Pubid, entity.Url, entity.NData.IsEmpty ? null : entity.NData.Name, this.doc);
                        node.SetBaseURI(entity.DeclaredURI);
                        dtNode.Entities.SetNamedItem(node);
                    }
                }
                if (info.ParameterEntities != null)
                {
                    foreach (SchemaEntity entity3 in info.ParameterEntities.Values)
                    {
                        XmlEntity entity4 = new XmlEntity(entity3.Name.Name, entity3.Text, entity3.Pubid, entity3.Url, entity3.NData.IsEmpty ? null : entity3.NData.Name, this.doc);
                        entity4.SetBaseURI(entity3.DeclaredURI);
                        dtNode.Entities.SetNamedItem(entity4);
                    }
                }
                this.doc.Entities = dtNode.Entities;
                IDictionaryEnumerator enumerator = info.ElementDecls.GetEnumerator();
                if (enumerator != null)
                {
                    enumerator.Reset();
                    while (enumerator.MoveNext())
                    {
                        SchemaElementDecl decl = (SchemaElementDecl)enumerator.Value;
                        if (decl.AttDefs != null)
                        {
                            IDictionaryEnumerator enumerator2 = decl.AttDefs.GetEnumerator();
                            while (enumerator2.MoveNext())
                            {
                                SchemaAttDef def = (SchemaAttDef)enumerator2.Value;
                                if (def.Datatype.TokenizedType == XmlTokenizedType.ID)
                                {
                                    this.doc.AddIdInfo(this.doc.AddXmlName(decl.Prefix, decl.Name.Name, string.Empty, null), this.doc.AddAttrXmlName(def.Prefix, def.Name.Name, string.Empty, null));
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#30
0
 internal XDocumentType(string name, string publicId, string systemId, string internalSubset, IDtdInfo dtdInfo) : this(name, publicId, systemId, internalSubset)
 {
     this.dtdInfo = dtdInfo;
 }
示例#31
0
        internal void LoadFromReader(XmlReader reader, XmlSpace space)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            IXmlLineInfo lineInfo = reader as IXmlLineInfo;

            if ((lineInfo == null) || !lineInfo.HasLineInfo())
            {
                lineInfo = null;
            }
            this.hasLineInfo = lineInfo != null;
            this.nameTable   = reader.NameTable;
            XPathDocumentBuilder builder = new XPathDocumentBuilder(this, lineInfo, reader.BaseURI, LoadFlags.None);

            try
            {
                bool   isEmptyElement;
                string str2;
                bool   flag  = reader.ReadState == ReadState.Initial;
                int    depth = reader.Depth;
                string str   = this.nameTable.Get("http://www.w3.org/2000/xmlns/");
                if (flag && !reader.Read())
                {
                    return;
                }
Label_007D:
                if (!flag && (reader.Depth < depth))
                {
                    return;
                }
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    isEmptyElement = reader.IsEmptyElement;
                    builder.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.BaseURI);
                    goto Label_017B;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                    builder.WriteString(reader.Value, TextBlockType.Text);
                    goto Label_022B;

                case XmlNodeType.EntityReference:
                    reader.ResolveEntity();
                    goto Label_022B;

                case XmlNodeType.ProcessingInstruction:
                    builder.WriteProcessingInstruction(reader.LocalName, reader.Value, reader.BaseURI);
                    goto Label_022B;

                case XmlNodeType.Comment:
                    builder.WriteComment(reader.Value);
                    goto Label_022B;

                case XmlNodeType.DocumentType:
                {
                    IDtdInfo dtdInfo = reader.DtdInfo;
                    if (dtdInfo != null)
                    {
                        builder.CreateIdTables(dtdInfo);
                    }
                    goto Label_022B;
                }

                case XmlNodeType.Whitespace:
                    goto Label_01C9;

                case XmlNodeType.SignificantWhitespace:
                    if (reader.XmlSpace != XmlSpace.Preserve)
                    {
                        goto Label_01C9;
                    }
                    builder.WriteString(reader.Value, TextBlockType.SignificantWhitespace);
                    goto Label_022B;

                case XmlNodeType.EndElement:
                    builder.WriteEndElement(false);
                    goto Label_022B;

                default:
                    goto Label_022B;
                }
Label_0113:
                str2 = reader.NamespaceURI;
                if (str2 == str)
                {
                    if (reader.Prefix.Length == 0)
                    {
                        builder.WriteNamespaceDeclaration(string.Empty, reader.Value);
                    }
                    else
                    {
                        builder.WriteNamespaceDeclaration(reader.LocalName, reader.Value);
                    }
                }
                else
                {
                    builder.WriteStartAttribute(reader.Prefix, reader.LocalName, str2);
                    builder.WriteString(reader.Value, TextBlockType.Text);
                    builder.WriteEndAttribute();
                }
Label_017B:
                if (reader.MoveToNextAttribute())
                {
                    goto Label_0113;
                }
                if (isEmptyElement)
                {
                    builder.WriteEndElement(true);
                }
                goto Label_022B;
Label_01C9:
                if ((space == XmlSpace.Preserve) && (!flag || (reader.Depth != 0)))
                {
                    builder.WriteString(reader.Value, TextBlockType.Whitespace);
                }
Label_022B:
                if (reader.Read())
                {
                    goto Label_007D;
                }
            }
            finally
            {
                builder.Close();
            }
        }
 private void LoadDocumentType(IDtdInfo dtdInfo, XmlDocumentType dtNode)
 {
     SchemaInfo info = dtdInfo as SchemaInfo;
     if (info == null)
     {
         throw new XmlException("Xml_InternalError", string.Empty);
     }
     dtNode.DtdSchemaInfo = info;
     if (info != null)
     {
         this.doc.DtdSchemaInfo = info;
         if (info.Notations != null)
         {
             foreach (SchemaNotation notation in info.Notations.Values)
             {
                 dtNode.Notations.SetNamedItem(new XmlNotation(notation.Name.Name, notation.Pubid, notation.SystemLiteral, this.doc));
             }
         }
         if (info.GeneralEntities != null)
         {
             foreach (SchemaEntity entity in info.GeneralEntities.Values)
             {
                 XmlEntity node = new XmlEntity(entity.Name.Name, entity.Text, entity.Pubid, entity.Url, entity.NData.IsEmpty ? null : entity.NData.Name, this.doc);
                 node.SetBaseURI(entity.DeclaredURI);
                 dtNode.Entities.SetNamedItem(node);
             }
         }
         if (info.ParameterEntities != null)
         {
             foreach (SchemaEntity entity3 in info.ParameterEntities.Values)
             {
                 XmlEntity entity4 = new XmlEntity(entity3.Name.Name, entity3.Text, entity3.Pubid, entity3.Url, entity3.NData.IsEmpty ? null : entity3.NData.Name, this.doc);
                 entity4.SetBaseURI(entity3.DeclaredURI);
                 dtNode.Entities.SetNamedItem(entity4);
             }
         }
         this.doc.Entities = dtNode.Entities;
         IDictionaryEnumerator enumerator = info.ElementDecls.GetEnumerator();
         if (enumerator != null)
         {
             enumerator.Reset();
             while (enumerator.MoveNext())
             {
                 SchemaElementDecl decl = (SchemaElementDecl) enumerator.Value;
                 if (decl.AttDefs != null)
                 {
                     IDictionaryEnumerator enumerator2 = decl.AttDefs.GetEnumerator();
                     while (enumerator2.MoveNext())
                     {
                         SchemaAttDef def = (SchemaAttDef) enumerator2.Value;
                         if (def.Datatype.TokenizedType == XmlTokenizedType.ID)
                         {
                             this.doc.AddIdInfo(this.doc.AddXmlName(decl.Prefix, decl.Name.Name, string.Empty, null), this.doc.AddAttrXmlName(def.Prefix, def.Name.Name, string.Empty, null));
                             continue;
                         }
                     }
                 }
             }
         }
     }
 }
示例#33
0
        private void LoadDocumentType(IDtdInfo dtdInfo, XmlDocumentType dtNode)
        {
            SchemaInfo schInfo = dtdInfo as SchemaInfo;

            if (schInfo == null)
            {
                throw new XmlException(SR.Xml_InternalError, string.Empty);
            }

            dtNode.DtdSchemaInfo = schInfo;
            if (schInfo != null)
            {
                //set the schema information into the document
                _doc.DtdSchemaInfo = schInfo;

                // Notation hashtable
                if (schInfo.Notations != null)
                {
                    foreach (SchemaNotation scNot in schInfo.Notations.Values)
                    {
                        dtNode.Notations.SetNamedItem(new XmlNotation(scNot.Name.Name, scNot.Pubid, scNot.SystemLiteral, _doc));
                    }
                }

                // Entity hashtables
                if (schInfo.GeneralEntities != null)
                {
                    foreach (SchemaEntity scEnt in schInfo.GeneralEntities.Values)
                    {
                        XmlEntity ent = new XmlEntity(scEnt.Name.Name, scEnt.Text, scEnt.Pubid, scEnt.Url, scEnt.NData.IsEmpty ? null : scEnt.NData.Name, _doc);
                        ent.SetBaseURI(scEnt.DeclaredURI);
                        dtNode.Entities.SetNamedItem(ent);
                    }
                }

                if (schInfo.ParameterEntities != null)
                {
                    foreach (SchemaEntity scEnt in schInfo.ParameterEntities.Values)
                    {
                        XmlEntity ent = new XmlEntity(scEnt.Name.Name, scEnt.Text, scEnt.Pubid, scEnt.Url, scEnt.NData.IsEmpty ? null : scEnt.NData.Name, _doc);
                        ent.SetBaseURI(scEnt.DeclaredURI);
                        dtNode.Entities.SetNamedItem(ent);
                    }
                }
                _doc.Entities = dtNode.Entities;

                //extract the elements which has attribute defined as ID from the element declarations
                IDictionaryEnumerator elementDecls = schInfo.ElementDecls.GetEnumerator();
                if (elementDecls != null)
                {
                    elementDecls.Reset();
                    while (elementDecls.MoveNext())
                    {
                        SchemaElementDecl elementDecl = (SchemaElementDecl)elementDecls.Value;
                        if (elementDecl.AttDefs != null)
                        {
                            IDictionaryEnumerator attDefs = elementDecl.AttDefs.GetEnumerator();
                            while (attDefs.MoveNext())
                            {
                                SchemaAttDef attdef = (SchemaAttDef)attDefs.Value;
                                if (attdef.Datatype.TokenizedType == XmlTokenizedType.ID)
                                {
                                    //we only register the XmlElement based on their Prefix/LocalName and skip the namespace
                                    _doc.AddIdInfo(
                                        _doc.AddXmlName(elementDecl.Prefix, elementDecl.Name.Name, string.Empty, null),
                                        _doc.AddAttrXmlName(attdef.Prefix, attdef.Name.Name, string.Empty, null));
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
 internal XDocumentType(string name, string publicId, string systemId, string internalSubset, IDtdInfo dtdInfo) : this(name, publicId, systemId, internalSubset)
 {
     this.dtdInfo = dtdInfo;
 }