Exemplo n.º 1
0
        //<include
        //  id = ID
        //  schemaLocation = anyURI
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?)
        //</include>
        internal static XmlSchemaInclude Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaInclude include = new XmlSchemaInclude();

            reader.MoveToElement();

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

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

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

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

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

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaInclude.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)
                    {
                        include.Annotation = annotation;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }

            return(include);
        }
Exemplo n.º 2
0
        //<selector
        //  id = ID
        //  xpath = a subset of XPath expression, see below
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?)
        //</selector>
        internal static XmlSchemaXPath Read(XmlSchemaReader reader, ValidationEventHandler h, string name)
        {
            XmlSchemaXPath path = new XmlSchemaXPath();

            reader.MoveToElement();

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

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

            XmlNamespaceManager currentMgr = XmlSchemaUtil.GetParserContext(reader.Reader).NamespaceManager;

            if (currentMgr != null)
            {
                path.nsmgr = new XmlNamespaceManager(reader.NameTable);
                IEnumerator e = currentMgr.GetEnumerator();
                while (e.MoveNext())
                {
                    string prefix = e.Current as string;
                    switch (prefix)
                    {
                    case "xml":
                    case "xmlns":
                        continue;

                    default:
                        path.nsmgr.AddNamespace(prefix, currentMgr.LookupNamespace(prefix, false));
                        break;
                    }
                }
            }

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

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

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

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != name)
                    {
                        error(h, "Should not happen :2: XmlSchemaXPath.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)
                    {
                        path.Annotation = annotation;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(path);
        }
        //<restriction
        //  base = QName
        //  id = ID
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
        //</restriction>
        internal static XmlSchemaComplexContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaComplexContentRestriction.Read, name=" + reader.Name, null);
                reader.Skip();
                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.(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: XmlSchemaComplexContentRestriction.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)
                {
                    if (reader.LocalName == "group")
                    {
                        level = 3;
                        XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader, h);
                        if (group != null)
                        {
                            restriction.particle = group;
                        }
                        continue;
                    }
                    if (reader.LocalName == "all")
                    {
                        level = 3;
                        XmlSchemaAll all = XmlSchemaAll.Read(reader, h);
                        if (all != null)
                        {
                            restriction.particle = all;
                        }
                        continue;
                    }
                    if (reader.LocalName == "choice")
                    {
                        level = 3;
                        XmlSchemaChoice choice = XmlSchemaChoice.Read(reader, h);
                        if (choice != null)
                        {
                            restriction.particle = choice;
                        }
                        continue;
                    }
                    if (reader.LocalName == "sequence")
                    {
                        level = 3;
                        XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h);
                        if (sequence != null)
                        {
                            restriction.particle = sequence;
                        }
                        continue;
                    }
                }
                if (level <= 3)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 3;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            restriction.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 3;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            restriction.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 4 && reader.LocalName == "anyAttribute")
                {
                    level = 5;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        restriction.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(restriction);
        }
Exemplo n.º 4
0
        //	<whiteSpace
        //	fixed = boolean : false
        //	id = ID
        //	value = (collapse | preserve | replace)
        //	{any attributes with non-schema namespace . . .}>
        //	Content: (annotation?)
        //	</whiteSpace>
        internal static XmlSchemaWhiteSpaceFacet Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaWhiteSpaceFacet ws = new XmlSchemaWhiteSpaceFacet();

            reader.MoveToElement();

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

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

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

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

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

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaWhiteSpaceFacet.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)
                    {
                        ws.Annotation = annotation;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(ws);
        }
Exemplo n.º 5
0
        //<all
        //  id = ID
        //  maxOccurs = 1 : 1
        //  minOccurs = (0 | 1) : 1
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, element*)
        //</all>
        internal static XmlSchemaAll Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAll all = new XmlSchemaAll();

            reader.MoveToElement();

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

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

            //Read Attributes
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    all.Id = reader.Value;
                }
                else if (reader.Name == "maxOccurs")
                {
                    try
                    {
                        all.MaxOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for maxOccurs", e);
                    }
                }
                else if (reader.Name == "minOccurs")
                {
                    try
                    {
                        all.MinOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for minOccurs", e);
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for all", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, all);
                }
            }

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

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

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaAll.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)
                    {
                        all.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2 && reader.LocalName == "element")
                {
                    level = 2;
                    XmlSchemaElement element = XmlSchemaElement.Read(reader, h);
                    if (element != null)
                    {
                        all.items.Add(element);
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(all);
        }
Exemplo n.º 6
0
        //	<group
        //		 id = ID
        //		 ref = QName
        //		 minOccurs = ? : 1
        //		 maxOccurs = ? : 1>
        //		 Content: (annotation?)
        //	</group>
        internal static XmlSchemaGroupRef Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaGroupRef groupref = new XmlSchemaGroupRef();

            reader.MoveToElement();

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

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

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    groupref.Id = reader.Value;
                }
                else if (reader.Name == "ref")
                {
                    Exception innerex;
                    groupref.refName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for ref attribute", innerex);
                    }
                }
                else if (reader.Name == "maxOccurs")
                {
                    try
                    {
                        groupref.MaxOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for maxOccurs", e);
                    }
                }
                else if (reader.Name == "minOccurs")
                {
                    try
                    {
                        groupref.MinOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for minOccurs", e);
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for group", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, groupref);
                }
            }

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

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

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaGroupRef.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)
                    {
                        groupref.Annotation = annotation;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(groupref);
        }
Exemplo n.º 7
0
        //<list
        //  id = ID
        //  itemType = QName
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (simpleType?))
        //</list>
        internal static XmlSchemaSimpleTypeList Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();

            reader.MoveToElement();

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

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

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

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(list);
            }
            //  Content: annotation?, simpleType?
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaSimpleTypeList.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)
                    {
                        list.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2 && reader.LocalName == "simpleType")
                {
                    level = 3;
                    XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h);
                    if (stype != null)
                    {
                        list.itemType = stype;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(list);
        }
Exemplo n.º 8
0
        //<annotation
        //  id = ID
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (appinfo | documentation)*
        //</annotation>
        internal static XmlSchemaAnnotation Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();

            reader.MoveToElement();

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

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

            //Read Attributes
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    annotation.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for annotation", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, annotation);
                }
            }

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

            //Content: (appinfo | documentation)*
            bool   skip        = false;
            string expectedEnd = null;

            while (!reader.EOF)
            {
                if (skip)
                {
                    skip = false;
                }
                else
                {
                    reader.ReadNextElement();
                }

                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    bool   end      = true;
                    string expected = xmlname;
                    if (expectedEnd != null)
                    {
                        expected    = expectedEnd;
                        expectedEnd = null;
                        end         = false;
                    }
                    if (reader.LocalName != expected)
                    {
                        error(h, "Should not happen :2: XmlSchemaAnnotation.Read, name=" + reader.Name + ",expected=" + expected, null);
                    }
                    if (end)
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                if (reader.LocalName == "appinfo")
                {
                    XmlSchemaAppInfo appinfo = XmlSchemaAppInfo.Read(reader, h, out skip);
                    if (appinfo != null)
                    {
                        annotation.items.Add(appinfo);
                    }
                    continue;
                }
                if (reader.LocalName == "documentation")
                {
                    XmlSchemaDocumentation documentation = XmlSchemaDocumentation.Read(reader, h, out skip);
                    if (documentation != null)
                    {
                        annotation.items.Add(documentation);
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(annotation);
        }
Exemplo n.º 9
0
        /*
         * internal new void error(ValidationEventHandler handle, string message)
         * {
         *      errorCount++;
         *      ValidationHandler.RaiseValidationError(handle, this, message);
         * }
         */

        //<key
        //  id = ID
        //  name = NCName
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (selector, field+))
        //</key>
        internal static XmlSchemaKey Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaKey key = new XmlSchemaKey();

            reader.MoveToElement();

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

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

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

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

            //  Content: annotation?, selector, field+
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaKey.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)
                    {
                        key.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2 && reader.LocalName == "selector")
                {
                    level = 3;
                    XmlSchemaXPath selector = XmlSchemaXPath.Read(reader, h, "selector");
                    if (selector != null)
                    {
                        key.Selector = selector;
                    }
                    continue;
                }
                if (level <= 3 && reader.LocalName == "field")
                {
                    level = 3;
                    if (key.Selector == null)
                    {
                        error(h, "selector must be defined before field declarations", null);
                    }
                    XmlSchemaXPath field = XmlSchemaXPath.Read(reader, h, "field");
                    if (field != null)
                    {
                        key.Fields.Add(field);
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(key);
        }
Exemplo n.º 10
0
        //<sequence
        //  id = ID
        //  maxOccurs =  (nonNegativeInteger | unbounded)  : 1
        //  minOccurs = nonNegativeInteger : 1
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (element | group | choice | sequence | any)*)
        //</sequence>
        internal static XmlSchemaSequence Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSequence sequence = new XmlSchemaSequence();

            reader.MoveToElement();

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

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

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    sequence.Id = reader.Value;
                }
                else if (reader.Name == "maxOccurs")
                {
                    try
                    {
                        sequence.MaxOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for maxOccurs", e);
                    }
                }
                else if (reader.Name == "minOccurs")
                {
                    try
                    {
                        sequence.MinOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for minOccurs", e);
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for sequence", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, sequence);
                }
            }

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

            //  Content: (annotation?, (element | group | choice | sequence | any)*)
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaSequence.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)
                    {
                        sequence.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "element")
                    {
                        level = 2;
                        XmlSchemaElement element = XmlSchemaElement.Read(reader, h);
                        if (element != null)
                        {
                            sequence.items.Add(element);
                        }
                        continue;
                    }
                    if (reader.LocalName == "group")
                    {
                        level = 2;
                        XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader, h);
                        if (group != null)
                        {
                            sequence.items.Add(group);
                        }
                        continue;
                    }
                    if (reader.LocalName == "choice")
                    {
                        level = 2;
                        XmlSchemaChoice choice = XmlSchemaChoice.Read(reader, h);
                        if (choice != null)
                        {
                            sequence.items.Add(choice);
                        }
                        continue;
                    }
                    if (reader.LocalName == "sequence")
                    {
                        level = 2;
                        XmlSchemaSequence seq = XmlSchemaSequence.Read(reader, h);
                        if (seq != null)
                        {
                            sequence.items.Add(seq);
                        }
                        continue;
                    }
                    if (reader.LocalName == "any")
                    {
                        level = 2;
                        XmlSchemaAny any = XmlSchemaAny.Read(reader, h);
                        if (any != null)
                        {
                            sequence.items.Add(any);
                        }
                        continue;
                    }
                }
                reader.RaiseInvalidElementError();
            }
            return(sequence);
        }
Exemplo n.º 11
0
        //<simpleContent
        //  id = ID
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (restriction | extension))
        //</simpleContent>
        internal static XmlSchemaSimpleContent Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleContent simple = new XmlSchemaSimpleContent();

            reader.MoveToElement();

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

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

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

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(simple);
            }
            //Content: (annotation?, (restriction | extension))
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaSimpleContent.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)
                    {
                        simple.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "restriction")
                    {
                        level = 3;
                        XmlSchemaSimpleContentRestriction restriction = XmlSchemaSimpleContentRestriction.Read(reader, h);
                        if (restriction != null)
                        {
                            simple.content = restriction;
                        }
                        continue;
                    }
                    if (reader.LocalName == "extension")
                    {
                        level = 3;
                        XmlSchemaSimpleContentExtension extension = XmlSchemaSimpleContentExtension.Read(reader, h);
                        if (extension != null)
                        {
                            simple.content = extension;
                        }
                        continue;
                    }
                }
                reader.RaiseInvalidElementError();
            }
            return(simple);
        }