Пример #1
0
        //<any
        //  id = ID
        //  maxOccurs =  (nonNegativeInteger | unbounded)  : 1
        //  minOccurs = nonNegativeInteger : 1
        //  namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )  : ##any
        //  processContents = (lax | skip | strict) : strict
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?)
        //</any>
        internal static XmlSchemaAny Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAny any = new XmlSchemaAny();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaAny.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 == "maxOccurs")
                {
                    try
                    {
                        any.MaxOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for maxOccurs", e);
                    }
                }
                else if (reader.Name == "minOccurs")
                {
                    try
                    {
                        any.MinOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for minOccurs", e);
                    }
                }
                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 any", 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: XmlSchemaAny.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);
        }
        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);
        }