Пример #1
0
 public static XmlQualifiedName ReadQNameAttribute(XmlReader reader, out Exception innerEx)
 {
     return(XmlSchemaUtil.ToQName(reader, reader.Value, out innerEx));
 }
Пример #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);
        }
        internal static XmlSchemaSimpleTypeUnion Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleTypeUnion xmlSchemaSimpleTypeUnion = new XmlSchemaSimpleTypeUnion();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "union")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaSimpleTypeUnion.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaSimpleTypeUnion.LineNumber   = reader.LineNumber;
            xmlSchemaSimpleTypeUnion.LinePosition = reader.LinePosition;
            xmlSchemaSimpleTypeUnion.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaSimpleTypeUnion.Id = reader.Value;
                }
                else if (reader.Name == "memberTypes")
                {
                    string[] array = XmlSchemaUtil.SplitList(reader.Value);
                    xmlSchemaSimpleTypeUnion.memberTypes = new XmlQualifiedName[array.Length];
                    for (int i = 0; i < array.Length; i++)
                    {
                        Exception ex;
                        xmlSchemaSimpleTypeUnion.memberTypes[i] = XmlSchemaUtil.ToQName(reader, array[i], out ex);
                        if (ex != null)
                        {
                            XmlSchemaObject.error(h, "'" + array[i] + "' is not a valid memberType", 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 union", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaSimpleTypeUnion);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaSimpleTypeUnion);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "union")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaSimpleTypeUnion.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaSimpleTypeUnion.Annotation = xmlSchemaAnnotation;
                    }
                }
                else if (num <= 2 && reader.LocalName == "simpleType")
                {
                    num = 2;
                    XmlSchemaSimpleType xmlSchemaSimpleType = XmlSchemaSimpleType.Read(reader, h);
                    if (xmlSchemaSimpleType != null)
                    {
                        xmlSchemaSimpleTypeUnion.baseTypes.Add(xmlSchemaSimpleType);
                    }
                }
                else
                {
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaSimpleTypeUnion);
        }