Inheritance: XmlSchemaAnnotated
 private static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents)
 {
     XmlSchemaComplexType type = new XmlSchemaComplexType();
     type.SetQualifiedName(DatatypeImplementation.QnAnyType);
     XmlSchemaAny item = new XmlSchemaAny {
         MinOccurs = 0M,
         MaxOccurs = 79228162514264337593543950335M,
         ProcessContents = processContents
     };
     item.BuildNamespaceList(null);
     XmlSchemaSequence sequence = new XmlSchemaSequence();
     sequence.Items.Add(item);
     type.SetContentTypeParticle(sequence);
     type.SetContentType(XmlSchemaContentType.Mixed);
     type.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
     type.ElementDecl.SchemaType = type;
     ParticleContentValidator validator = new ParticleContentValidator(XmlSchemaContentType.Mixed);
     validator.Start();
     validator.OpenGroup();
     validator.AddNamespaceList(item.NamespaceList, item);
     validator.AddStar();
     validator.CloseGroup();
     ContentValidator validator2 = validator.Finish(true);
     type.ElementDecl.ContentValidator = validator2;
     XmlSchemaAnyAttribute attribute = new XmlSchemaAnyAttribute {
         ProcessContents = processContents
     };
     attribute.BuildNamespaceList(null);
     type.SetAttributeWildcard(attribute);
     type.ElementDecl.AnyAttribute = attribute;
     return type;
 }
Ejemplo n.º 2
0
 // Spec 3.10.4 Item Valid (Wildcard)
 private static bool AttributeWildcardItemValid(XmlSchemaAnyAttribute anyAttr, XmlQualifiedName qname, string ns)
 {
     if (anyAttr.HasValueAny)
     {
         return(true);
     }
     if (anyAttr.HasValueOther && (anyAttr.TargetNamespace == "" || ns != anyAttr.TargetNamespace))
     {
         return(true);
     }
     if (anyAttr.HasValueTargetNamespace && ns == anyAttr.TargetNamespace)
     {
         return(true);
     }
     if (anyAttr.HasValueLocal && ns == "")
     {
         return(true);
     }
     for (int i = 0; i < anyAttr.ResolvedNamespaces.Count; i++)
     {
         if (anyAttr.ResolvedNamespaces [i] == ns)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
 internal static XmlSchemaAnyAttribute Intersection(XmlSchemaAnyAttribute o1, XmlSchemaAnyAttribute o2) {
     NamespaceList nsl = NamespaceList.Intersection(o1.NamespaceList, o2.NamespaceList);
     if (nsl != null) {
         XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
         anyAttribute.namespaceList = nsl;
         if (o1.processContents == XmlSchemaContentProcessing.Strict || 
             o1.processContents == XmlSchemaContentProcessing.None ||
             o2.processContents == XmlSchemaContentProcessing.Strict ||
             o2.processContents == XmlSchemaContentProcessing.None) {
             anyAttribute.processContents = XmlSchemaContentProcessing.Strict;
         }
         else if (o1.processContents == XmlSchemaContentProcessing.Lax ||
                  o2.processContents == XmlSchemaContentProcessing.Lax) {
             anyAttribute.processContents = XmlSchemaContentProcessing.Lax;
         }
         else {
             anyAttribute.processContents = XmlSchemaContentProcessing.Skip;
         }
         anyAttribute.Annotation = o1.Annotation;
         return anyAttribute;
     }
     else {
         // not expressible
         return null;
     }
 }
Ejemplo n.º 4
0
        internal static XmlSchemaAnyAttribute Intersection(XmlSchemaAnyAttribute o1, XmlSchemaAnyAttribute o2)
        {
            NamespaceList nsl = NamespaceList.Intersection(o1.NamespaceList, o2.NamespaceList);

            if (nsl != null)
            {
                XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
                anyAttribute.namespaceList = nsl;
                if (o1.processContents == XmlSchemaContentProcessing.Strict ||
                    o1.processContents == XmlSchemaContentProcessing.None ||
                    o2.processContents == XmlSchemaContentProcessing.Strict ||
                    o2.processContents == XmlSchemaContentProcessing.None)
                {
                    anyAttribute.processContents = XmlSchemaContentProcessing.Strict;
                }
                else if (o1.processContents == XmlSchemaContentProcessing.Lax ||
                         o2.processContents == XmlSchemaContentProcessing.Lax)
                {
                    anyAttribute.processContents = XmlSchemaContentProcessing.Lax;
                }
                else
                {
                    anyAttribute.processContents = XmlSchemaContentProcessing.Skip;
                }
                anyAttribute.Annotation = o1.Annotation;
                return(anyAttribute);
            }
            else
            {
                // not expressible
                return(null);
            }
        }
 private void ClearCompiledState()
 {
     this.attributeUses = null;
     this.localElements = null;
     this.attributeWildcard = null;
     this.contentTypeParticle = XmlSchemaParticle.Empty;
     this.blockResolved = XmlSchemaDerivationMethod.None;
 }
Ejemplo n.º 6
0
        public IEnumerable<XmlSchemaObject> GetExtensionAttributes(XmlSchemaAnyAttribute parent)
        {
            List<XmlSchemaObject> attributes;
            if (!_extensionAttributes.TryGetValue(parent, out attributes))
                return _emptyObjectList;

            return attributes;
        }
 private void ClearCompiledState()
 {
     this.attributeUses = null;
     this.localElements = null;
     this.attributeWildcard = null;
     this.contentTypeParticle = XmlSchemaParticle.Empty;
     this.blockResolved = XmlSchemaDerivationMethod.None;
 }
Ejemplo n.º 8
0
 static XmlSchemaComplexType() {
     anyType = new XmlSchemaComplexType();
     anyType.SetContentType(XmlSchemaContentType.Mixed);
     anyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
     XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
     anyAttribute.BuildNamespaceList(null);
     anyType.SetAttributeWildcard(anyAttribute);
     anyType.ElementDecl.AnyAttribute = anyAttribute;
 }
 public SDataSchemaResourceType(string elementName)
     : base(elementName)
 {
     ListName = elementName + "--list";
     ListItemName = elementName;
     CanGet = true;
     AnyAttribute = new XmlSchemaAnyAttribute();
     ListAnyAttribute = new XmlSchemaAnyAttribute();
 }
Ejemplo n.º 10
0
 private void ClearCompiledState()
 {
     //Re-set post-compiled state for cloned object
     _attributeUses       = null;
     _localElements       = null;
     _attributeWildcard   = null;
     _contentTypeParticle = XmlSchemaParticle.Empty;
     _blockResolved       = XmlSchemaDerivationMethod.None;
 }
 internal static XmlSchemaAnyAttribute Union(XmlSchemaAnyAttribute o1, XmlSchemaAnyAttribute o2, bool v1Compat)
 {
     System.Xml.Schema.NamespaceList list = System.Xml.Schema.NamespaceList.Union(o1.NamespaceList, o2.NamespaceList, v1Compat);
     if (list != null)
     {
         return new XmlSchemaAnyAttribute { namespaceList = list, processContents = o1.processContents, Annotation = o1.Annotation };
     }
     return null;
 }
 internal static XmlSchemaAnyAttribute Union(XmlSchemaAnyAttribute o1, XmlSchemaAnyAttribute o2, bool v1Compat)
 {
     System.Xml.Schema.NamespaceList list = System.Xml.Schema.NamespaceList.Union(o1.NamespaceList, o2.NamespaceList, v1Compat);
     if (list != null)
     {
         return(new XmlSchemaAnyAttribute {
             namespaceList = list, processContents = o1.processContents, Annotation = o1.Annotation
         });
     }
     return(null);
 }
Ejemplo n.º 13
0
        static XmlSchemaComplexType()
        {
            anyType = new XmlSchemaComplexType();
            anyType.SetContentType(XmlSchemaContentType.Mixed);
            anyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
            XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();

            anyAttribute.BuildNamespaceList(null);
            anyType.SetAttributeWildcard(anyAttribute);
            anyType.ElementDecl.AnyAttribute = anyAttribute;
        }
 internal static XmlSchemaAnyAttribute Intersection(XmlSchemaAnyAttribute o1, XmlSchemaAnyAttribute o2, bool v1Compat) {
     NamespaceList nsl = NamespaceList.Intersection(o1.NamespaceList, o2.NamespaceList, v1Compat);
     if (nsl != null) {
         XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
         anyAttribute.namespaceList = nsl;
         anyAttribute.ProcessContents = o1.ProcessContents;
         anyAttribute.Annotation = o1.Annotation;
         return anyAttribute;
     }
     else {
         // not expressible
         return null;
     }
 }
Ejemplo n.º 15
0
        internal static XmlSchemaAnyAttribute Intersection(XmlSchemaAnyAttribute o1, XmlSchemaAnyAttribute o2, bool v1Compat)
        {
            NamespaceList nsl = NamespaceList.Intersection(o1.NamespaceList, o2.NamespaceList, v1Compat);

            if (nsl != null)
            {
                XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
                anyAttribute._namespaceList  = nsl;
                anyAttribute.ProcessContents = o1.ProcessContents;
                anyAttribute.Annotation      = o1.Annotation;
                return(anyAttribute);
            }
            else
            {
                // not expressible
                return(null);
            }
        }
Ejemplo n.º 16
0
        internal static XmlSchemaAnyAttribute Union(XmlSchemaAnyAttribute o1, XmlSchemaAnyAttribute o2)
        {
            NamespaceList nsl = NamespaceList.Union(o1.NamespaceList, o2.NamespaceList);

            if (nsl != null)
            {
                XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
                anyAttribute.namespaceList   = nsl;
                anyAttribute.processContents = o1.processContents;
                anyAttribute.Annotation      = o1.Annotation;
                return(anyAttribute);
            }
            else
            {
                // not expressible
                return(null);
            }
        }
Ejemplo n.º 17
0
        private static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents)
        {
            XmlSchemaComplexType localAnyType = new XmlSchemaComplexType();

            localAnyType.SetQualifiedName(DatatypeImplementation.QnAnyType);

            XmlSchemaAny anyElement = new XmlSchemaAny();

            anyElement.MinOccurs = decimal.Zero;
            anyElement.MaxOccurs = decimal.MaxValue;

            anyElement.ProcessContents = processContents;
            anyElement.BuildNamespaceList(null);
            XmlSchemaSequence seq = new XmlSchemaSequence();

            seq.Items.Add(anyElement);

            localAnyType.SetContentTypeParticle(seq);
            localAnyType.SetContentType(XmlSchemaContentType.Mixed);

            localAnyType.ElementDecl            = SchemaElementDecl.CreateAnyTypeElementDecl();
            localAnyType.ElementDecl.SchemaType = localAnyType;

            //Create contentValidator for Any
            ParticleContentValidator contentValidator = new ParticleContentValidator(XmlSchemaContentType.Mixed);

            contentValidator.Start();
            contentValidator.OpenGroup();
            contentValidator.AddNamespaceList(anyElement.NamespaceList !, anyElement);
            contentValidator.AddStar();
            contentValidator.CloseGroup();
            ContentValidator anyContentValidator = contentValidator.Finish(true);

            localAnyType.ElementDecl.ContentValidator = anyContentValidator;

            XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();

            anyAttribute.ProcessContents = processContents;
            anyAttribute.BuildNamespaceList(null);
            localAnyType.SetAttributeWildcard(anyAttribute);
            localAnyType.ElementDecl.AnyAttribute = anyAttribute;
            return(localAnyType);
        }
        internal static XmlSchemaSimpleContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleContentRestriction xmlSchemaSimpleContentRestriction = new XmlSchemaSimpleContentRestriction();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "restriction")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaComplexContentRestriction.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }
            xmlSchemaSimpleContentRestriction.LineNumber   = reader.LineNumber;
            xmlSchemaSimpleContentRestriction.LinePosition = reader.LinePosition;
            xmlSchemaSimpleContentRestriction.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception ex;
                    xmlSchemaSimpleContentRestriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out ex);
                    if (ex != null)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is not a valid value for base attribute", ex);
                    }
                }
                else if (reader.Name == "id")
                {
                    xmlSchemaSimpleContentRestriction.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
                {
                    XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for restriction", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaSimpleContentRestriction);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaSimpleContentRestriction);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "restriction")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaSimpleContentRestriction.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaSimpleContentRestriction.Annotation = xmlSchemaAnnotation;
                    }
                }
                else if (num <= 2 && reader.LocalName == "simpleType")
                {
                    num = 3;
                    XmlSchemaSimpleType xmlSchemaSimpleType = XmlSchemaSimpleType.Read(reader, h);
                    if (xmlSchemaSimpleType != null)
                    {
                        xmlSchemaSimpleContentRestriction.baseType = xmlSchemaSimpleType;
                    }
                }
                else
                {
                    if (num <= 3)
                    {
                        if (reader.LocalName == "minExclusive")
                        {
                            num = 3;
                            XmlSchemaMinExclusiveFacet xmlSchemaMinExclusiveFacet = XmlSchemaMinExclusiveFacet.Read(reader, h);
                            if (xmlSchemaMinExclusiveFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMinExclusiveFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "minInclusive")
                        {
                            num = 3;
                            XmlSchemaMinInclusiveFacet xmlSchemaMinInclusiveFacet = XmlSchemaMinInclusiveFacet.Read(reader, h);
                            if (xmlSchemaMinInclusiveFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMinInclusiveFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "maxExclusive")
                        {
                            num = 3;
                            XmlSchemaMaxExclusiveFacet xmlSchemaMaxExclusiveFacet = XmlSchemaMaxExclusiveFacet.Read(reader, h);
                            if (xmlSchemaMaxExclusiveFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMaxExclusiveFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "maxInclusive")
                        {
                            num = 3;
                            XmlSchemaMaxInclusiveFacet xmlSchemaMaxInclusiveFacet = XmlSchemaMaxInclusiveFacet.Read(reader, h);
                            if (xmlSchemaMaxInclusiveFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMaxInclusiveFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "totalDigits")
                        {
                            num = 3;
                            XmlSchemaTotalDigitsFacet xmlSchemaTotalDigitsFacet = XmlSchemaTotalDigitsFacet.Read(reader, h);
                            if (xmlSchemaTotalDigitsFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaTotalDigitsFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "fractionDigits")
                        {
                            num = 3;
                            XmlSchemaFractionDigitsFacet xmlSchemaFractionDigitsFacet = XmlSchemaFractionDigitsFacet.Read(reader, h);
                            if (xmlSchemaFractionDigitsFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaFractionDigitsFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "length")
                        {
                            num = 3;
                            XmlSchemaLengthFacet xmlSchemaLengthFacet = XmlSchemaLengthFacet.Read(reader, h);
                            if (xmlSchemaLengthFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaLengthFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "minLength")
                        {
                            num = 3;
                            XmlSchemaMinLengthFacet xmlSchemaMinLengthFacet = XmlSchemaMinLengthFacet.Read(reader, h);
                            if (xmlSchemaMinLengthFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMinLengthFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "maxLength")
                        {
                            num = 3;
                            XmlSchemaMaxLengthFacet xmlSchemaMaxLengthFacet = XmlSchemaMaxLengthFacet.Read(reader, h);
                            if (xmlSchemaMaxLengthFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMaxLengthFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "enumeration")
                        {
                            num = 3;
                            XmlSchemaEnumerationFacet xmlSchemaEnumerationFacet = XmlSchemaEnumerationFacet.Read(reader, h);
                            if (xmlSchemaEnumerationFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaEnumerationFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "whiteSpace")
                        {
                            num = 3;
                            XmlSchemaWhiteSpaceFacet xmlSchemaWhiteSpaceFacet = XmlSchemaWhiteSpaceFacet.Read(reader, h);
                            if (xmlSchemaWhiteSpaceFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaWhiteSpaceFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "pattern")
                        {
                            num = 3;
                            XmlSchemaPatternFacet xmlSchemaPatternFacet = XmlSchemaPatternFacet.Read(reader, h);
                            if (xmlSchemaPatternFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaPatternFacet);
                            }
                            continue;
                        }
                    }
                    if (num <= 4)
                    {
                        if (reader.LocalName == "attribute")
                        {
                            num = 4;
                            XmlSchemaAttribute xmlSchemaAttribute = XmlSchemaAttribute.Read(reader, h);
                            if (xmlSchemaAttribute != null)
                            {
                                xmlSchemaSimpleContentRestriction.Attributes.Add(xmlSchemaAttribute);
                            }
                            continue;
                        }
                        if (reader.LocalName == "attributeGroup")
                        {
                            num = 4;
                            XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = XmlSchemaAttributeGroupRef.Read(reader, h);
                            if (xmlSchemaAttributeGroupRef != null)
                            {
                                xmlSchemaSimpleContentRestriction.attributes.Add(xmlSchemaAttributeGroupRef);
                            }
                            continue;
                        }
                    }
                    if (num <= 5 && reader.LocalName == "anyAttribute")
                    {
                        num = 6;
                        XmlSchemaAnyAttribute xmlSchemaAnyAttribute = XmlSchemaAnyAttribute.Read(reader, h);
                        if (xmlSchemaAnyAttribute != null)
                        {
                            xmlSchemaSimpleContentRestriction.AnyAttribute = xmlSchemaAnyAttribute;
                        }
                    }
                    else
                    {
                        reader.RaiseInvalidElementError();
                    }
                }
            }
            return(xmlSchemaSimpleContentRestriction);
        }
Ejemplo n.º 19
0
        void ImportAnyAttributeMember(XmlSchemaAnyAttribute any, CodeIdentifiers members) {
            SpecialMapping mapping = new SpecialMapping();
            mapping.TypeDesc = scope.GetTypeDesc(typeof(XmlAttribute));
            mapping.TypeName = mapping.TypeDesc.Name;

            AttributeAccessor accessor = new AttributeAccessor();
            accessor.Any = true;
            accessor.Mapping = mapping;

            MemberMapping member = new MemberMapping();
            member.Elements = new ElementAccessor[0];
            member.Attribute = accessor;
            member.Name = members.MakeRightCase("AnyAttr");
            member.Name = members.AddUnique(member.Name, member);
            member.TypeDesc = ((TypeMapping)accessor.Mapping).TypeDesc;
            member.TypeDesc = member.TypeDesc.CreateArrayTypeDesc();
        }
        //<restriction
        //base = QName
        //id = ID
        //{any attributes with non-schema namespace . . .}>
        //Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))
        //</restriction>
        internal static XmlSchemaSimpleContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleContentRestriction restriction = new XmlSchemaSimpleContentRestriction();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaComplexContentRestriction.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }

            restriction.LineNumber   = reader.LineNumber;
            restriction.LinePosition = reader.LinePosition;
            restriction.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception innerex;
                    restriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for base attribute", innerex);
                    }
                }
                else if (reader.Name == "id")
                {
                    restriction.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for restriction", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, restriction);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(restriction);
            }

            //Content:  1.annotation?,
            //		    2.simpleType?,
            //			3.(minExclusive |...| enumeration | whiteSpace | pattern)*,
            //			4.(attribute | attributeGroup)*,
            //			5.anyAttribute?
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaSimpleContentRestriction.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2; //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        restriction.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2 && reader.LocalName == "simpleType")
                {
                    level = 3;
                    XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h);
                    if (stype != null)
                    {
                        restriction.baseType = stype;
                    }
                    continue;
                }
                if (level <= 3)
                {
                    if (reader.LocalName == "minExclusive")
                    {
                        level = 3;
                        XmlSchemaMinExclusiveFacet minex = XmlSchemaMinExclusiveFacet.Read(reader, h);
                        if (minex != null)
                        {
                            restriction.facets.Add(minex);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "minInclusive")
                    {
                        level = 3;
                        XmlSchemaMinInclusiveFacet mini = XmlSchemaMinInclusiveFacet.Read(reader, h);
                        if (mini != null)
                        {
                            restriction.facets.Add(mini);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "maxExclusive")
                    {
                        level = 3;
                        XmlSchemaMaxExclusiveFacet maxex = XmlSchemaMaxExclusiveFacet.Read(reader, h);
                        if (maxex != null)
                        {
                            restriction.facets.Add(maxex);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "maxInclusive")
                    {
                        level = 3;
                        XmlSchemaMaxInclusiveFacet maxi = XmlSchemaMaxInclusiveFacet.Read(reader, h);
                        if (maxi != null)
                        {
                            restriction.facets.Add(maxi);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "totalDigits")
                    {
                        level = 3;
                        XmlSchemaTotalDigitsFacet total = XmlSchemaTotalDigitsFacet.Read(reader, h);
                        if (total != null)
                        {
                            restriction.facets.Add(total);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "fractionDigits")
                    {
                        level = 3;
                        XmlSchemaFractionDigitsFacet fraction = XmlSchemaFractionDigitsFacet.Read(reader, h);
                        if (fraction != null)
                        {
                            restriction.facets.Add(fraction);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "length")
                    {
                        level = 3;
                        XmlSchemaLengthFacet length = XmlSchemaLengthFacet.Read(reader, h);
                        if (length != null)
                        {
                            restriction.facets.Add(length);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "minLength")
                    {
                        level = 3;
                        XmlSchemaMinLengthFacet minlen = XmlSchemaMinLengthFacet.Read(reader, h);
                        if (minlen != null)
                        {
                            restriction.facets.Add(minlen);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "maxLength")
                    {
                        level = 3;
                        XmlSchemaMaxLengthFacet maxlen = XmlSchemaMaxLengthFacet.Read(reader, h);
                        if (maxlen != null)
                        {
                            restriction.facets.Add(maxlen);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "enumeration")
                    {
                        level = 3;
                        XmlSchemaEnumerationFacet enumeration = XmlSchemaEnumerationFacet.Read(reader, h);
                        if (enumeration != null)
                        {
                            restriction.facets.Add(enumeration);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "whiteSpace")
                    {
                        level = 3;
                        XmlSchemaWhiteSpaceFacet ws = XmlSchemaWhiteSpaceFacet.Read(reader, h);
                        if (ws != null)
                        {
                            restriction.facets.Add(ws);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "pattern")
                    {
                        level = 3;
                        XmlSchemaPatternFacet pattern = XmlSchemaPatternFacet.Read(reader, h);
                        if (pattern != null)
                        {
                            restriction.facets.Add(pattern);
                        }
                        continue;
                    }
                }
                if (level <= 4)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 4;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            restriction.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 4;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            restriction.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 5 && reader.LocalName == "anyAttribute")
                {
                    level = 6;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        restriction.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(restriction);
        }
 private XmlSchemaAnyAttribute CompileAnyAttributeIntersection(XmlSchemaAnyAttribute a, XmlSchemaAnyAttribute b) {
     if (a == null) {
         return b;
     }
     else if (b == null) {
         return a;
     }
     else {
         XmlSchemaAnyAttribute attribute = XmlSchemaAnyAttribute.Intersection(a, b, false); //false is for v1Compat
         if (attribute == null) {
             SendValidationEvent(Res.Sch_UnexpressibleAnyAttribute, a);
         }
         return attribute;
     }
 }
 private string DumpAttributes(XmlSchemaObjectTable attributeUses, XmlSchemaAnyAttribute attributeWildcard) {
     StringBuilder sb = new StringBuilder();
     sb.Append("[");
     bool first = true;
     foreach (XmlSchemaAttribute attribute in attributeUses.Values) {
         if (attribute.Use != XmlSchemaUse.Prohibited) {
             if (first) {
                 first = false;
             }
             else {
                 sb.Append(" ");
             }
             sb.Append(attribute.QualifiedName.Name);       
             if (attribute.Use == XmlSchemaUse.Optional || attribute.Use == XmlSchemaUse.None) {
                 sb.Append("?");                                                                  
             }
         }
     }
     if (attributeWildcard != null) {
         if (attributeUses.Count != 0) {
             sb.Append(" ");                                                                  
         }
         sb.Append("<");
         sb.Append(attributeWildcard.NamespaceList.ToString());
         sb.Append(">");
     }
     sb.Append("] - [");
     first = true;
     foreach (XmlSchemaAttribute attribute in attributeUses.Values) {
         if (attribute.Use == XmlSchemaUse.Prohibited) {
             if (first) {
                 first = false;
             }
             else {
                 sb.Append(" ");
             }
             sb.Append(attribute.QualifiedName.Name);       
         }
     }
     sb.Append("]");
     return sb.ToString();
 }
Ejemplo n.º 23
0
 private void PreprocessAttributes(XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, XmlSchemaObject parent) {
     for (int i = 0; i < attributes.Count; ++i) {
         SetParent(attributes[i], parent);
         XmlSchemaAttribute attr = attributes[i] as XmlSchemaAttribute;
         if (attr != null) {
             PreprocessLocalAttribute(attr);
         } 
         else { // XmlSchemaAttributeGroupRef
             XmlSchemaAttributeGroupRef attributeGroupRef = (XmlSchemaAttributeGroupRef)attributes[i];
             if (attributeGroupRef.RefName.IsEmpty) {
                 SendValidationEvent(Res.Sch_MissAttribute, "ref", attributeGroupRef);
             }
             else {
                 ValidateQNameAttribute(attributeGroupRef, "ref", attributeGroupRef.RefName);
             }
             PreprocessAnnotation(attributes[i]); //set parent of annotation child of attributeGroupRef
             ValidateIdAttribute(attributes[i]);
         }
     }
     if (anyAttribute != null) {
         try {
             SetParent(anyAttribute, parent);
             PreprocessAnnotation(anyAttribute); //set parent of annotation child of any attribute
             anyAttribute.BuildNamespaceList(this.targetNamespace);
         } 
         catch(FormatException fe) {
             SendValidationEvent(Res.Sch_InvalidAnyDetailed, new string[] {fe.Message}, fe, anyAttribute);
         }
         ValidateIdAttribute(anyAttribute);
     }
 }
        static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents) {
            XmlSchemaComplexType localAnyType = new XmlSchemaComplexType();
            localAnyType.SetQualifiedName(DatatypeImplementation.QnAnyType);

            XmlSchemaAny anyElement = new XmlSchemaAny();
            anyElement.MinOccurs = decimal.Zero;
            anyElement.MaxOccurs = decimal.MaxValue;

            anyElement.ProcessContents = processContents;
            anyElement.BuildNamespaceList(null);
            XmlSchemaSequence seq = new XmlSchemaSequence();
            seq.Items.Add(anyElement);

            localAnyType.SetContentTypeParticle(seq);
            localAnyType.SetContentType(XmlSchemaContentType.Mixed);

            localAnyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
            localAnyType.ElementDecl.SchemaType = localAnyType;

            //Create contentValidator for Any
            ParticleContentValidator contentValidator = new ParticleContentValidator(XmlSchemaContentType.Mixed);
            contentValidator.Start();
            contentValidator.OpenGroup();
            contentValidator.AddNamespaceList(anyElement.NamespaceList, anyElement);
            contentValidator.AddStar();
            contentValidator.CloseGroup();
            ContentValidator anyContentValidator = contentValidator.Finish(true);
            localAnyType.ElementDecl.ContentValidator = anyContentValidator;

            XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
            anyAttribute.ProcessContents = processContents;
            anyAttribute.BuildNamespaceList(null);
            localAnyType.SetAttributeWildcard(anyAttribute);
            localAnyType.ElementDecl.AnyAttribute = anyAttribute;
            return localAnyType;
        }
        //<extension
        //  base = QName
        //  id = ID
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
        //</extension>
        internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            extension.LineNumber   = reader.LineNumber;
            extension.LinePosition = reader.LinePosition;
            extension.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception innerex;
                    extension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for base attribute", innerex);
                    }
                }
                else if (reader.Name == "id")
                {
                    extension.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for extension", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, extension);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(extension);
            }
            //Content: 1. annotation?,
            //			(2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2; //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        extension.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "group")
                    {
                        level = 3;
                        XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader, h);
                        if (group != null)
                        {
                            extension.particle = group;
                        }
                        continue;
                    }
                    if (reader.LocalName == "all")
                    {
                        level = 3;
                        XmlSchemaAll all = XmlSchemaAll.Read(reader, h);
                        if (all != null)
                        {
                            extension.particle = all;
                        }
                        continue;
                    }
                    if (reader.LocalName == "choice")
                    {
                        level = 3;
                        XmlSchemaChoice choice = XmlSchemaChoice.Read(reader, h);
                        if (choice != null)
                        {
                            extension.particle = choice;
                        }
                        continue;
                    }
                    if (reader.LocalName == "sequence")
                    {
                        level = 3;
                        XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h);
                        if (sequence != null)
                        {
                            extension.particle = sequence;
                        }
                        continue;
                    }
                }
                if (level <= 3)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 3;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            extension.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 3;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            extension.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 4 && reader.LocalName == "anyAttribute")
                {
                    level = 5;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        extension.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(extension);
        }
Ejemplo n.º 26
0
 private void SetContainer(State state, object container) {
     switch (state) {
         case State.Root:
             break;
         case State.Schema:
             break;
         case State.Annotation:
             this.annotation = (XmlSchemaAnnotation)container;
             break;
         case State.Include:
             this.include = (XmlSchemaInclude)container;
             break;
         case State.Import:
             this.import = (XmlSchemaImport)container;
             break;
         case State.Element:
             this.element = (XmlSchemaElement)container;
             break;
         case State.Attribute:
             this.attribute = (XmlSchemaAttribute)container;
             break;
         case State.AttributeGroup:
             this.attributeGroup = (XmlSchemaAttributeGroup)container;
             break;
         case State.AttributeGroupRef:
             this.attributeGroupRef = (XmlSchemaAttributeGroupRef)container;
             break;
         case State.AnyAttribute:
             this.anyAttribute = (XmlSchemaAnyAttribute)container;
             break;
         case State.Group:
             this.group = (XmlSchemaGroup)container;
             break;
         case State.GroupRef:
             this.groupRef = (XmlSchemaGroupRef)container;
             break;
         case State.All:
             this.all = (XmlSchemaAll)container;
             break;
         case State.Choice:
             this.choice = (XmlSchemaChoice)container;
             break;
         case State.Sequence:
             this.sequence = (XmlSchemaSequence)container;
             break;
         case State.Any:
             this.anyElement = (XmlSchemaAny)container;
             break;
         case State.Notation:
             this.notation = (XmlSchemaNotation)container;
             break;
         case State.SimpleType:
             this.simpleType = (XmlSchemaSimpleType)container;
             break;
         case State.ComplexType:
             this.complexType = (XmlSchemaComplexType)container;
             break;
         case State.ComplexContent:
             this.complexContent = (XmlSchemaComplexContent)container;
             break;
         case State.ComplexContentExtension:
             this.complexContentExtension = (XmlSchemaComplexContentExtension)container;
             break;
         case State.ComplexContentRestriction:
             this.complexContentRestriction = (XmlSchemaComplexContentRestriction)container;
             break;
         case State.SimpleContent:
             this.simpleContent = (XmlSchemaSimpleContent)container;
             break;
         case State.SimpleContentExtension:
             this.simpleContentExtension = (XmlSchemaSimpleContentExtension)container;
             break;
         case State.SimpleContentRestriction:
             this.simpleContentRestriction = (XmlSchemaSimpleContentRestriction)container;
             break;
         case State.SimpleTypeUnion:
             this.simpleTypeUnion = (XmlSchemaSimpleTypeUnion)container;
             break;
         case State.SimpleTypeList:
             this.simpleTypeList = (XmlSchemaSimpleTypeList)container;
             break;
         case State.SimpleTypeRestriction:
             this.simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)container;
             break;
         case State.Unique:
         case State.Key:
         case State.KeyRef:
             this.identityConstraint = (XmlSchemaIdentityConstraint)container;
             break;
         case State.Selector:
         case State.Field:
             this.xpath = (XmlSchemaXPath)container;
             break;
         case State.MinExclusive:
         case State.MinInclusive:
         case State.MaxExclusive:
         case State.MaxInclusive:
         case State.TotalDigits:
         case State.FractionDigits:
         case State.Length:
         case State.MinLength:
         case State.MaxLength:
         case State.Enumeration:
         case State.Pattern:
         case State.WhiteSpace:
             this.facet = (XmlSchemaFacet)container;
             break;
         case State.AppInfo:
             this.appInfo = (XmlSchemaAppInfo)container;
             break;
         case State.Documentation:
             this.documentation = (XmlSchemaDocumentation)container;
             break;
         case State.Redefine:
             this.redefine = (XmlSchemaRedefine)container;
             break;
         default:
             Debug.Assert(false, "State is " + state);
             break;
     }
 }
Ejemplo n.º 27
0
        internal SchemaAttDef GetAttribute(SchemaElementDecl ed, XmlQualifiedName qname, ref bool skip)
        {
            SchemaAttDef attdef = null;

            if (ed != null)   // local attribute or XSD
            {
                skip   = false;
                attdef = ed.GetAttDef(qname);
                if (attdef == null)
                {
                    // In DTD, every attribute must be declared.
                    if (schemaType == SchemaType.DTD)
                    {
                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                    }
                    else if (schemaType == SchemaType.XDR)
                    {
                        if (ed.Content.IsOpen)
                        {
                            attdef = (SchemaAttDef)attributeDecls[qname];
                            if ((attdef == null) && ((qname.Namespace == String.Empty) || HasSchema(qname.Namespace)))
                            {
                                throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                            }
                        }
                        else
                        {
                            throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                        }
                    }
                    else   //XML Schema
                    {
                        XmlSchemaAnyAttribute any = ed.AnyAttribute;
                        if (any != null)
                        {
                            if (any.NamespaceList.Allows(qname))
                            {
                                if (any.ProcessContentsCorrect != XmlSchemaContentProcessing.Skip)
                                {
                                    attdef = (SchemaAttDef)attributeDecls[qname];
                                    if (attdef == null && any.ProcessContentsCorrect == XmlSchemaContentProcessing.Strict)
                                    {
                                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                                    }
                                }
                                else
                                {
                                    skip = true;
                                }
                            }
                            else
                            {
                                throw new XmlSchemaException(Res.Sch_ProhibitedAttribute, qname.ToString());
                            }
                        }
                        else if (ed.ProhibitedAttributes[qname] != null)
                        {
                            throw new XmlSchemaException(Res.Sch_ProhibitedAttribute, qname.ToString());
                        }
                        else
                        {
                            throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                        }
                    }
                }
            }
            else   // global attribute
            {
                if (!skip)
                {
                    attdef = (SchemaAttDef)attributeDecls[qname];
                    if ((attdef == null) && HasSchema(qname.Namespace))
                    {
                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                    }
                }
            }
            return(attdef);
        }
Ejemplo n.º 28
0
        //<anyAttribute
        //  id = ID
        //  namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )  : ##any
        //  processContents = (lax | skip | strict) : strict
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?)
        //</anyAttribute>
        internal static XmlSchemaAnyAttribute Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAnyAttribute any = new XmlSchemaAnyAttribute();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaAnyAttribute.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }

            any.LineNumber   = reader.LineNumber;
            any.LinePosition = reader.LinePosition;
            any.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    any.Id = reader.Value;
                }
                else if (reader.Name == "namespace")
                {
                    any.nameSpace = reader.Value;
                }
                else if (reader.Name == "processContents")
                {
                    Exception innerex;
                    any.processing = XmlSchemaUtil.ReadProcessingAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for processContents", innerex);
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for anyAttribute", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, any);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(any);
            }

            //  Content: (annotation?)
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaAnyAttribute.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                          //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        any.Annotation = annotation;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(any);
        }
Ejemplo n.º 29
0
        public static int ValidateAttributesResolved(
            XmlSchemaObjectTable attributesResolved,
            ValidationEventHandler h,
            XmlSchema schema,
            XmlSchemaObjectCollection attributes,
            XmlSchemaAnyAttribute anyAttribute,
            ref XmlSchemaAnyAttribute anyAttributeUse,
            XmlSchemaAttributeGroup redefined,
            bool skipEquivalent)
        {
            int errorCount = 0;

            if (anyAttribute != null && anyAttributeUse == null)
            {
                anyAttributeUse = anyAttribute;
            }

            ArrayList newAttrNames = new ArrayList();

            foreach (XmlSchemaObject xsobj in attributes)
            {
                XmlSchemaAttributeGroupRef grpRef = xsobj as XmlSchemaAttributeGroupRef;
                if (grpRef != null)
                {
                    // Resolve attributeGroup redefinition.
                    XmlSchemaAttributeGroup grp = null;
                    if (redefined != null && grpRef.RefName == redefined.QualifiedName)
                    {
                        grp = redefined;
                    }
                    else
                    {
                        grp = schema.FindAttributeGroup(grpRef.RefName);
                    }
                    // otherwise, it might be missing sub components.
                    if (grp == null)
                    {
                        if (!schema.missedSubComponents)                        // && schema.Schemas [grpRef.RefName.Namespace] != null)
                        {
                            grpRef.error(h, "Referenced attribute group " + grpRef.RefName + " was not found in the corresponding schema.");
                        }
                        continue;
                    }
                    if (grp.AttributeGroupRecursionCheck)
                    {
                        grp.error(h, "Attribute group recursion was found: " + grpRef.RefName);
                        continue;
                    }
                    try {
                        grp.AttributeGroupRecursionCheck = true;
                        errorCount += grp.Validate(h, schema);
                    } finally {
                        grp.AttributeGroupRecursionCheck = false;
                    }
                    if (grp.AnyAttributeUse != null)
                    {
                        if (anyAttribute == null)
                        {
                            anyAttributeUse = grp.AnyAttributeUse;
                        }
                    }
                    foreach (DictionaryEntry entry in grp.AttributeUses)
                    {
                        XmlSchemaAttribute attr = (XmlSchemaAttribute)entry.Value;

                        if (StrictMsCompliant && attr.Use == XmlSchemaUse.Prohibited)
                        {
                            continue;
                        }

                        if (attr.RefName != null && attr.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !AreAttributesEqual(attr, attributesResolved [attr.RefName] as XmlSchemaAttribute)))
                        {
                            AddToTable(attributesResolved, attr, attr.RefName, h);
                        }
                        else if (!skipEquivalent || !AreAttributesEqual(attr, attributesResolved [attr.QualifiedName] as XmlSchemaAttribute))
                        {
                            AddToTable(attributesResolved, attr, attr.QualifiedName, h);
                        }
                    }
                }
                else
                {
                    XmlSchemaAttribute attr = xsobj as XmlSchemaAttribute;
                    if (attr != null)
                    {
                        errorCount += attr.Validate(h, schema);

                        if (newAttrNames.Contains(attr.QualifiedName))
                        {
                            attr.error(h, String.Format("Duplicate attributes was found for '{0}'", attr.QualifiedName));
                        }
                        newAttrNames.Add(attr.QualifiedName);


                        if (StrictMsCompliant && attr.Use == XmlSchemaUse.Prohibited)
                        {
                            continue;
                        }

                        if (attr.RefName != null && attr.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !AreAttributesEqual(attr, attributesResolved [attr.RefName] as XmlSchemaAttribute)))
                        {
                            AddToTable(attributesResolved, attr, attr.RefName, h);
                        }
                        else if (!skipEquivalent || !AreAttributesEqual(attr, attributesResolved [attr.QualifiedName] as XmlSchemaAttribute))
                        {
                            AddToTable(attributesResolved, attr, attr.QualifiedName, h);
                        }
                    }
                    else
                    {
                        if (anyAttribute != null)
                        {
                            anyAttributeUse = (XmlSchemaAnyAttribute)xsobj;
                            anyAttribute.Validate(h, schema);
                        }
                    }
                }
            }
            return(errorCount);
        }
        internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaComplexContentExtension xmlSchemaComplexContentExtension = new XmlSchemaComplexContentExtension();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "extension")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaComplexContentExtension.LineNumber   = reader.LineNumber;
            xmlSchemaComplexContentExtension.LinePosition = reader.LinePosition;
            xmlSchemaComplexContentExtension.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception ex;
                    xmlSchemaComplexContentExtension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out ex);
                    if (ex != null)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is not a valid value for base attribute", ex);
                    }
                }
                else if (reader.Name == "id")
                {
                    xmlSchemaComplexContentExtension.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
                {
                    XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for extension", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaComplexContentExtension);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaComplexContentExtension);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "extension")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaComplexContentExtension.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    if (num <= 2)
                    {
                        if (reader.LocalName == "group")
                        {
                            num = 3;
                            XmlSchemaGroupRef xmlSchemaGroupRef = XmlSchemaGroupRef.Read(reader, h);
                            if (xmlSchemaGroupRef != null)
                            {
                                xmlSchemaComplexContentExtension.particle = xmlSchemaGroupRef;
                            }
                            continue;
                        }
                        if (reader.LocalName == "all")
                        {
                            num = 3;
                            XmlSchemaAll xmlSchemaAll = XmlSchemaAll.Read(reader, h);
                            if (xmlSchemaAll != null)
                            {
                                xmlSchemaComplexContentExtension.particle = xmlSchemaAll;
                            }
                            continue;
                        }
                        if (reader.LocalName == "choice")
                        {
                            num = 3;
                            XmlSchemaChoice xmlSchemaChoice = XmlSchemaChoice.Read(reader, h);
                            if (xmlSchemaChoice != null)
                            {
                                xmlSchemaComplexContentExtension.particle = xmlSchemaChoice;
                            }
                            continue;
                        }
                        if (reader.LocalName == "sequence")
                        {
                            num = 3;
                            XmlSchemaSequence xmlSchemaSequence = XmlSchemaSequence.Read(reader, h);
                            if (xmlSchemaSequence != null)
                            {
                                xmlSchemaComplexContentExtension.particle = xmlSchemaSequence;
                            }
                            continue;
                        }
                    }
                    if (num <= 3)
                    {
                        if (reader.LocalName == "attribute")
                        {
                            num = 3;
                            XmlSchemaAttribute xmlSchemaAttribute = XmlSchemaAttribute.Read(reader, h);
                            if (xmlSchemaAttribute != null)
                            {
                                xmlSchemaComplexContentExtension.Attributes.Add(xmlSchemaAttribute);
                            }
                            continue;
                        }
                        if (reader.LocalName == "attributeGroup")
                        {
                            num = 3;
                            XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = XmlSchemaAttributeGroupRef.Read(reader, h);
                            if (xmlSchemaAttributeGroupRef != null)
                            {
                                xmlSchemaComplexContentExtension.attributes.Add(xmlSchemaAttributeGroupRef);
                            }
                            continue;
                        }
                    }
                    if (num <= 4 && reader.LocalName == "anyAttribute")
                    {
                        num = 5;
                        XmlSchemaAnyAttribute xmlSchemaAnyAttribute = XmlSchemaAnyAttribute.Read(reader, h);
                        if (xmlSchemaAnyAttribute != null)
                        {
                            xmlSchemaComplexContentExtension.AnyAttribute = xmlSchemaAnyAttribute;
                        }
                    }
                    else
                    {
                        reader.RaiseInvalidElementError();
                    }
                }
            }
            return(xmlSchemaComplexContentExtension);
        }
 void Write33_XmlSchemaAnyAttribute(XmlSchemaAnyAttribute o) {
     if ((object)o == null) return;
     WriteStartElement("anyAttribute");
     
     WriteAttribute(@"id", @"", ((System.String)o.@Id));
     WriteAttribute("namespace", "", ToString(o.NamespaceList));
     XmlSchemaContentProcessing process = o.@ProcessContents == XmlSchemaContentProcessing.@None ? XmlSchemaContentProcessing.Strict : o.@ProcessContents;
     WriteAttribute(@"processContents", @"", Write34_XmlSchemaContentProcessing(process));
     WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o);
     Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation);
     WriteEndElement();
 }
 internal void SetAttributeWildcard(XmlSchemaAnyAttribute value) {
      attributeWildcard = value; 
 }
Ejemplo n.º 33
0
 internal static bool IsSubset(XmlSchemaAnyAttribute sub, XmlSchemaAnyAttribute super)
 {
     return(NamespaceList.IsSubset(sub.NamespaceList, super.NamespaceList));
 }
        private XmlQueryCardinality AddAttributes(List<XmlQueryType> list, XmlSchemaObjectTable attributeUses, XmlSchemaAnyAttribute attributeWildcard, XmlQueryType filter) {
            XmlQueryCardinality card = XmlQueryCardinality.Zero;
            if (attributeWildcard != null) {
                XmlSchemaType attributeSchemaType = attributeWildcard.ProcessContentsCorrect == XmlSchemaContentProcessing.Skip ? DatatypeImplementation.UntypedAtomicType : DatatypeImplementation.AnySimpleType;

                // wildcard will match more then one attribute
                switch (attributeWildcard.NamespaceList.Type) {
                case NamespaceList.ListType.Set:
                    foreach (string ns in attributeWildcard.NamespaceList.Enumerate) {
                        card += AddFilteredPrime(list, CreateAttributeType(ns, false, attributeSchemaType), filter);
                    }
                    break;
                case NamespaceList.ListType.Other:
                    card += AddFilteredPrime(list, CreateAttributeType(attributeWildcard.NamespaceList.Excluded, true, attributeSchemaType), filter);
                    break;
                case NamespaceList.ListType.Any:
                default:
                    card +=  AddFilteredPrime(list, attributeWildcard.ProcessContentsCorrect == XmlSchemaContentProcessing.Skip ? UntypedAttribute : Attribute, filter);
                    break;
                }
                // Always optional
                card *= XmlQueryCardinality.ZeroOrOne;
            }
            foreach (XmlSchemaAttribute attribute in attributeUses.Values) {
                XmlQueryCardinality cardAttr = AddFilteredPrime(list, CreateAttributeType(attribute), filter);
                if (cardAttr != XmlQueryCardinality.Zero) {
                    Debug.Assert(cardAttr == XmlQueryCardinality.ZeroOrOne || cardAttr == XmlQueryCardinality.One);
                    card += (attribute.Use == XmlSchemaUse.Optional ? XmlQueryCardinality.ZeroOrOne : cardAttr);
                }
            }
            return card;
        }
Ejemplo n.º 35
0
        internal static XmlSchemaAttributeGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAttributeGroup xmlSchemaAttributeGroup = new XmlSchemaAttributeGroup();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "attributeGroup")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaAttributeGroup.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }
            xmlSchemaAttributeGroup.LineNumber   = reader.LineNumber;
            xmlSchemaAttributeGroup.LinePosition = reader.LinePosition;
            xmlSchemaAttributeGroup.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaAttributeGroup.Id = reader.Value;
                }
                else if (reader.Name == "name")
                {
                    xmlSchemaAttributeGroup.name = reader.Value;
                }
                else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
                {
                    XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for attributeGroup in this context", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaAttributeGroup);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaAttributeGroup);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "attributeGroup")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaAttributeGroup.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaAttributeGroup.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    if (num <= 2)
                    {
                        if (reader.LocalName == "attribute")
                        {
                            num = 2;
                            XmlSchemaAttribute xmlSchemaAttribute = XmlSchemaAttribute.Read(reader, h);
                            if (xmlSchemaAttribute != null)
                            {
                                xmlSchemaAttributeGroup.Attributes.Add(xmlSchemaAttribute);
                            }
                            continue;
                        }
                        if (reader.LocalName == "attributeGroup")
                        {
                            num = 2;
                            XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = XmlSchemaAttributeGroupRef.Read(reader, h);
                            if (xmlSchemaAttributeGroupRef != null)
                            {
                                xmlSchemaAttributeGroup.attributes.Add(xmlSchemaAttributeGroupRef);
                            }
                            continue;
                        }
                    }
                    if (num <= 3 && reader.LocalName == "anyAttribute")
                    {
                        num = 4;
                        XmlSchemaAnyAttribute xmlSchemaAnyAttribute = XmlSchemaAnyAttribute.Read(reader, h);
                        if (xmlSchemaAnyAttribute != null)
                        {
                            xmlSchemaAttributeGroup.AnyAttribute = xmlSchemaAnyAttribute;
                        }
                    }
                    else
                    {
                        reader.RaiseInvalidElementError();
                    }
                }
            }
            return(xmlSchemaAttributeGroup);
        }
        private void CompileLocalAttributes(XmlSchemaComplexType baseType, XmlSchemaComplexType derivedType, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, XmlSchemaDerivationMethod derivedBy) {
            XmlSchemaAnyAttribute baseAttributeWildcard = baseType != null ? baseType.AttributeWildcard : null;  
            for (int i = 0; i < attributes.Count; ++i) {
                XmlSchemaAttribute attr = attributes[i] as XmlSchemaAttribute;
                if (attr != null) {
                    if (attr.Use != XmlSchemaUse.Prohibited) {
                        CompileAttribute(attr);
                    }
                    if (attr.Use != XmlSchemaUse.Prohibited || 
                        (attr.Use == XmlSchemaUse.Prohibited && derivedBy == XmlSchemaDerivationMethod.Restriction && baseType != XmlSchemaComplexType.AnyType)) {

                        if (derivedType.AttributeUses[attr.QualifiedName] == null) {
                            derivedType.AttributeUses.Add(attr.QualifiedName, attr);
                        }
                        else  {
                            SendValidationEvent(Res.Sch_DupAttributeUse, attr.QualifiedName.ToString(), attr);
                        }
                    }
                    else {
                        SendValidationEvent(Res.Sch_AttributeIgnored, attr.QualifiedName.ToString(), attr, XmlSeverityType.Warning);
                    }

                }
                else { // is XmlSchemaAttributeGroupRef
                    XmlSchemaAttributeGroupRef attributeGroupRef = (XmlSchemaAttributeGroupRef) attributes[i];
                    XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup)attributeGroups[attributeGroupRef.RefName];
                    if (attributeGroup != null) {
                        CompileAttributeGroup(attributeGroup);
                        foreach (XmlSchemaAttribute attribute in attributeGroup.AttributeUses.Values) {
                          if (attribute.Use != XmlSchemaUse.Prohibited || 
                             (attribute.Use == XmlSchemaUse.Prohibited && derivedBy == XmlSchemaDerivationMethod.Restriction && baseType != XmlSchemaComplexType.AnyType)) {
                            if (derivedType.AttributeUses[attribute.QualifiedName] == null) {
                                derivedType.AttributeUses.Add(attribute.QualifiedName, attribute);
                            }
                            else {
                                SendValidationEvent(Res.Sch_DupAttributeUse, attribute.QualifiedName.ToString(), attributeGroupRef);
                            }
                          }
                          else {
                            SendValidationEvent(Res.Sch_AttributeIgnored, attribute.QualifiedName.ToString(), attribute, XmlSeverityType.Warning);
                          }

                        }
                        anyAttribute = CompileAnyAttributeIntersection(anyAttribute, attributeGroup.AttributeWildcard);
                    }
                    else {
                        SendValidationEvent(Res.Sch_UndefAttributeGroupRef, attributeGroupRef.RefName.ToString(), attributeGroupRef);
                    }
                }
            }

            // check derivation rules
            if (baseType != null) {
                if (derivedBy == XmlSchemaDerivationMethod.Extension) {
                    derivedType.SetAttributeWildcard(CompileAnyAttributeUnion(anyAttribute, baseAttributeWildcard));
                    foreach(XmlSchemaAttribute attributeBase in baseType.AttributeUses.Values) {
                        XmlSchemaAttribute attribute = (XmlSchemaAttribute)derivedType.AttributeUses[attributeBase.QualifiedName];
                        if (attribute == null) {
                            derivedType.AttributeUses.Add(attributeBase.QualifiedName, attributeBase);
                        }
                        else {
                            Debug.Assert(attribute.Use != XmlSchemaUse.Prohibited);
                            if (attributeBase.Use != XmlSchemaUse.Prohibited && attribute.AttributeSchemaType != attributeBase.AttributeSchemaType) { //Extension allows previously prohibited attributes to be re-added, 
                                SendValidationEvent(Res.Sch_InvalidAttributeExtension, attribute);
                            }
                        }
                    }
                }
                else {  // derivedBy == XmlSchemaDerivationMethod.Restriction
                    // Schema Component Constraint: Derivation Valid (Restriction, Complex)
                    if ((anyAttribute != null) && (baseAttributeWildcard == null || !XmlSchemaAnyAttribute.IsSubset(anyAttribute, baseAttributeWildcard) || !IsProcessContentsRestricted(baseType, anyAttribute, baseAttributeWildcard)) ) {
                        SendValidationEvent(Res.Sch_InvalidAnyAttributeRestriction, derivedType);
                    }
                    else {
                        derivedType.SetAttributeWildcard(anyAttribute); //complete wildcard
                    }

                    // Add form the base
                    foreach(XmlSchemaAttribute attributeBase in baseType.AttributeUses.Values) {
                        XmlSchemaAttribute attribute = (XmlSchemaAttribute)derivedType.AttributeUses[attributeBase.QualifiedName];
                        if (attribute == null) {
                            derivedType.AttributeUses.Add(attributeBase.QualifiedName, attributeBase);
                        } 
                        else {
                            if (attributeBase.Use == XmlSchemaUse.Prohibited && attribute.Use != XmlSchemaUse.Prohibited) {
#if DEBUG
                                string position = string.Empty;
                                if (derivedType.SourceUri != null) {
                                    position = " in " + derivedType.SourceUri + "(" + derivedType.LineNumber + ", " + derivedType.LinePosition + ")";
                                }
                                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "Invalid complexType attributes restriction" + position);
                                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "     Base    " + DumpAttributes(baseType.AttributeUses, baseType.AttributeWildcard));
                                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "     Derived " + DumpAttributes(derivedType.AttributeUses, derivedType.AttributeWildcard));
#endif
                                SendValidationEvent(Res.Sch_AttributeRestrictionProhibited, attribute);
                            } 
                            else if (attributeBase.Use == XmlSchemaUse.Required && (attribute.Use != XmlSchemaUse.Required)) { //If base is required, derived should also be required
                                SendValidationEvent(Res.Sch_AttributeUseInvalid, attribute);
                            }
                            else if (attribute.Use == XmlSchemaUse.Prohibited) {
                                continue;
                            }
                            else if (attributeBase.AttributeSchemaType == null || attribute.AttributeSchemaType == null || !XmlSchemaType.IsDerivedFrom(attribute.AttributeSchemaType, attributeBase.AttributeSchemaType, XmlSchemaDerivationMethod.Empty)) {
                                SendValidationEvent(Res.Sch_AttributeRestrictionInvalid, attribute);
                            }
                            else if (!IsFixedEqual(attributeBase.AttDef, attribute.AttDef)) {
                                SendValidationEvent(Res.Sch_AttributeFixedInvalid, attribute);
                            }
                        }
                    }

                    // Check additional ones are valid restriction of base's wildcard
                    foreach(XmlSchemaAttribute attribute in derivedType.AttributeUses.Values) {
                        XmlSchemaAttribute attributeBase = (XmlSchemaAttribute)baseType.AttributeUses[attribute.QualifiedName];
                        if (attributeBase != null) {
                            continue;
                        }
                        if (baseAttributeWildcard == null || !baseAttributeWildcard.Allows(attribute.QualifiedName)) {
#if DEBUG
                            string position = string.Empty;
                            if (derivedType.SourceUri != null) {
                                position = " in " + derivedType.SourceUri + "(" + derivedType.LineNumber + ", " + derivedType.LinePosition + ")";
                            }
                            Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "Invalid complexType attributes restriction" + position);
                            Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "     Base    " + DumpAttributes(baseType.AttributeUses, baseType.AttributeWildcard));
                            Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, "     Derived " + DumpAttributes(derivedType.AttributeUses, derivedType.AttributeWildcard));
#endif
                            SendValidationEvent(Res.Sch_AttributeRestrictionInvalidFromWildcard, attribute);
                        }
                    }
                }
            } 
            else {
                derivedType.SetAttributeWildcard(anyAttribute);
            }
       }
Ejemplo n.º 37
0
 // 3.10.6 Wildcard Subset
 internal void ValidateWildcardSubset(XmlSchemaAnyAttribute other,
                                      ValidationEventHandler h, XmlSchema schema)
 {
     wildcard.ValidateWildcardSubset(other.wildcard, h, schema);
 }
 private bool IsProcessContentsRestricted(XmlSchemaComplexType baseType, XmlSchemaAnyAttribute derivedAttributeWildcard, XmlSchemaAnyAttribute baseAttributeWildcard) {
     if (baseType == XmlSchemaComplexType.AnyType) {
         return true;
     }
     if ((int)derivedAttributeWildcard.ProcessContentsCorrect >= (int)baseAttributeWildcard.ProcessContentsCorrect) {
         return true;
     }
     return false;
 }
Ejemplo n.º 39
0
        void WriteAttributes(XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
        {
            foreach (XmlSchemaObject at in atts) {
                if (at is XmlSchemaAttribute) {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
                    XmlSchemaAttribute refAttr = attr;

                    // refAttr.Form; TODO

                    if (!attr.RefName.IsEmpty) {
                        refAttr = FindRefAttribute(attr.RefName);
                        if (refAttr == null) throw new InvalidOperationException("Global attribute not found: " + attr.RefName);
                    }

                    string val;
                    if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType(refAttr.SchemaTypeName);
                    else val = FindBuiltInType((XmlSchemaSimpleType)refAttr.SchemaType);

                    xtw.WriteAttributeString(refAttr.Name, val);
                }
                else if (at is XmlSchemaAttributeGroupRef) {
                    XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
                    XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup)schemas.Find(gref.RefName, typeof(XmlSchemaAttributeGroup));
                    WriteAttributes(xtw, grp.Attributes, grp.AnyAttribute);
                }
            }

            if (anyat != null)
                xtw.WriteAttributeString("custom-attribute", "value");
        }
Ejemplo n.º 40
0
		internal static XmlSchema BuildSchema (DiscoveryVersion version)
		{
			var schema = new XmlSchema () { TargetNamespace = version.Namespace };

			var anyAttr = new XmlSchemaAnyAttribute () { Namespace = "##other", ProcessContents = XmlSchemaContentProcessing.Lax };

			var probePart = new XmlSchemaSequence ();
			probePart.Items.Add (new XmlSchemaElement () { RefName = new XmlQualifiedName ("Types", version.Namespace), MinOccurs = 0 });
			probePart.Items.Add (new XmlSchemaElement () { RefName = new XmlQualifiedName ("Scopes", version.Namespace), MinOccurs = 0 });
			probePart.Items.Add (new XmlSchemaAny () { MinOccurs = 0, MaxOccursString = "unbounded", Namespace = "##other", ProcessContents = XmlSchemaContentProcessing.Lax });
			var ct = new XmlSchemaComplexType () { Name = "ProbeType", Particle = probePart, AnyAttribute = anyAttr };
			schema.Items.Add (ct);

			schema.Items.Add (new XmlSchemaSimpleType () { Name = "QNameListType", Content = new XmlSchemaSimpleTypeList () { ItemTypeName = new XmlQualifiedName ("QName", XmlSchema.Namespace) } });

			var scr = new XmlSchemaSimpleContentRestriction () { BaseTypeName = new XmlQualifiedName ("UriListType", version.Namespace), AnyAttribute = anyAttr };
			scr.Attributes.Add (new XmlSchemaAttribute () { Name = "matchBy", SchemaTypeName = new XmlQualifiedName ("anyURI", XmlSchema.Namespace) });
			schema.Items.Add (new XmlSchemaComplexType () { Name = "ScopesType", ContentModel = new XmlSchemaSimpleContent () { Content = scr } });

			schema.Items.Add (new XmlSchemaSimpleType () { Name = "UriListType", Content = new XmlSchemaSimpleTypeList () { ItemTypeName = new XmlQualifiedName ("anyURI", XmlSchema.Namespace) } });

			schema.Items.Add (new XmlSchemaElement () { Name = "Types", SchemaTypeName = new XmlQualifiedName ("QNameListType", version.Namespace) });
			schema.Items.Add (new XmlSchemaElement () { Name = "Scopes", SchemaTypeName = new XmlQualifiedName ("ScopesType", version.Namespace) });

			return schema;
		}
        internal SchemaAttDef GetAttributeXsd(SchemaElementDecl ed, XmlQualifiedName qname, XmlSchemaObject partialValidationType, out AttributeMatchState attributeMatchState)
        {
            SchemaAttDef attdef = null;

            attributeMatchState = AttributeMatchState.UndeclaredAttribute;
            if (ed != null)
            {
                attdef = ed.GetAttDef(qname);
                if (attdef != null)
                {
                    attributeMatchState = AttributeMatchState.AttributeFound;
                    return(attdef);
                }
                XmlSchemaAnyAttribute any = ed.AnyAttribute;
                if (any != null)
                {
                    if (!any.NamespaceList.Allows(qname))
                    {
                        attributeMatchState = AttributeMatchState.ProhibitedAnyAttribute;
                    }
                    else if (any.ProcessContentsCorrect != XmlSchemaContentProcessing.Skip)
                    {
                        if (attributeDecls.TryGetValue(qname, out attdef))
                        {
                            if (attdef.Datatype.TypeCode == XmlTypeCode.Id)   //anyAttribute match whose type is ID
                            {
                                attributeMatchState = AttributeMatchState.AnyIdAttributeFound;
                            }
                            else
                            {
                                attributeMatchState = AttributeMatchState.AttributeFound;
                            }
                        }
                        else if (any.ProcessContentsCorrect == XmlSchemaContentProcessing.Lax)
                        {
                            attributeMatchState = AttributeMatchState.AnyAttributeLax;
                        }
                    }
                    else
                    {
                        attributeMatchState = AttributeMatchState.AnyAttributeSkip;
                    }
                }
                else if (ed.ProhibitedAttributes.ContainsKey(qname))
                {
                    attributeMatchState = AttributeMatchState.ProhibitedAttribute;
                }
            }
            else if (partialValidationType != null)
            {
                XmlSchemaAttribute attr = partialValidationType as XmlSchemaAttribute;
                if (attr != null)
                {
                    if (qname.Equals(attr.QualifiedName))
                    {
                        attdef = attr.AttDef;
                        attributeMatchState = AttributeMatchState.AttributeFound;
                    }
                    else
                    {
                        attributeMatchState = AttributeMatchState.AttributeNameMismatch;
                    }
                }
                else
                {
                    attributeMatchState = AttributeMatchState.ValidateAttributeInvalidCall;
                }
            }
            else
            {
                if (attributeDecls.TryGetValue(qname, out attdef))
                {
                    attributeMatchState = AttributeMatchState.AttributeFound;
                }
                else
                {
                    attributeMatchState = AttributeMatchState.UndeclaredElementAndAttribute;
                }
            }
            return(attdef);
        }
 private void CompileLocalAttributes(XmlSchemaComplexType baseType, XmlSchemaComplexType derivedType, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, XmlSchemaDerivationMethod derivedBy)
 {
     XmlSchemaAnyAttribute b = (baseType != null) ? baseType.AttributeWildcard : null;
     for (int i = 0; i < attributes.Count; i++)
     {
         XmlSchemaAttribute xa = attributes[i] as XmlSchemaAttribute;
         if (xa != null)
         {
             if (xa.Use != XmlSchemaUse.Prohibited)
             {
                 this.CompileAttribute(xa);
             }
             if ((xa.Use != XmlSchemaUse.Prohibited) || (((xa.Use == XmlSchemaUse.Prohibited) && (derivedBy == XmlSchemaDerivationMethod.Restriction)) && (baseType != XmlSchemaComplexType.AnyType)))
             {
                 if (derivedType.AttributeUses[xa.QualifiedName] == null)
                 {
                     derivedType.AttributeUses.Add(xa.QualifiedName, xa);
                 }
                 else
                 {
                     base.SendValidationEvent("Sch_DupAttributeUse", xa.QualifiedName.ToString(), xa);
                 }
             }
             else
             {
                 base.SendValidationEvent("Sch_AttributeIgnored", xa.QualifiedName.ToString(), xa, XmlSeverityType.Warning);
             }
         }
         else
         {
             XmlSchemaAttributeGroupRef source = (XmlSchemaAttributeGroupRef) attributes[i];
             XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup) this.schema.AttributeGroups[source.RefName];
             if (attributeGroup != null)
             {
                 this.CompileAttributeGroup(attributeGroup);
                 foreach (XmlSchemaAttribute attribute3 in attributeGroup.AttributeUses.Values)
                 {
                     if ((attribute3.Use != XmlSchemaUse.Prohibited) || (((attribute3.Use == XmlSchemaUse.Prohibited) && (derivedBy == XmlSchemaDerivationMethod.Restriction)) && (baseType != XmlSchemaComplexType.AnyType)))
                     {
                         if (derivedType.AttributeUses[attribute3.QualifiedName] == null)
                         {
                             derivedType.AttributeUses.Add(attribute3.QualifiedName, attribute3);
                         }
                         else
                         {
                             base.SendValidationEvent("Sch_DupAttributeUse", attribute3.QualifiedName.ToString(), source);
                         }
                     }
                     else
                     {
                         base.SendValidationEvent("Sch_AttributeIgnored", attribute3.QualifiedName.ToString(), attribute3, XmlSeverityType.Warning);
                     }
                 }
                 anyAttribute = this.CompileAnyAttributeIntersection(anyAttribute, attributeGroup.AttributeWildcard);
             }
             else
             {
                 base.SendValidationEvent("Sch_UndefAttributeGroupRef", source.RefName.ToString(), source);
             }
         }
     }
     if (baseType != null)
     {
         if (derivedBy == XmlSchemaDerivationMethod.Extension)
         {
             derivedType.SetAttributeWildcard(this.CompileAnyAttributeUnion(anyAttribute, b));
             foreach (XmlSchemaAttribute attribute4 in baseType.AttributeUses.Values)
             {
                 XmlSchemaAttribute attribute5 = (XmlSchemaAttribute) derivedType.AttributeUses[attribute4.QualifiedName];
                 if (attribute5 != null)
                 {
                     if ((attribute5.AttributeSchemaType != attribute4.AttributeSchemaType) || (attribute4.Use == XmlSchemaUse.Prohibited))
                     {
                         base.SendValidationEvent("Sch_InvalidAttributeExtension", attribute5);
                     }
                 }
                 else
                 {
                     derivedType.AttributeUses.Add(attribute4.QualifiedName, attribute4);
                 }
             }
         }
         else
         {
             if ((anyAttribute != null) && ((b == null) || !XmlSchemaAnyAttribute.IsSubset(anyAttribute, b)))
             {
                 base.SendValidationEvent("Sch_InvalidAnyAttributeRestriction", derivedType);
             }
             else
             {
                 derivedType.SetAttributeWildcard(anyAttribute);
             }
             foreach (XmlSchemaAttribute attribute6 in baseType.AttributeUses.Values)
             {
                 XmlSchemaAttribute attribute7 = (XmlSchemaAttribute) derivedType.AttributeUses[attribute6.QualifiedName];
                 if (attribute7 == null)
                 {
                     derivedType.AttributeUses.Add(attribute6.QualifiedName, attribute6);
                 }
                 else if ((attribute6.Use == XmlSchemaUse.Prohibited) && (attribute7.Use != XmlSchemaUse.Prohibited))
                 {
                     base.SendValidationEvent("Sch_AttributeRestrictionProhibited", attribute7);
                 }
                 else if ((attribute7.Use != XmlSchemaUse.Prohibited) && (((attribute6.AttributeSchemaType == null) || (attribute7.AttributeSchemaType == null)) || !XmlSchemaType.IsDerivedFrom(attribute7.AttributeSchemaType, attribute6.AttributeSchemaType, XmlSchemaDerivationMethod.Empty)))
                 {
                     base.SendValidationEvent("Sch_AttributeRestrictionInvalid", attribute7);
                 }
             }
             foreach (XmlSchemaAttribute attribute8 in derivedType.AttributeUses.Values)
             {
                 if ((((XmlSchemaAttribute) baseType.AttributeUses[attribute8.QualifiedName]) == null) && ((b == null) || !b.Allows(attribute8.QualifiedName)))
                 {
                     base.SendValidationEvent("Sch_AttributeRestrictionInvalidFromWildcard", attribute8);
                 }
             }
         }
     }
     else
     {
         derivedType.SetAttributeWildcard(anyAttribute);
     }
 }
Ejemplo n.º 43
0
 internal void SetAttributeWildcard(XmlSchemaAnyAttribute value)
 {
     attributeWildcard = value;
 }
Ejemplo n.º 44
0
 internal static bool IsSubset(XmlSchemaAnyAttribute sub, XmlSchemaAnyAttribute super)
 {
     return NamespaceList.IsSubset(sub.NamespaceList, super.NamespaceList);
 }
        internal static XmlSchemaAnyAttribute Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAnyAttribute xmlSchemaAnyAttribute = new XmlSchemaAnyAttribute();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "anyAttribute")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaAnyAttribute.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }
            xmlSchemaAnyAttribute.LineNumber   = reader.LineNumber;
            xmlSchemaAnyAttribute.LinePosition = reader.LinePosition;
            xmlSchemaAnyAttribute.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaAnyAttribute.Id = reader.Value;
                }
                else if (reader.Name == "namespace")
                {
                    xmlSchemaAnyAttribute.nameSpace = reader.Value;
                }
                else if (reader.Name == "processContents")
                {
                    Exception ex;
                    xmlSchemaAnyAttribute.processing = XmlSchemaUtil.ReadProcessingAttribute(reader, out ex);
                    if (ex != null)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is not a valid value for processContents", ex);
                    }
                }
                else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
                {
                    XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for anyAttribute", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaAnyAttribute);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaAnyAttribute);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "anyAttribute")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaAnyAttribute.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaAnyAttribute.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaAnyAttribute);
        }
Ejemplo n.º 46
0
		void ImportAttributes (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat, CodeIdentifiers classIds)
		{
			atts = CollectAttributeUsesNonOverlap (atts, cmap);

			if (anyat != null)
			{
    			XmlTypeMapMemberAnyAttribute member = new XmlTypeMapMemberAnyAttribute ();
				member.Name = classIds.AddUnique ("AnyAttribute", member);
				member.TypeData = TypeTranslator.GetTypeData (typeof(XmlAttribute[]));
				cmap.AddMember (member);
			}
			
			foreach (XmlSchemaObject at in atts)
			{
				if (at is XmlSchemaAttribute)
				{
					string ns;
					XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
					XmlSchemaAttribute refAttr = GetRefAttribute (typeQName, attr, out ns);
					XmlTypeMapMemberAttribute member = new XmlTypeMapMemberAttribute ();
					member.Name = classIds.AddUnique (CodeIdentifier.MakeValid (refAttr.Name), member);
					member.Documentation = GetDocumentation (attr);
					member.AttributeName = refAttr.Name;
					member.Namespace = ns;
					member.Form = refAttr.Form;
					member.TypeData = GetAttributeTypeData (typeQName, attr);
					
					if (refAttr.DefaultValue != null) 
						member.DefaultValue = ImportDefaultValue (member.TypeData, refAttr.DefaultValue);
					else if (member.TypeData.IsValueType)
						member.IsOptionalValueType = (refAttr.ValidatedUse != XmlSchemaUse.Required);
						
					if (member.TypeData.IsComplexType)
						member.MappedType = GetTypeMapping (member.TypeData);
					cmap.AddMember (member);
				}
				else if (at is XmlSchemaAttributeGroupRef)
				{
					XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
					XmlSchemaAttributeGroup grp = FindRefAttributeGroup (gref.RefName);
					ImportAttributes (typeQName, cmap, grp.Attributes, grp.AnyAttribute, classIds);
				}
			}
		}
Ejemplo n.º 47
0
        static void AddAppSequenceType(DiscoveryVersion discoveryVersion, XmlSchema schema)
        {
            //<xs:complexType name="AppSequenceType" >
            XmlSchemaComplexType appSequenceType = new XmlSchemaComplexType();
            appSequenceType.Name = ProtocolStrings.SchemaNames.AppSequenceType;

            // <xs:complexContent>
            XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();
            appSequenceType.ContentModel = complexContent;

            // <xs:restriction base="xs:anyType" >
            XmlSchemaComplexContentRestriction contentRestriction = new XmlSchemaComplexContentRestriction();
            complexContent.Content = contentRestriction;
            contentRestriction.BaseTypeName = discoveryVersion.Implementation.QualifiedNames.AnyType;

            // <xs:attribute name="InstanceId" type="xs:unsignedInt" use="required" />
            XmlSchemaAttribute instanceId = new XmlSchemaAttribute();
            instanceId.Name = ProtocolStrings.SchemaNames.AppSequenceInstanceId;
            instanceId.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.UnsignedIntType;
            instanceId.Use = XmlSchemaUse.Required;

            // <xs:attribute name="SequenceId" type="xs:anyURI" />
            XmlSchemaAttribute sequenceId = new XmlSchemaAttribute();
            sequenceId.Name = ProtocolStrings.SchemaNames.AppSequenceSequenceId;
            sequenceId.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.AnyUriType;

            // <xs:attribute name="MessageNumber" type="xs:unsignedInt" use="required" />
            XmlSchemaAttribute messageNumber = new XmlSchemaAttribute();
            messageNumber.Name = ProtocolStrings.SchemaNames.AppSequenceMessageNumber;
            messageNumber.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.UnsignedIntType;
            messageNumber.Use = XmlSchemaUse.Required;

            // <xs:anyAttribute namespace="##other" processContents="lax" />
            XmlSchemaAnyAttribute anyAttribue = new XmlSchemaAnyAttribute();
            anyAttribue.Namespace = "##other";
            anyAttribue.ProcessContents = XmlSchemaContentProcessing.Lax;

            contentRestriction.Attributes.Add(instanceId);
            contentRestriction.Attributes.Add(sequenceId);
            contentRestriction.Attributes.Add(messageNumber);
            contentRestriction.AnyAttribute = anyAttribue;

            schema.Items.Add(appSequenceType);
        }
Ejemplo n.º 48
0
        //<attributeGroup
        //  id = ID
        //  name = NCName
        //  ref = QName // Not present in this class.
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
        //</attributeGroup>
        internal static XmlSchemaAttributeGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAttributeGroup attrgrp = new XmlSchemaAttributeGroup();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaAttributeGroup.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }

            attrgrp.LineNumber   = reader.LineNumber;
            attrgrp.LinePosition = reader.LinePosition;
            attrgrp.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    attrgrp.Id = reader.Value;
                }
                else if (reader.Name == "name")
                {
                    attrgrp.name = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for attributeGroup in this context", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, attrgrp);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(attrgrp);
            }

            //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute?
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaAttributeGroup.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                     //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        attrgrp.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 2;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            attrgrp.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 2;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            attrgrp.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 3 && reader.LocalName == "anyAttribute")
                {
                    level = 4;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        attrgrp.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(attrgrp);
        }
Ejemplo n.º 49
0
        static void AddResolveType(DiscoveryVersion discoveryVersion, XmlSchema schema)
        {
            //<xs:complexType name="ResolveType" >
            XmlSchemaComplexType resolveType = new XmlSchemaComplexType();
            resolveType.Name = ProtocolStrings.SchemaNames.ResolveType;

            //   <xs:sequence>
            XmlSchemaSequence resolveSequence = new XmlSchemaSequence();

            //     <xs:element ref="wsa:EndpointReference" />
            XmlSchemaElement eprElement = new XmlSchemaElement();
            eprElement.RefName = discoveryVersion.Implementation.QualifiedNames.EprElement;

            //     <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other" processContents="lax" />
            XmlSchemaAny any = new XmlSchemaAny();
            any.Namespace = "##other";
            any.ProcessContents = XmlSchemaContentProcessing.Lax;
            any.MinOccurs = 0;
            any.MaxOccurs = decimal.MaxValue;

            resolveSequence.Items.Add(eprElement);
            resolveSequence.Items.Add(any);

            //   <xs:anyAttribute namespace="##other" processContents="lax" />
            XmlSchemaAnyAttribute anyAttribue = new XmlSchemaAnyAttribute();
            anyAttribue.Namespace = "##other";
            anyAttribue.ProcessContents = XmlSchemaContentProcessing.Lax;

            // </xs:complexType>
            resolveType.Particle = resolveSequence;
            resolveType.AnyAttribute = anyAttribue;

            schema.Items.Add(resolveType);
        }
Ejemplo n.º 50
0
        static void AddProbeMatchType(DiscoveryVersion discoveryVersion, XmlSchema schema)
        {
            // <xs:complexType name="ProbeMatchType">
            XmlSchemaComplexType probeMatchType = new XmlSchemaComplexType();
            probeMatchType.Name = ProtocolStrings.SchemaNames.ProbeMatchType;

            //   <xs:sequence>
            XmlSchemaSequence probeMatcheSequence = new XmlSchemaSequence();

            //     <xs:element ref="wsa:EndpointReference" />
            XmlSchemaElement eprElement = new XmlSchemaElement();
            eprElement.RefName = discoveryVersion.Implementation.QualifiedNames.EprElement;

            //     <xs:element minOccurs="0" ref="tns:Types" />
            XmlSchemaElement typesElement = new XmlSchemaElement();
            typesElement.RefName = discoveryVersion.Implementation.QualifiedNames.TypesElement;
            typesElement.MinOccurs = 0;

            //     <xs:element minOccurs="0" ref="tns:Scopes" />
            XmlSchemaElement scopesElement = new XmlSchemaElement();
            scopesElement.RefName = discoveryVersion.Implementation.QualifiedNames.ScopesElement;
            scopesElement.MinOccurs = 0;

            //     <xs:element minOccurs="0" ref="tns:XAddrs" />
            XmlSchemaElement xAddrsElement = new XmlSchemaElement();
            xAddrsElement.RefName = discoveryVersion.Implementation.QualifiedNames.XAddrsElement;
            xAddrsElement.MinOccurs = 0;

            //     <xs:element ref="tns:MetadataVersion" /> -- allowing minOccurs=0 because the same type is used for Bye messages
            XmlSchemaElement metadataVersionElement = new XmlSchemaElement();
            metadataVersionElement.RefName = discoveryVersion.Implementation.QualifiedNames.MetadataVersionElement;
            metadataVersionElement.MinOccurs = 0;

            //     <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other" processContents="lax" />
            XmlSchemaAny any = new XmlSchemaAny();
            any.Namespace = "##other";
            any.ProcessContents = XmlSchemaContentProcessing.Lax;
            any.MinOccurs = 0;
            any.MaxOccurs = decimal.MaxValue;

            //   </xs:sequence>
            probeMatcheSequence.Items.Add(eprElement);
            probeMatcheSequence.Items.Add(typesElement);
            probeMatcheSequence.Items.Add(scopesElement);
            probeMatcheSequence.Items.Add(xAddrsElement);
            probeMatcheSequence.Items.Add(metadataVersionElement);
            probeMatcheSequence.Items.Add(any);

            //   <xs:anyAttribute namespace="##other" processContents="lax" />
            XmlSchemaAnyAttribute anyAttribue = new XmlSchemaAnyAttribute();
            anyAttribue.Namespace = "##other";
            anyAttribue.ProcessContents = XmlSchemaContentProcessing.Lax;

            // </xs:complexType>
            probeMatchType.Particle = probeMatcheSequence;
            probeMatchType.AnyAttribute = anyAttribue;

            schema.Items.Add(probeMatchType);
        }
Ejemplo n.º 51
0
        static void AddProbeType(DiscoveryVersion discoveryVersion, XmlSchema schema)
        {
            // <xs:complexType name="ProbeType">
            XmlSchemaComplexType probeType = new XmlSchemaComplexType();
            probeType.Name = ProtocolStrings.SchemaNames.ProbeType;

            //   <xs:sequence>
            XmlSchemaSequence probeTypeSequence = new XmlSchemaSequence();

            //     <xs:element ref="tns:Types" minOccurs="0" />
            XmlSchemaElement typesElement = new XmlSchemaElement();
            typesElement.RefName = discoveryVersion.Implementation.QualifiedNames.TypesElement;
            typesElement.MinOccurs = 0;

            //     <xs:element ref="tns:Scopes" minOccurs="0" />
            XmlSchemaElement scopesElement = new XmlSchemaElement();
            scopesElement.RefName = discoveryVersion.Implementation.QualifiedNames.ScopesElement;
            scopesElement.MinOccurs = 0;

            //     <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
            XmlSchemaAny any = new XmlSchemaAny();
            any.Namespace = "##other";
            any.ProcessContents = XmlSchemaContentProcessing.Lax;
            any.MinOccurs = 0;
            any.MaxOccurs = decimal.MaxValue;

            //   </xs:sequence>
            probeTypeSequence.Items.Add(typesElement);
            probeTypeSequence.Items.Add(scopesElement);
            probeTypeSequence.Items.Add(any);

            //   <xs:anyAttribute namespace="##other" processContents="lax" />
            XmlSchemaAnyAttribute anyAttribue = new XmlSchemaAnyAttribute();
            anyAttribue.Namespace = "##other";
            anyAttribue.ProcessContents = XmlSchemaContentProcessing.Lax;

            // </xs:complexType>
            probeType.Particle = probeTypeSequence;
            probeType.AnyAttribute = anyAttribue;

            schema.Items.Add(probeType);
        }
 private XmlSchemaAnyAttribute CompileAnyAttributeUnion(XmlSchemaAnyAttribute a, XmlSchemaAnyAttribute b)
 {
     if (a == null)
     {
         return b;
     }
     if (b == null)
     {
         return a;
     }
     XmlSchemaAnyAttribute attribute = XmlSchemaAnyAttribute.Union(a, b, true);
     if (attribute == null)
     {
         base.SendValidationEvent("Sch_UnexpressibleAnyAttribute", a);
     }
     return attribute;
 }
Ejemplo n.º 53
0
        static void AddScopesType(DiscoveryVersion discoveryVersion, XmlSchema schema)
        {
            // <xs:complexType name="ScopesType">
            XmlSchemaComplexType scopesType = new XmlSchemaComplexType();
            scopesType.Name = ProtocolStrings.SchemaNames.ScopesType;

            //    <xs:simpleContent>
            XmlSchemaSimpleContent scopesTypeContent = new XmlSchemaSimpleContent();

            //       <xs:extension base="tns:UriListType">
            XmlSchemaSimpleContentExtension scopesTypeContentExtension = new XmlSchemaSimpleContentExtension();
            scopesTypeContentExtension.BaseTypeName = discoveryVersion.Implementation.QualifiedNames.UriListType;

            //          <xs:attribute name="MatchBy" type="xs:anyURI" />    
            XmlSchemaAttribute matchBy = new XmlSchemaAttribute();
            matchBy.Name = ProtocolStrings.SchemaNames.MatchByAttribute;
            matchBy.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.AnyUriType;

            //          <xs:anyAttribute namespace="##other" processContents="lax" />
            XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
            anyAttribute.Namespace = "##other";
            anyAttribute.ProcessContents = XmlSchemaContentProcessing.Lax;

            //       </xs:extension>
            scopesTypeContentExtension.Attributes.Add(matchBy);
            scopesTypeContentExtension.AnyAttribute = anyAttribute;

            //    </xs:simpleContent>
            scopesTypeContent.Content = scopesTypeContentExtension;

            // <xs:complexType name="ScopesType">
            scopesType.ContentModel = scopesTypeContent;

            schema.Items.Add(scopesType);
        }
 private void PreprocessAttributes(XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, XmlSchemaObject parent)
 {
     for (int i = 0; i < attributes.Count; i++)
     {
         this.SetParent(attributes[i], parent);
         XmlSchemaAttribute attribute = attributes[i] as XmlSchemaAttribute;
         if (attribute != null)
         {
             this.PreprocessLocalAttribute(attribute);
         }
         else
         {
             XmlSchemaAttributeGroupRef source = (XmlSchemaAttributeGroupRef) attributes[i];
             if (source.RefName.IsEmpty)
             {
                 base.SendValidationEvent("Sch_MissAttribute", "ref", source);
             }
             else
             {
                 this.ValidateQNameAttribute(source, "ref", source.RefName);
             }
             this.PreprocessAnnotation(attributes[i]);
             this.ValidateIdAttribute(attributes[i]);
         }
     }
     if (anyAttribute != null)
     {
         try
         {
             this.SetParent(anyAttribute, parent);
             this.PreprocessAnnotation(anyAttribute);
             anyAttribute.BuildNamespaceList(this.targetNamespace);
         }
         catch (FormatException exception)
         {
             base.SendValidationEvent("Sch_InvalidAnyDetailed", new string[] { exception.Message }, exception, anyAttribute);
         }
         this.ValidateIdAttribute(anyAttribute);
     }
 }
Ejemplo n.º 55
0
        public static int ValidateAttributesResolved(XmlSchemaObjectTable attributesResolved, ValidationEventHandler h, XmlSchema schema, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, ref XmlSchemaAnyAttribute anyAttributeUse, XmlSchemaAttributeGroup redefined, bool skipEquivalent)
        {
            int num = 0;

            if (anyAttribute != null && anyAttributeUse == null)
            {
                anyAttributeUse = anyAttribute;
            }
            ArrayList arrayList = new ArrayList();

            foreach (XmlSchemaObject xmlSchemaObject in attributes)
            {
                XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = xmlSchemaObject as XmlSchemaAttributeGroupRef;
                if (xmlSchemaAttributeGroupRef != null)
                {
                    XmlSchemaAttributeGroup xmlSchemaAttributeGroup = null;
                    if (redefined != null && xmlSchemaAttributeGroupRef.RefName == redefined.QualifiedName)
                    {
                        xmlSchemaAttributeGroup = redefined;
                    }
                    else
                    {
                        xmlSchemaAttributeGroup = schema.FindAttributeGroup(xmlSchemaAttributeGroupRef.RefName);
                    }
                    if (xmlSchemaAttributeGroup == null)
                    {
                        if (!schema.missedSubComponents)
                        {
                            xmlSchemaAttributeGroupRef.error(h, "Referenced attribute group " + xmlSchemaAttributeGroupRef.RefName + " was not found in the corresponding schema.");
                        }
                    }
                    else if (xmlSchemaAttributeGroup.AttributeGroupRecursionCheck)
                    {
                        xmlSchemaAttributeGroup.error(h, "Attribute group recursion was found: " + xmlSchemaAttributeGroupRef.RefName);
                    }
                    else
                    {
                        try
                        {
                            xmlSchemaAttributeGroup.AttributeGroupRecursionCheck = true;
                            num += xmlSchemaAttributeGroup.Validate(h, schema);
                        }
                        finally
                        {
                            xmlSchemaAttributeGroup.AttributeGroupRecursionCheck = false;
                        }
                        if (xmlSchemaAttributeGroup.AnyAttributeUse != null && anyAttribute == null)
                        {
                            anyAttributeUse = xmlSchemaAttributeGroup.AnyAttributeUse;
                        }
                        foreach (object obj in xmlSchemaAttributeGroup.AttributeUses)
                        {
                            XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute)((DictionaryEntry)obj).Value;
                            if (!XmlSchemaUtil.StrictMsCompliant || xmlSchemaAttribute.Use != XmlSchemaUse.Prohibited)
                            {
                                if (xmlSchemaAttribute.RefName != null && xmlSchemaAttribute.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !XmlSchemaUtil.AreAttributesEqual(xmlSchemaAttribute, attributesResolved[xmlSchemaAttribute.RefName] as XmlSchemaAttribute)))
                                {
                                    XmlSchemaUtil.AddToTable(attributesResolved, xmlSchemaAttribute, xmlSchemaAttribute.RefName, h);
                                }
                                else if (!skipEquivalent || !XmlSchemaUtil.AreAttributesEqual(xmlSchemaAttribute, attributesResolved[xmlSchemaAttribute.QualifiedName] as XmlSchemaAttribute))
                                {
                                    XmlSchemaUtil.AddToTable(attributesResolved, xmlSchemaAttribute, xmlSchemaAttribute.QualifiedName, h);
                                }
                            }
                        }
                    }
                }
                else
                {
                    XmlSchemaAttribute xmlSchemaAttribute2 = xmlSchemaObject as XmlSchemaAttribute;
                    if (xmlSchemaAttribute2 != null)
                    {
                        num += xmlSchemaAttribute2.Validate(h, schema);
                        if (arrayList.Contains(xmlSchemaAttribute2.QualifiedName))
                        {
                            xmlSchemaAttribute2.error(h, string.Format("Duplicate attributes was found for '{0}'", xmlSchemaAttribute2.QualifiedName));
                        }
                        arrayList.Add(xmlSchemaAttribute2.QualifiedName);
                        if (!XmlSchemaUtil.StrictMsCompliant || xmlSchemaAttribute2.Use != XmlSchemaUse.Prohibited)
                        {
                            if (xmlSchemaAttribute2.RefName != null && xmlSchemaAttribute2.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !XmlSchemaUtil.AreAttributesEqual(xmlSchemaAttribute2, attributesResolved[xmlSchemaAttribute2.RefName] as XmlSchemaAttribute)))
                            {
                                XmlSchemaUtil.AddToTable(attributesResolved, xmlSchemaAttribute2, xmlSchemaAttribute2.RefName, h);
                            }
                            else if (!skipEquivalent || !XmlSchemaUtil.AreAttributesEqual(xmlSchemaAttribute2, attributesResolved[xmlSchemaAttribute2.QualifiedName] as XmlSchemaAttribute))
                            {
                                XmlSchemaUtil.AddToTable(attributesResolved, xmlSchemaAttribute2, xmlSchemaAttribute2.QualifiedName, h);
                            }
                        }
                    }
                    else if (anyAttribute == null)
                    {
                        anyAttributeUse = (XmlSchemaAnyAttribute)xmlSchemaObject;
                        anyAttribute.Validate(h, schema);
                    }
                }
            }
            return(num);
        }