Beispiel #1
0
        private QuickFix[] GetInsertFixes(XmlElement e)
        {
            if (e == null)
            {
                return new QuickFix[] {}
            }
            ;

            XmlElement parent = e.ParentNode as XmlElement;

            // TODO: E: entities!
            if (parent == null)
            {
                return new QuickFix[] {}
            }
            ;

            ValidationEngine ve = new ValidationEngine(documentType, null);

            // get candidate replacements
            ElementListItem[] possibles = ve.GetValidElements(parent, e, false);

            ArrayList ret = new ArrayList();

            foreach (ElementListItem eli in possibles)
            {
                if (eli.IsRequired)
                {
                    QuickFixInsert qfi = new QuickFixInsert(e, eli.Name);
                    ret.Add(qfi);
                }
            }
            return(ret.ToArray(typeof(QuickFix)) as QuickFix[]);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public bool IsValidSequence(XmlElement e, ArrayList items)
        {
            ValidationEngine ve = new ValidationEngine(documentType, this);
            ElementType      et = documentType.GetElementType(e);

            if (et == null)
            {
                return(true);
            }

            valid = true;
            ve.Validate(e, et, items);

            return(valid);
        }
Beispiel #4
0
        private QuickFix[] GetChangeFixes(XmlElement e)
        {
            if (e == null)
            {
                return new QuickFix[] {}
            }
            ;

            XmlElement parent = e.ParentNode as XmlElement;

            // TODO: E: entities!
            if (parent == null)
            {
                return new QuickFix[] {}
            }
            ;

            // TODO: M: refactor - shouldn't need to pass null here
            //			(some of the ve methods have no callback - new class?)
            ValidationEngine ve = new ValidationEngine(documentType, null);

            // get candidate replacements
            ElementListItem[] possibles = ve.GetValidElements(parent, e, true);

            ArrayList children = new ArrayList();

            foreach (XmlNode n in e.ChildNodes)
            {
                children.Add(n);
            }

            ArrayList ret = new ArrayList();

            foreach (ElementListItem eli in possibles)
            {
                // TODO: M: error checking (should never be null though)
                ElementType et = documentType[eli.Name];
                if (ve.IsValid(et, children))
                {
                    QuickFixChange qfc = new QuickFixChange(e, eli.Name);
                    ret.Add(qfc);
                }
            }
            return(ret.ToArray(typeof(QuickFix)) as QuickFix[]);
        }
Beispiel #5
0
        private ICollection GetAppendFixes(XmlElement e)
        {
            ValidationEngine ve = new ValidationEngine(documentType, null);

            ElementListItem[] possibles = ve.GetMissingElements(e);

            ArrayList list = new ArrayList();

            foreach (ElementListItem eli in possibles)
            {
                if (eli.IsRequired)
                {
                    QuickFixAppend qfi = new QuickFixAppend(e, eli.Name);
                    list.Add(qfi);
                }
            }
            return(list);
        }
Beispiel #6
0
        public void Detach()
        {
            if (document == null)
            {
                return;
            }

            document.NodeChanging -= new XmlNodeChangedEventHandler(NodeChanging);
            document.NodeChanged  -= new XmlNodeChangedEventHandler(NodeChanged);
            document.NodeInserted -= new XmlNodeChangedEventHandler(NodeInserted);
            document.NodeRemoved  -= new XmlNodeChangedEventHandler(NodeRemoved);

            documentType     = null;
            quickFixer       = null;
            nodeInfo         = new InvalidNodeInfo();
            idTracker        = new IdTracker();
            validationEngine = null;
        }
Beispiel #7
0
        public void Detach()
        {
            if ( document == null )
                return;

            document.NodeChanging-=new XmlNodeChangedEventHandler(NodeChanging);
            document.NodeChanged-=new XmlNodeChangedEventHandler(NodeChanged);
            document.NodeInserted-=new XmlNodeChangedEventHandler(NodeInserted);
            document.NodeRemoved-=new XmlNodeChangedEventHandler(NodeRemoved);

            documentType=null;
            quickFixer=null;
            nodeInfo=new InvalidNodeInfo();
            idTracker=new IdTracker();
            validationEngine=null;
        }
Beispiel #8
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);
        }
Beispiel #9
0
        public bool IsValidSequence(XmlElement e, ArrayList items)
        {
            ValidationEngine ve=new ValidationEngine(documentType, this);
            ElementType et=documentType.GetElementType(e);
            if ( et == null )
                return true;

            valid=true;
            ve.Validate(e, et, items);

            return valid;
        }
Beispiel #10
0
        private QuickFix[] GetInsertFixes(XmlElement e)
        {
            if ( e == null )
                return new QuickFix[] {};

            XmlElement parent=e.ParentNode as XmlElement;
            // TODO: E: entities!
            if ( parent == null )
                return new QuickFix[] {};

            ValidationEngine ve=new ValidationEngine(documentType, null);
            // get candidate replacements
            ElementListItem[] possibles=ve.GetValidElements(parent, e, false);

            ArrayList ret=new ArrayList();
            foreach ( ElementListItem eli in possibles )
            {
                if ( eli.IsRequired )
                {
                    QuickFixInsert qfi=new QuickFixInsert(e, eli.Name);
                    ret.Add(qfi);
                }
            }
            return ret.ToArray(typeof(QuickFix)) as QuickFix[];
        }
Beispiel #11
0
        private QuickFix[] GetChangeFixes(XmlElement e)
        {
            if ( e == null )
                return new QuickFix[] {};

            XmlElement parent=e.ParentNode as XmlElement;
            // TODO: E: entities!
            if ( parent == null )
                return new QuickFix[] {};

            // TODO: M: refactor - shouldn't need to pass null here
            //			(some of the ve methods have no callback - new class?)
            ValidationEngine ve=new ValidationEngine(documentType, null);
            // get candidate replacements
            ElementListItem[] possibles=ve.GetValidElements(parent, e, true);

            ArrayList children=new ArrayList();
            foreach ( XmlNode n in e.ChildNodes )
                children.Add(n);

            ArrayList ret=new ArrayList();
            foreach ( ElementListItem eli in possibles )
            {
                // TODO: M: error checking (should never be null though)
                ElementType et=documentType[eli.Name];
                if ( ve.IsValid(et, children) )
                {
                    QuickFixChange qfc=new QuickFixChange(e, eli.Name);
                    ret.Add(qfc);
                }
            }
            return ret.ToArray(typeof(QuickFix)) as QuickFix[];
        }
Beispiel #12
0
        private ICollection GetAppendFixes(XmlElement e)
        {
            ValidationEngine ve=new ValidationEngine(documentType, null);
            ElementListItem[] possibles=ve.GetMissingElements(e);

            ArrayList list=new ArrayList();
            foreach ( ElementListItem eli in possibles )
            {
                if ( eli.IsRequired )
                {
                    QuickFixAppend qfi=new QuickFixAppend(e, eli.Name);
                    list.Add(qfi);
                }
            }
            return list;
        }