Inheritance: SchemaBuilder
Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
 private static void BuildGroupRef_Ref(XsdBuilder builder, string value) {
     builder.groupRef.RefName = builder.ParseQName(value, "ref");
 }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
 /*
     <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[] {};
 }
Exemplo n.º 5
0
 private static void BuildAppinfo_Source(XsdBuilder builder, string value) {
     builder.appInfo.Source = ParseUriReference(value);
 }
Exemplo n.º 6
0
 /*
     <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);
 }
Exemplo n.º 7
0
 /*
     <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);
 }
Exemplo n.º 8
0
 /*
     <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);
     }
 }
Exemplo n.º 9
0
 /*
     <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);
 }
Exemplo n.º 10
0
 private static void BuildAny_ProcessContents(XsdBuilder builder, string value) {
     builder.anyElement.ProcessContents = (XmlSchemaContentProcessing)builder.ParseEnum(value, "processContents", ProcessContentsStringValues);
 }
Exemplo n.º 11
0
 private static void BuildAny_Namespace(XsdBuilder builder, string value) {
     builder.anyElement.Namespace = value;
 } 
Exemplo n.º 12
0
 /*
     <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);
 } 
Exemplo n.º 13
0
 /*
      <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);
 }
Exemplo n.º 14
0
 /*
     <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);
 }
Exemplo n.º 15
0
 /*
     <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);
 }
Exemplo n.º 16
0
 private static void BuildIdentityConstraint_Name(XsdBuilder builder, string value) {
     builder.identityConstraint.Name = value;
 } 
Exemplo n.º 17
0
 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");
     }
 } 
Exemplo n.º 18
0
 private static void BuildNotation_Name(XsdBuilder builder, string value) {
     builder.notation.Name = value;
 }
Exemplo n.º 19
0
 private static void BuildSelector_XPath(XsdBuilder builder, string value) {
     builder.xpath.XPath = value;
 } 
Exemplo n.º 20
0
 private static void BuildNotation_Public(XsdBuilder builder, string value) {
     builder.notation.Public = value;
 }
Exemplo n.º 21
0
 private static void BuildField_XPath(XsdBuilder builder, string value) {
     builder.xpath.XPath = value;
 } 
Exemplo n.º 22
0
 private static void BuildNotation_System(XsdBuilder builder, string value) {
     builder.notation.System = value;
 }
Exemplo n.º 23
0
 /*
     <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[] {};
 }
Exemplo n.º 24
0
 //
 // 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);
     }
 }
Exemplo n.º 25
0
 private static void EndAppinfo(XsdBuilder builder) {
     builder.appInfo.Markup = builder.markup;
 }
Exemplo n.º 26
0
 private static void BuildFacet_Fixed(XsdBuilder builder, string value) {
     builder.facet.IsFixed = builder.ParseBoolean(value, "fixed");
 }
Exemplo n.º 27
0
 private static void BuildDocumentation_Source(XsdBuilder builder, string value) {
     builder.documentation.Source = ParseUriReference(value);
 }
Exemplo n.º 28
0
 private static void BuildFacet_Value(XsdBuilder builder, string value) {
     builder.facet.Value = value;
 }
Exemplo n.º 29
0
        private static void EndDocumentation(XsdBuilder builder) {
            builder.documentation.Markup = builder.markup;

        }
Exemplo n.º 30
0
        /*
            <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);
        }