private void ValidateMixedModel(ElementType et, ICollection list)
        {
            foreach ( XmlNode n in list )
            {
                client.StartChildValidation(n);

                if ( n.NodeType != XmlNodeType.Element )
                    // TODO: H: entities!
                    continue;
            //				{
            //					RemoveValidationErrors(n);
            //					continue;
            //				}

                if ( !et.HasChildElement(new XmlName(n.Name)) )
                    client.ProcessError(n, ValidationErrorType.ElementNotInContentModel);
            }
        }
        internal ElementTypeRef IsValidSequence(ElementType et, ICollection s, int index)
        {
            ICollection col=et.ContentModel.GetValidFirstElements();

            int count=0;
            ElementTypeRef ret=null;
            foreach ( XmlName name in s )
            {
                count++;

                if ( !et.HasChildElement(name) )
                    // ignore elements that simply aren't in the model
                    // TODO: H: count can get out
                    continue;

                ElementTypeRef sr=FindInCollection(col, name);
                if ( count == index+1 )
                {
                    ret=sr;
                }

                if ( sr == null )
                {
                    // element name is not allowed here
                    if ( ret != null && count < index+1 )
                        return ret;

                    return null;
                }

                // TODO: M: optimise - this is called at end of s even though not going to loop again
                col=sr.OriginalReference.GetValidNextElements();
            }
            // TODO: M: think about required elements at end - but probably
            //			not needed here because don't want to stop someone
            //			adding an element even if more are allowed
            return ret;
        }
        private void ValidateElementModel(XmlElement e, ElementType et, ICollection children)
        {
            ICollection col=et.ContentModel.GetValidFirstElements();

            bool elementMissing=false;
            foreach ( XmlNode n in children )
            {
                client.StartChildValidation(n);

                if ( n.NodeType == XmlNodeType.Text )
                {
                    client.ProcessError(n, ValidationErrorType.NodeNotAllowed);
                }
                else if ( n.NodeType == XmlNodeType.Element )
                {
                    ElementType et2=documentType.GetElementType((XmlElement) n);
                    if ( et2 == null )
                        // not in DTD, will be picked up later
                        continue;

                    // TODO: E: entities!
                    if ( !et.HasChildElement(new XmlName(n)) )
                    {
                        // this element can never be allowed here
                        client.ProcessError(n, ValidationErrorType.ElementNotInContentModel);
                        continue;
                    }

                    if ( elementMissing )
                        continue;

                    ElementTypeRef sr=FindInCollection(col, (XmlElement) n);
                    if ( sr == null )
                    {
                        foreach ( ElementTypeRef etr in col )
                        {
                            if ( etr.IsRequired )
                            {
                                elementMissing=true;
                                client.ProcessError(n, ValidationErrorType.ElementNotAllowedHere);
                                break;
                            }
                        }
                        if ( elementMissing )
                            continue;

                        client.ProcessError(n, ValidationErrorType.NodeNotAllowed);
                    }
                    else
                        col=sr.OriginalReference.GetValidNextElements();
                }
            }
            if ( !elementMissing )
            {
                foreach ( ElementTypeRef sr in col )
                {
                    if ( sr.IsRequired )
                    {
                        // TODO: M: can provide some more info to the error here
                        client.ProcessError(e, ValidationErrorType.RequiredElementMissing);
                        break;
                    }
                }
            }
        }
Example #4
0
        Reference getReference(Group group, ElementType parent, bool mixed)
        {
            //      XMLName     name;
            ElementType child;
            Reference   rf;

            // Create an ElementType for the referenced child.

            child = createElementType();

            // Add the child to the parent and vice versa. If we are processing
            // mixed content, then each child must be unique in the parent.

            if ( mixed )
            {
                if (parent.HasChildElement(child.Name))
                    throwXMLMiddlewareException("The element type " + child.Name + " appeared more than once in the declaration of mixed content for the element type " + parent.Name + ".");
            }

            parent.AddChildElement(child);
            child.AddParentElement(parent);

            // Create a Reference for the child, add it to the group, and return it.

            rf = new Reference(child);
            group.AddMember(rf);
            return rf;
        }