コード例 #1
0
ファイル: Validation.cs プロジェクト: jugglingcats/XEditNet
        private void RemoveIdOrIdRef(XmlElement e, XmlAttribute a)
        {
            ElementType et=documentType.GetElementType(e);
            XmlName xn=new XmlName(a);
            Attribute attr=et.GetAttribute(xn);
            if ( attr == null )
                return;

            AttributeBinding ab;
            string val=a.Value;
            switch ( attr.Type )
            {
                case AttributeType.ID:
                    // record the previous id because we'll need that later (NodeChanged event)
                    ab=new AttributeBinding(e, attr.Name, val, a.Specified);
                    idTracker.RemoveId(ab);
                    ProcessRemovedId(val);
                    break;

                case AttributeType.IDREF:
                case AttributeType.IDREFS:
                    ab=new AttributeBinding(e, attr.Name, val, a.Specified);
                    idTracker.RemoveIdRefs(ab);
                    break;
            }
        }
コード例 #2
0
ファイル: Validation.cs プロジェクト: jugglingcats/XEditNet
        private void AddIdOrIdRef(XmlElement e, XmlAttribute a, Attribute attr)
        {
            // any previous value will have been removed in NodeChanging event

            AttributeBinding ab;
            string val=a.Value;
            switch ( attr.Type )
            {
                case AttributeType.ID:
                    ab=new AttributeBinding(e, attr.Name, val, a.Specified);
                    idTracker.AddId(ab);
                    if ( idTracker.IdCount(val) > 1 )
                    {
                        foreach ( AttributeBinding ab2 in idTracker.GetIdBindings(val) )
                        {
                            // TODO: L: inefficient, lots of removing then adding
                            XmlAttribute a2=ab2.Element.GetAttributeNode(ab2.Name);
                            AttributeErrorFilter aef=new AttributeErrorFilter(ab2.Element, a2, ValidationErrorType.IdAttributeInUse);
                            RemoveValidationErrors(aef);
                            ValidationErrorAttribute vea=new ValidationErrorAttribute(ab2.Element, a2.Name, ValidationErrorType.IdAttributeInUse);
                            AddValidationError(ab2.Element, vea);
                        }
                    }

                    foreach ( AttributeBinding ab2 in idTracker.GetIdRefBindings(val) )
                    {
                        XmlAttribute ar=ab.Element.GetAttributeNode(ab2.Name);
                        AttributeErrorFilter aef=new AttributeErrorFilter(ab2.Element, ar, ValidationErrorType.IdAttributeNotDefined);
                        RemoveValidationErrors(aef);
                    }

                    break;

                case AttributeType.IDREF:
                case AttributeType.IDREFS:
                    ab=new AttributeBinding(e, attr.Name, val, a.Specified);
                    idTracker.AddIdRefs(ab);
                    // TODO: L: inefficient - we split twice, here and in AddIdRefs
                    foreach ( string id in ab.Value.Split(' ') )
                    if ( idTracker.IdCount(id) == 0 )
                    {
                        ValidationErrorAttribute vea=new ValidationErrorAttribute(e, a.Name, ValidationErrorType.IdAttributeNotDefined);
                        AddValidationError(e, vea);
                    }
                    break;
            }
        }
コード例 #3
0
ファイル: Validation.cs プロジェクト: jugglingcats/XEditNet
        private void GetAllIdAndIdRefs()
        {
            if ( documentType == null )
                return;

            foreach ( XmlElement e in document.SelectNodes("//*") )
            {
                ElementType et=documentType.GetElementType(e);
                if ( et == null )
                    continue;

                foreach ( Attribute a in et.Attributes )
                {
                    XmlAttribute attr=e.Attributes[a.Name.QualifiedName];
                    if ( attr == null )
                        continue;

                    if ( !validationEngine.ValidateAttribute(a, e, attr) )
                        // don't bother storing info on invalid attributes
                        continue;

                    AttributeBinding ab;
                    string val=attr.Value;
                    switch ( a.Type )
                    {
                        case AttributeType.ID:
                            ab=new AttributeBinding(e, a.Name, val, attr.Specified);
                            idTracker.AddId(ab);
                            break;

                        case AttributeType.IDREF:
                        case AttributeType.IDREFS:
                            ab=new AttributeBinding(e, a.Name, val, attr.Specified);
                            idTracker.AddIdRefs(ab);
                            break;
                    }
                }
            }
        }
コード例 #4
0
ファイル: Validation.cs プロジェクト: jugglingcats/XEditNet
        // TODO: ?: remove?
        public IList GetAttributeInfo(XmlElement elem)
        {
            ArrayList ret=new ArrayList();

            if ( documentType == null )
                return ret;

            ElementType et=documentType.GetElementType(elem);
            if ( et == null )
                return ret;

            foreach ( Attribute a in et.Attributes )
            {
                string val=a.DefaultValue;
                bool specified=false;
                if ( elem.HasAttribute(a.Name.QualifiedName) )
                {
                    val=elem.GetAttribute(a.Name.QualifiedName);
                    specified=true;
                }
                AttributeBinding ab=new AttributeBinding(elem, a.Name, val, specified);
                ret.Add(ab);
            }
            return ret;
        }