// 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); } }
//<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); }
public static XmlSchemaDerivationMethod ReadDerivationAttribute(XmlReader reader, out Exception innerExcpetion, string name, XmlSchemaDerivationMethod allowed) { innerExcpetion = null; XmlSchemaDerivationMethod result; try { string value = reader.Value; string text = string.Empty; XmlSchemaDerivationMethod xmlSchemaDerivationMethod = XmlSchemaDerivationMethod.Empty; if (value.IndexOf("#all") != -1 && value.Trim() != "#all") { innerExcpetion = new Exception(value + " is not a valid value for " + name + ". #all if present must be the only value"); result = XmlSchemaDerivationMethod.All; } else { string[] array = XmlSchemaUtil.SplitList(value); int i = 0; while (i < array.Length) { string text2 = array[i]; string text3 = text2; if (text3 == null) { goto IL_192; } if (XmlSchemaUtil.< > f__switch$map38 == null) { XmlSchemaUtil.< > f__switch$map38 = new Dictionary <string, int>(7) { { string.Empty, 0 }, { "#all", 1 }, { "substitution", 2 }, { "extension", 3 }, { "restriction", 4 }, { "list", 5 }, { "union", 6 } }; } int num; if (!XmlSchemaUtil.< > f__switch$map38.TryGetValue(text3, out num)) { goto IL_192; } switch (num) { case 0: xmlSchemaDerivationMethod = XmlSchemaUtil.AddFlag(xmlSchemaDerivationMethod, XmlSchemaDerivationMethod.Empty, allowed); break; case 1: xmlSchemaDerivationMethod = XmlSchemaUtil.AddFlag(xmlSchemaDerivationMethod, XmlSchemaDerivationMethod.All, allowed); break; case 2: xmlSchemaDerivationMethod = XmlSchemaUtil.AddFlag(xmlSchemaDerivationMethod, XmlSchemaDerivationMethod.Substitution, allowed); break; case 3: xmlSchemaDerivationMethod = XmlSchemaUtil.AddFlag(xmlSchemaDerivationMethod, XmlSchemaDerivationMethod.Extension, allowed); break; case 4: xmlSchemaDerivationMethod = XmlSchemaUtil.AddFlag(xmlSchemaDerivationMethod, XmlSchemaDerivationMethod.Restriction, allowed); break; case 5: xmlSchemaDerivationMethod = XmlSchemaUtil.AddFlag(xmlSchemaDerivationMethod, XmlSchemaDerivationMethod.List, allowed); break; case 6: xmlSchemaDerivationMethod = XmlSchemaUtil.AddFlag(xmlSchemaDerivationMethod, XmlSchemaDerivationMethod.Union, allowed); break; default: goto IL_192; } IL_1A4: i++; continue; IL_192: text = text + text2 + " "; goto IL_1A4; } if (text != string.Empty) { innerExcpetion = new Exception(text + "is/are not valid values for " + name); } result = xmlSchemaDerivationMethod; } } catch (Exception ex) { innerExcpetion = ex; result = XmlSchemaDerivationMethod.None; } return(result); }
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); }