예제 #1
0
        private void loadDTD(string dtdIdentifier)
        {
            DTD dtd = UseDtd(dtdIdentifier);

            if (dtd == null)
            {
                return;
            }

            foreach (DictionaryEntry entry in dtd.Entities)
            {
                DTDEntity dtdEntity = (DTDEntity)entry.Value;

                if (dtdEntity.ExternalId == null)
                {
                    continue;
                }

                string system = dtdEntity.ExternalId.System;
                if (dtdEntity.ExternalId is DTDPublic)
                {
                    string pub = ((DTDPublic)dtdEntity.ExternalId).Pub;
                    if (!string.IsNullOrEmpty(pub))
                    {
                        system = pub; //.Replace(" ", "%20");
                    }
                }

                string normalisedUri = system.Replace("%20", " ").Replace(" //", "//").Replace("// ", "//");

                foreach (String key in DTDs.DTDs.ENTITIES_MAPPING.Keys)
                {
                    if (normalisedUri.Contains(key))
                    {
                        loadDTD(DTDs.DTDs.ENTITIES_MAPPING[key]);
                        break;
                    }
                }
            }
        }
        private void initMixedContentXmlElementNamesFromDTD(string dtdUniqueResourceId, Stream dtdStream)
        {
            List <string> list;

            m_listOfMixedContentXmlElementNames.TryGetValue(dtdUniqueResourceId, out list);

            DebugFix.Assert(list != null);

            if (list == null)
            {
                return;
            }

            DTD dtd = null;

            try
            {
                // NOTE: the Stream is automatically closed by the parser, see Scanner.ReadNextChar()
                DTDParser parser = new DTDParser(new StreamReader(dtdStream, Encoding.UTF8));
                dtd = parser.Parse(true);
            }
            catch (Exception ex)
            {
#if DEBUG
                Debugger.Break();
#endif
                dtdStream.Close();
            }

            if (dtd != null)
            {
                foreach (DictionaryEntry entry in dtd.Elements)
                {
                    DTDElement dtdElement = (DTDElement)entry.Value;
                    DTDItem    item       = dtdElement.Content;
                    if (isMixedContent(item))
                    {
                        if (!list.Contains(dtdElement.Name))
                        {
                            list.Add(dtdElement.Name);
                        }
                    }
                }


                foreach (DictionaryEntry entry in dtd.Entities)
                {
                    DTDEntity dtdEntity = (DTDEntity)entry.Value;

                    if (dtdEntity.ExternalId == null)
                    {
                        continue;
                    }

                    string system = dtdEntity.ExternalId.System;
                    if (dtdEntity.ExternalId is DTDPublic)
                    {
                        string pub = ((DTDPublic)dtdEntity.ExternalId).Pub;
                        if (!string.IsNullOrEmpty(pub))
                        {
                            system = pub; //.Replace(" ", "%20");
                        }
                    }

                    string normalisedUri = system.Replace("%20", " ").Replace(" //", "//").Replace("// ", "//");

                    foreach (String key in DTDs.DTDs.ENTITIES_MAPPING.Keys)
                    {
                        if (normalisedUri.Contains(key))
                        {
                            string subResource = DTDs.DTDs.ENTITIES_MAPPING[key];
                            Stream stream      = DTDs.DTDs.Fetch(subResource);

                            if (stream != null)
                            {
                                initMixedContentXmlElementNamesFromDTD(dtdUniqueResourceId, stream);
                            }
                            else
                            {
#if DEBUG
                                Debugger.Break();
#endif
                            }

                            break;
                        }
                    }
                }
            }
        }