示例#1
0
        public void Attach(XmlDocument doc, Uri baseUri)
        {
            Detach();
            this.document = doc;
            if (doc.DocumentType == null)
            {
                return;
            }

            DTDParser dtp = new DTDParser();

            bool hasInternalSubset  = doc.DocumentType.InternalSubset != null;
            bool internalSubsetOnly = doc.DocumentType.SystemId == null;

            if (baseUri == null && !doc.BaseURI.Equals(""))
            {
                baseUri = new Uri(doc.BaseURI);
            }

            // TODO: H: shouldn't this use the doc's resolver?
            CustomXmlResolver cxr = new CustomXmlResolver(baseUri);

            dtp.XmlResolver = cxr;

            if (hasInternalSubset)
            {
                InputSource ii = new InputSource(doc.DocumentType.InternalSubset);
                documentType = dtp.parseInternalSubset(ii, internalSubsetOnly);
            }

            if (!internalSubsetOnly)
            {
                Uri         doctypeUri = cxr.ResolveUri(baseUri, doc.DocumentType.SystemId);
                InputSource i          = new InputSource(doctypeUri);
                if (hasInternalSubset)
                {
                    documentType = dtp.parseExternalSubset(i);
                }
                else
                {
                    documentType = dtp.parseExternalSubset(i, true);
                }
            }

            validationEngine = new ValidationEngine(documentType, this);
            quickFixer       = new QuickFixer(documentType);

            GetAllIdAndIdRefs();
            ValidateAllIdAndIdRefs();

            document.NodeChanging += new XmlNodeChangedEventHandler(NodeChanging);
            document.NodeChanged  += new XmlNodeChangedEventHandler(NodeChanged);
            document.NodeInserted += new XmlNodeChangedEventHandler(NodeInserted);
            document.NodeRemoved  += new XmlNodeChangedEventHandler(NodeRemoved);
        }
示例#2
0
        public static ElementInfo[] GetAllElements(Uri dtdUri)
        {
            DTDParser    p   = new DTDParser();
            InputSource  ins = new InputSource(dtdUri, dtdUri.AbsoluteUri);
            DocumentType t   = p.parseExternalSubset(ins, true);

            ElementInfo[] ret = new ElementInfo[t.ElementTypes.Length];
            int           n   = 0;

            foreach (ElementType et in t.ElementTypes)
            {
                ret[n].LocalName     = et.Name.LocalName;
                ret[n].IsRootElement = et.IsRootElement;
                n++;
            }

            return(ret);
        }