Ejemplo n.º 1
0
        // Is some value is read, return it.
        // If no values return empty.
        // If exception, return none
        public static XmlSchemaDerivationMethod ReadDerivationAttribute(XmlReader reader, out Exception innerExcpetion, string name, XmlSchemaDerivationMethod allowed)
        {
            innerExcpetion = null;
            try
            {
                string list = reader.Value;
                string warn = "";
                XmlSchemaDerivationMethod val = 0;

                if (list.IndexOf("#all") != -1 && list.Trim() != "#all")
                {
                    innerExcpetion = new Exception(list + " is not a valid value for " + name + ". #all if present must be the only value");
                    return(XmlSchemaDerivationMethod.All);
                }
                foreach (string xsdm in XmlSchemaUtil.SplitList(list))
                {
                    switch (xsdm)
                    {
                    case "":
                        val = AddFlag(val, XmlSchemaDerivationMethod.Empty, allowed); break;

                    case "#all":
                        val = AddFlag(val, XmlSchemaDerivationMethod.All, allowed); break;

                    case "substitution":
                        val = AddFlag(val, XmlSchemaDerivationMethod.Substitution, allowed); break;

                    case "extension":
                        val = AddFlag(val, XmlSchemaDerivationMethod.Extension, allowed); break;

                    case "restriction":
                        val = AddFlag(val, XmlSchemaDerivationMethod.Restriction, allowed); break;

                    case "list":
                        val = AddFlag(val, XmlSchemaDerivationMethod.List, allowed); break;

                    case "union":
                        val = AddFlag(val, XmlSchemaDerivationMethod.Union, allowed); break;

                    default:
                        warn += xsdm + " "; break;
                    }
                }
                if (warn != "")
                {
                    innerExcpetion = new Exception(warn + "is/are not valid values for " + name);
                }
                return(val);
            }
            catch (Exception ex)
            {
                innerExcpetion = ex;
                return(XmlSchemaDerivationMethod.None);
            }
        }
Ejemplo n.º 2
0
        //<union
        //  id = ID
        //  memberTypes = List of QName
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (simpleType*))
        //</union>
        internal static XmlSchemaSimpleTypeUnion Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleTypeUnion union = new XmlSchemaSimpleTypeUnion();

            reader.MoveToElement();

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

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

            //Read Attributes
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    union.Id = reader.Value;
                }
                else if (reader.Name == "memberTypes")
                {
                    Exception innerEx;
                    string[]  names = XmlSchemaUtil.SplitList(reader.Value);
                    union.memberTypes = new XmlQualifiedName[names.Length];
                    for (int i = 0; i < names.Length; i++)
                    {
                        union.memberTypes[i] = XmlSchemaUtil.ToQName(reader, names[i], out innerEx);
                        if (innerEx != null)
                        {
                            error(h, "'" + names[i] + "' is not a valid memberType", innerEx);
                        }
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for union", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, union);
                }
            }

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

            //  Content: annotation?, simpleType*
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaSimpleTypeUnion.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)
                    {
                        union.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2 && reader.LocalName == "simpleType")
                {
                    level = 2;
                    XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h);
                    if (stype != null)
                    {
                        union.baseTypes.Add(stype);
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(union);
        }