public async Task StartParsingAsync(XmlReader reader, string targetNamespace) { this.reader = reader; positionInfo = PositionInfo.GetPositionInfo(reader); namespaceManager = reader.NamespaceManager; if (namespaceManager == null) { namespaceManager = new XmlNamespaceManager(nameTable); isProcessNamespaces = true; } else { isProcessNamespaces = false; } while (reader.NodeType != XmlNodeType.Element && await reader.ReadAsync().ConfigureAwait(false)) {} markupDepth = int.MaxValue; schemaXmlDepth = reader.Depth; SchemaType rootType = schemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI); string code; if (!CheckSchemaRoot(rootType, out code)) { throw new XmlSchemaException(code, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition); } if (schemaType == SchemaType.XSD) { schema = new XmlSchema(); schema.BaseUri = new Uri(reader.BaseURI, UriKind.RelativeOrAbsolute); builder = new XsdBuilder(reader, namespaceManager, schema, nameTable, schemaNames, eventHandler); } else { Debug.Assert(schemaType == SchemaType.XDR); xdrSchema = new SchemaInfo(); xdrSchema.SchemaType = SchemaType.XDR; builder = new XdrBuilder(reader, namespaceManager, xdrSchema, targetNamespace, nameTable, schemaNames, eventHandler); ((XdrBuilder)builder).XmlResolver = xmlResolver; } }
private static void BuildGroupRef_Ref(XsdBuilder builder, string value) { builder.groupRef.RefName = builder.ParseQName(value, "ref"); }
private static void BuildDocumentation_XmlLang(XsdBuilder builder, string value) { try { builder.documentation.Language = value; } catch (XmlSchemaException e) { e.SetSource(builder.reader.BaseURI, builder.positionInfo.LineNumber, builder.positionInfo.LinePosition); builder.SendValidationEvent(e); } }
/* <documentation source = uriReference> Content: ({any})* </documentation> */ private static void InitDocumentation(XsdBuilder builder, string value) { builder.xso = builder.documentation = new XmlSchemaDocumentation(); builder.annotation.Items.Add(builder.documentation); builder.markup = new XmlNode[] {}; }
private static void BuildAppinfo_Source(XsdBuilder builder, string value) { builder.appInfo.Source = ParseUriReference(value); }
/* <annotation> Content: (appinfo | documentation)* </annotation> */ private static void InitAnnotation(XsdBuilder builder, string value) { // On most elements annotations are only allowed to be the first child // (so the element must not have any children by now), and only one annotation is allowed. // Exceptions are xs:schema and xs:redefine, these can have any number of annotations // in any place. if (builder.hasChild && builder.ParentElement != SchemaNames.Token.XsdSchema && builder.ParentElement != SchemaNames.Token.XsdRedefine) { builder.SendValidationEvent(Res.Sch_AnnotationLocation, null); } builder.xso = builder.annotation = new XmlSchemaAnnotation(); builder.ParentContainer.AddAnnotation(builder.annotation); }
/* <field id = ID xpath = An XPath expression {any attributes with non-schema namespace . . .}> Content: (annotation?) </field> */ private static void InitField(XsdBuilder builder, string value) { builder.xso = builder.xpath = new XmlSchemaXPath(); // no selector before fields? if ( builder.identityConstraint.Selector == null ) { builder.SendValidationEvent(Res.Sch_SelectorBeforeFields, builder.identityConstraint.Name); } builder.identityConstraint.Fields.Add(builder.xpath); }
/* <selector id = ID xpath = An XPath expression {any attributes with non-schema namespace . . .}> Content: (annotation?) </selector> */ private static void InitSelector(XsdBuilder builder, string value) { builder.xso = builder.xpath = new XmlSchemaXPath(); if ( builder.identityConstraint.Selector == null ) { builder.identityConstraint.Selector = builder.xpath; } else { builder.SendValidationEvent(Res.Sch_DupSelector, builder.identityConstraint.Name); } }
/* <notation id = ID name = NCName public = A public identifier, per ISO 8879 system = uriReference {any attributes with non-schema namespace . . .}> Content: (annotation?) </notation> */ private static void InitNotation(XsdBuilder builder, string value) { builder.xso = builder.notation = new XmlSchemaNotation(); builder.canIncludeImport = false; builder.schema.Items.Add(builder.notation); }
private static void BuildAny_ProcessContents(XsdBuilder builder, string value) { builder.anyElement.ProcessContents = (XmlSchemaContentProcessing)builder.ParseEnum(value, "processContents", ProcessContentsStringValues); }
private static void BuildAny_Namespace(XsdBuilder builder, string value) { builder.anyElement.Namespace = value; }
/* <any id = ID maxOccurs = for maxOccurs : 1 minOccurs = nonNegativeInteger : 1 namespace = ##any | ##other | list of {uri, ##targetNamespace, ##local} : ##any processContents = skip | lax | strict : strict {any attributes with non-schema namespace . . .}> Content: (annotation?) </any> */ private static void InitAny(XsdBuilder builder, string value) { builder.xso = builder.particle = builder.anyElement = new XmlSchemaAny(); builder.AddParticle(builder.anyElement); }
/* <sequence id = ID maxOccurs = for maxOccurs : 1 minOccurs = nonNegativeInteger : 1 {any attributes with non-schema namespace . . .}> Content: (annotation? , (element | group | choice | sequence | any)*) </sequence> */ private static void InitSequence(XsdBuilder builder, string value) { builder.xso = builder.particle = builder.sequence = new XmlSchemaSequence(); builder.AddParticle(builder.sequence); }
/* <choice id = ID maxOccurs = for maxOccurs : 1 minOccurs = nonNegativeInteger : 1 {any attributes with non-schema namespace . . .}> Content: (annotation? , (element | group | choice | sequence | any)*) </choice> */ private static void InitChoice(XsdBuilder builder, string value) { builder.xso = builder.particle = builder.choice = new XmlSchemaChoice(); builder.AddParticle(builder.choice); }
/* <all id = ID maxOccurs = for maxOccurs : 1 minOccurs = nonNegativeInteger : 1 {any attributes with non-schema namespace . . .}> Content: (annotation? , element*) </all> */ private static void InitAll(XsdBuilder builder, string value) { builder.xso = builder.particle = builder.all = new XmlSchemaAll(); builder.AddParticle(builder.all); }
private static void BuildIdentityConstraint_Name(XsdBuilder builder, string value) { builder.identityConstraint.Name = value; }
private static void BuildIdentityConstraint_Refer(XsdBuilder builder, string value) { if (builder.identityConstraint is XmlSchemaKeyref) { ((XmlSchemaKeyref)builder.identityConstraint).Refer = builder.ParseQName(value, "refer"); } else { builder.SendValidationEvent(Res.Sch_UnsupportedAttribute, "refer"); } }
private static void BuildNotation_Name(XsdBuilder builder, string value) { builder.notation.Name = value; }
private static void BuildSelector_XPath(XsdBuilder builder, string value) { builder.xpath.XPath = value; }
private static void BuildNotation_Public(XsdBuilder builder, string value) { builder.notation.Public = value; }
private static void BuildField_XPath(XsdBuilder builder, string value) { builder.xpath.XPath = value; }
private static void BuildNotation_System(XsdBuilder builder, string value) { builder.notation.System = value; }
/* <appinfo source = uriReference> Content: ({any})* </appinfo> */ private static void InitAppinfo(XsdBuilder builder, string value) { builder.xso = builder.appInfo = new XmlSchemaAppInfo(); builder.annotation.Items.Add(builder.appInfo); builder.markup = new XmlNode[] {}; }
// // Facets // /* <duration id = ID value = timeDuration fixed = boolean : false> Content: (annotation?) </duration> */ private static void InitFacet(XsdBuilder builder, string value) { switch (builder.CurrentElement) { case SchemaNames.Token.XsdEnumeration: builder.facet = new XmlSchemaEnumerationFacet(); break; case SchemaNames.Token.XsdLength: builder.facet = new XmlSchemaLengthFacet(); break; case SchemaNames.Token.XsdMaxExclusive: builder.facet = new XmlSchemaMaxExclusiveFacet(); break; case SchemaNames.Token.XsdMaxInclusive: builder.facet = new XmlSchemaMaxInclusiveFacet(); break; case SchemaNames.Token.XsdMaxLength: builder.facet = new XmlSchemaMaxLengthFacet(); break; case SchemaNames.Token.XsdMinExclusive: builder.facet = new XmlSchemaMinExclusiveFacet(); break; case SchemaNames.Token.XsdMinInclusive: builder.facet = new XmlSchemaMinInclusiveFacet(); break; case SchemaNames.Token.XsdMinLength: builder.facet = new XmlSchemaMinLengthFacet(); break; case SchemaNames.Token.XsdPattern: builder.facet = new XmlSchemaPatternFacet(); break; case SchemaNames.Token.XsdTotalDigits: builder.facet = new XmlSchemaTotalDigitsFacet(); break; case SchemaNames.Token.XsdFractionDigits: builder.facet = new XmlSchemaFractionDigitsFacet(); break; case SchemaNames.Token.XsdWhitespace: builder.facet = new XmlSchemaWhiteSpaceFacet(); break; } builder.xso = builder.facet; if (SchemaNames.Token.XsdSimpleTypeRestriction == builder.ParentElement) { builder.simpleTypeRestriction.Facets.Add(builder.facet); } else { if (builder.simpleContentRestriction.Attributes.Count != 0 || (builder.simpleContentRestriction.AnyAttribute != null)) { builder.SendValidationEvent(Res.Sch_InvalidFacetPosition, null); } builder.simpleContentRestriction.Facets.Add(builder.facet); } }
private static void EndAppinfo(XsdBuilder builder) { builder.appInfo.Markup = builder.markup; }
private static void BuildFacet_Fixed(XsdBuilder builder, string value) { builder.facet.IsFixed = builder.ParseBoolean(value, "fixed"); }
private static void BuildDocumentation_Source(XsdBuilder builder, string value) { builder.documentation.Source = ParseUriReference(value); }
private static void BuildFacet_Value(XsdBuilder builder, string value) { builder.facet.Value = value; }
private static void EndDocumentation(XsdBuilder builder) { builder.documentation.Markup = builder.markup; }
/* <unique id = ID name = NCName {any attributes with non-schema namespace . . .}> Content: (annotation? , (selector , field+)) </unique> <key id = ID name = NCName {any attributes with non-schema namespace . . .}> Content: (annotation? , (selector , field+)) </key> <keyref id = ID name = NCName refer = QName {any attributes with non-schema namespace . . .}> Content: (annotation? , (selector , field+)) </keyref> */ private static void InitIdentityConstraint(XsdBuilder builder, string value) { if (!builder.element.RefName.IsEmpty) { builder.SendValidationEvent(Res.Sch_ElementRef, null); } switch (builder.CurrentElement) { case SchemaNames.Token.XsdUnique: builder.xso = builder.identityConstraint = new XmlSchemaUnique(); break; case SchemaNames.Token.XsdKey: builder.xso = builder.identityConstraint = new XmlSchemaKey(); break; case SchemaNames.Token.XsdKeyref: builder.xso = builder.identityConstraint = new XmlSchemaKeyref(); break; } builder.element.Constraints.Add(builder.identityConstraint); }