2 // System.Xml.Schema.XmlSchema.cs
\r
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
\r
6 // Atsushi Enomoto ginga@kit.hi-ho.ne.jp
\r
9 using System.Collections;
\r
12 using System.Xml.Serialization;
\r
13 using System.ComponentModel;
\r
15 namespace System.Xml.Schema
\r
18 /// Summary description for XmlSchema.
\r
20 [XmlRoot("schema",Namespace=XmlSchema.Namespace)]
\r
21 public class XmlSchema : XmlSchemaObject
\r
24 public const string Namespace = "http://www.w3.org/2001/XMLSchema";
\r
25 public const string InstanceNamespace = "http://www.w3.org/2001/XMLSchema-instance";
\r
28 private XmlSchemaForm attributeFormDefault ;
\r
29 private XmlSchemaObjectTable attributeGroups ;
\r
30 private XmlSchemaObjectTable attributes ;
\r
31 private XmlSchemaDerivationMethod blockDefault ;
\r
32 private XmlSchemaForm elementFormDefault ;
\r
33 private XmlSchemaObjectTable elements ;
\r
34 private XmlSchemaDerivationMethod finalDefault ;
\r
35 private XmlSchemaObjectTable groups ;
\r
37 private XmlSchemaObjectCollection includes ;
\r
38 private XmlSchemaObjectCollection items ;
\r
39 private XmlSchemaObjectTable notations ;
\r
40 private XmlSchemaObjectTable schemaTypes ;
\r
41 private string targetNamespace ;
\r
42 private XmlAttribute[] unhandledAttributes ;
\r
43 private string version;
\r
44 private string language;
\r
46 // other post schema compilation infoset
\r
47 private Hashtable idCollection;
\r
48 private XmlSchemaObjectTable namedIdentities;
\r
49 private XmlSchemaCollection schemas;
\r
51 private XmlNameTable nameTable;
\r
52 private XmlResolver resolver;
\r
54 internal bool missedSubComponents;
\r
56 // Compiler specific things
\r
57 private static string xmlname = "schema";
\r
61 attributeFormDefault= XmlSchemaForm.None;
\r
62 blockDefault = XmlSchemaDerivationMethod.None;
\r
63 elementFormDefault = XmlSchemaForm.None;
\r
64 finalDefault = XmlSchemaDerivationMethod.None;
\r
65 includes = new XmlSchemaObjectCollection();
\r
67 items = new XmlSchemaObjectCollection();
\r
68 attributeGroups = new XmlSchemaObjectTable();
\r
69 attributes = new XmlSchemaObjectTable();
\r
70 elements = new XmlSchemaObjectTable();
\r
71 groups = new XmlSchemaObjectTable();
\r
72 notations = new XmlSchemaObjectTable();
\r
73 schemaTypes = new XmlSchemaObjectTable();
\r
74 idCollection = new Hashtable ();
\r
75 namedIdentities = new XmlSchemaObjectTable();
\r
80 [DefaultValue(XmlSchemaForm.None)]
\r
81 [System.Xml.Serialization.XmlAttribute("attributeFormDefault")]
\r
82 public XmlSchemaForm AttributeFormDefault
\r
84 get{ return attributeFormDefault; }
\r
85 set{ this.attributeFormDefault = value;}
\r
88 [DefaultValue(XmlSchemaDerivationMethod.None)]
\r
89 [System.Xml.Serialization.XmlAttribute("blockDefault")]
\r
90 public XmlSchemaDerivationMethod BlockDefault
\r
92 get{ return blockDefault;}
\r
93 set{ blockDefault = value;}
\r
96 [DefaultValue(XmlSchemaDerivationMethod.None)]
\r
97 [System.Xml.Serialization.XmlAttribute("finalDefault")]
\r
98 public XmlSchemaDerivationMethod FinalDefault
\r
100 get{ return finalDefault;}
\r
101 set{ finalDefault = value;}
\r
104 [DefaultValue(XmlSchemaForm.None)]
\r
105 [System.Xml.Serialization.XmlAttribute("elementFormDefault")]
\r
106 public XmlSchemaForm ElementFormDefault
\r
108 get{ return elementFormDefault;}
\r
109 set{ elementFormDefault = value;}
\r
112 [System.Xml.Serialization.XmlAttribute("targetNamespace")]
\r
113 public string TargetNamespace
\r
115 get{ return targetNamespace;}
\r
116 set{ targetNamespace = value;}
\r
119 [System.Xml.Serialization.XmlAttribute("version")]
\r
120 public string Version
\r
122 get{ return version;}
\r
123 set{ version = value;}
\r
126 [XmlElement("include",typeof(XmlSchemaInclude),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
127 [XmlElement("import",typeof(XmlSchemaImport),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
128 [XmlElement("redefine",typeof(XmlSchemaRedefine),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
129 public XmlSchemaObjectCollection Includes
\r
131 get{ return includes;}
\r
134 [XmlElement("simpleType",typeof(XmlSchemaSimpleType),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
135 [XmlElement("complexType",typeof(XmlSchemaComplexType),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
136 [XmlElement("group",typeof(XmlSchemaGroup),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
137 //Only Schema's attributeGroup has type XmlSchemaAttributeGroup.
\r
138 //Others (complextype, restrictions etc) must have XmlSchemaAttributeGroupRef
\r
139 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroup),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
140 [XmlElement("element",typeof(XmlSchemaElement),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
141 [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
142 [XmlElement("notation",typeof(XmlSchemaNotation),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
143 [XmlElement("annotation",typeof(XmlSchemaAnnotation),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
144 public XmlSchemaObjectCollection Items
\r
146 get{ return items;}
\r
150 public bool IsCompiled
\r
152 get{ return this.CompilationId != Guid.Empty;}
\r
156 public XmlSchemaObjectTable Attributes
\r
158 get{ return attributes;}
\r
162 public XmlSchemaObjectTable AttributeGroups
\r
164 get{ return attributeGroups; }
\r
168 public XmlSchemaObjectTable SchemaTypes
\r
170 get{ return schemaTypes; }
\r
174 public XmlSchemaObjectTable Elements
\r
176 get{ return elements;}
\r
179 [System.Xml.Serialization.XmlAttribute("id")]
\r
187 public XmlAttribute[] UnhandledAttributes
\r
191 if(unhandledAttributeList != null)
\r
193 unhandledAttributes = (XmlAttribute[]) unhandledAttributeList.ToArray(typeof(XmlAttribute));
\r
194 unhandledAttributeList = null;
\r
196 return unhandledAttributes;
\r
200 unhandledAttributes = value;
\r
201 unhandledAttributeList = null;
\r
206 public XmlSchemaObjectTable Groups
\r
208 get{ return groups;}
\r
212 public XmlSchemaObjectTable Notations
\r
214 get{ return notations;}
\r
217 // New attribute defined in W3C schema element
\r
218 [System.Xml.Serialization.XmlAttribute("xml:lang")]
\r
219 public string Language
\r
221 get{ return language; }
\r
222 set{ language = value; }
\r
225 internal Hashtable IDCollection
\r
227 get { return idCollection; }
\r
230 internal XmlSchemaObjectTable NamedIdentities
\r
232 get { return namedIdentities; }
\r
235 internal XmlSchemaCollection Schemas
\r
237 get { return schemas; }
\r
245 /// This compile method does two things:
\r
246 /// 1. It compiles and fills the PSVI dataset
\r
247 /// 2. Validates the schema by calling Validate method.
\r
248 /// Every XmlSchemaObject has a Compile Method which gets called.
\r
251 /// 1. blockDefault must be one of #all | List of (extension | restriction | substitution)
\r
252 /// 2. finalDefault must be one of (#all | List of (extension | restriction| union| list))
\r
253 /// 3. id must be of type ID
\r
254 /// 4. targetNamespace should be any uri
\r
255 /// 5. version should be a normalizedString
\r
256 /// 6. xml:lang should be a language
\r
259 public void Compile(ValidationEventHandler handler)
\r
261 Compile (handler, new Stack (), this, null);
\r
265 internal void Compile (ValidationEventHandler handler, XmlSchemaCollection col)
\r
267 Compile (handler, new Stack (), this, col);
\r
270 private void Compile (ValidationEventHandler handler, Stack schemaLocationStack, XmlSchema rootSchema, XmlSchemaCollection col)
\r
272 if (rootSchema != this) {
\r
273 CompilationId = rootSchema.CompilationId;
\r
274 schemas = rootSchema.schemas;
\r
278 if (schemas == null) {
\r
279 schemas = new XmlSchemaCollection ();
\r
280 schemas.CompilationId = Guid.NewGuid ();
\r
282 CompilationId = schemas.CompilationId;
\r
283 this.idCollection.Clear ();
\r
285 schemas.Add (this);
\r
287 attributeGroups = new XmlSchemaObjectTable ();
\r
288 attributes = new XmlSchemaObjectTable ();
\r
289 elements = new XmlSchemaObjectTable ();
\r
290 groups = new XmlSchemaObjectTable ();
\r
291 notations = new XmlSchemaObjectTable ();
\r
292 schemaTypes = new XmlSchemaObjectTable ();
\r
294 //1. Union and List are not allowed in block default
\r
295 if(BlockDefault != XmlSchemaDerivationMethod.All)
\r
297 if((BlockDefault & XmlSchemaDerivationMethod.List)!=0 )
\r
298 error(handler, "list is not allowed in blockDefault attribute");
\r
299 if((BlockDefault & XmlSchemaDerivationMethod.Union)!=0 )
\r
300 error(handler, "union is not allowed in blockDefault attribute");
\r
303 //2. Substitution is not allowed in finaldefault.
\r
304 if(FinalDefault != XmlSchemaDerivationMethod.All)
\r
306 if((FinalDefault & XmlSchemaDerivationMethod.Substitution)!=0 )
\r
307 error(handler, "substitution is not allowed in finalDefault attribute");
\r
310 //3. id must be of type ID
\r
311 XmlSchemaUtil.CompileID(Id, this, this.IDCollection, handler);
\r
313 //4. targetNamespace should be of type anyURI or absent
\r
314 if(TargetNamespace != null)
\r
316 if(!XmlSchemaUtil.CheckAnyUri(TargetNamespace))
\r
317 error(handler, TargetNamespace+" is not a valid value for targetNamespace attribute of schema");
\r
320 //5. version should be of type normalizedString
\r
321 if(!XmlSchemaUtil.CheckNormalizedString(Version))
\r
322 error(handler, Version + "is not a valid value for version attribute of schema");
\r
324 //6. xml:lang must be a language
\r
325 if(!XmlSchemaUtil.CheckLanguage(Language))
\r
326 error(handler, Language + " is not a valid language");
\r
328 // Compile the content of this schema
\r
330 XmlSchemaObjectCollection compilationItems = new XmlSchemaObjectCollection ();
\r
331 foreach (XmlSchemaObject obj in Items)
\r
332 compilationItems.Add (obj);
\r
334 // First, we run into inclusion schemas to collect
\r
335 // compilation target items into compiledItems.
\r
336 foreach(XmlSchemaObject obj in Includes)
\r
338 XmlSchemaExternal ext = obj as XmlSchemaExternal;
\r
341 if (ext.SchemaLocation == null)
\r
343 string url = GetResolvedUri (ext.SchemaLocation);
\r
344 Stream stream = null;
\r
345 if (schemaLocationStack.Contains (url)) {
\r
346 error(handler, "Nested inclusion was found: " + url);
\r
347 // must skip this inclusion
\r
351 if (resolver == null)
\r
352 resolver = new XmlUrlResolver ();
\r
353 stream = resolver.GetEntity (new Uri (url), null, typeof (Stream)) as Stream;
\r
354 } catch (Exception ex) {
\r
355 // FIXME: This is not good way to handle errors.
\r
359 // Process redefinition children in advance.
\r
360 XmlSchemaRedefine redefine = obj as XmlSchemaRedefine;
\r
361 if (redefine != null) {
\r
362 foreach (XmlSchemaObject redefinedObj in redefine.Items) {
\r
363 redefinedObj.isRedefinedComponent = true;
\r
364 redefinedObj.isRedefineChild = true;
\r
365 if (redefinedObj is XmlSchemaType ||
\r
366 redefinedObj is XmlSchemaGroup ||
\r
367 redefinedObj is XmlSchemaAttributeGroup)
\r
368 compilationItems.Add (redefinedObj);
\r
370 error (handler, "Redefinition is only allowed to simpleType, complexType, group and attributeGroup.");
\r
374 XmlSchema includedSchema = null;
\r
375 if (stream == null) {
\r
376 // It is missing schema components.
\r
377 missedSubComponents = true;
\r
380 schemaLocationStack.Push (url);
\r
381 includedSchema = XmlSchema.Read (new XmlTextReader (url, stream, nameTable), handler);
\r
382 includedSchema.schemas = schemas;
\r
385 // Set - actual - target namespace for the included schema * before compilation*.
\r
386 XmlSchemaImport import = ext as XmlSchemaImport;
\r
387 if (import != null) {
\r
388 if (TargetNamespace == includedSchema.TargetNamespace) {
\r
389 error (handler, "Target namespace must be different from that of included schema.");
\r
391 } else if (includedSchema.TargetNamespace != import.Namespace) {
\r
392 error (handler, "Attribute namespace and its importing schema's target namespace must be the same.");
\r
396 if (TargetNamespace == null &&
\r
397 includedSchema.TargetNamespace != null) {
\r
398 error (handler, "Target namespace is required to include a schema which has its own target namespace");
\r
401 else if (TargetNamespace != null &&
\r
402 includedSchema.TargetNamespace == null)
\r
403 includedSchema.TargetNamespace = TargetNamespace;
\r
406 // Compile included schema.
\r
407 includedSchema.idCollection = this.IDCollection;
\r
408 includedSchema.Compile (handler, schemaLocationStack, rootSchema, col);
\r
409 schemaLocationStack.Pop ();
\r
411 if (import != null)
\r
412 rootSchema.schemas.Add (includedSchema);
\r
414 // Add compiled items.
\r
415 foreach (XmlSchemaObject includedObj in includedSchema.Items)
\r
416 compilationItems.Add (includedObj);
\r
420 error(handler,"Object of Type "+obj.GetType().Name+" is not valid in Includes Property of XmlSchema");
\r
424 // Compilation phase.
\r
425 // At least each Compile() must gives unique (qualified) name for each component.
\r
426 // It also checks self-resolvable properties correct.
\r
427 // Post compilation schema information contribution is not required here.
\r
428 // It should be done by Validate().
\r
429 foreach(XmlSchemaObject obj in compilationItems)
\r
431 if(obj is XmlSchemaAnnotation)
\r
433 int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this);
\r
434 errorCount += numerr;
\r
437 //FIXME: What PSVI set do we add this to?
\r
440 else if(obj is XmlSchemaAttribute)
\r
442 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
443 attr.ParentIsSchema = true;
\r
444 int numerr = attr.Compile(handler, this);
\r
445 errorCount += numerr;
\r
448 XmlSchemaUtil.AddToTable (Attributes, attr, attr.QualifiedName, handler);
\r
451 else if(obj is XmlSchemaAttributeGroup)
\r
453 XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup) obj;
\r
454 int numerr = attrgrp.Compile(handler, this);
\r
455 errorCount += numerr;
\r
458 XmlSchemaUtil.AddToTable (AttributeGroups, attrgrp, attrgrp.QualifiedName, handler);
\r
461 else if(obj is XmlSchemaComplexType)
\r
463 XmlSchemaComplexType ctype = (XmlSchemaComplexType) obj;
\r
464 ctype.ParentIsSchema = true;
\r
465 int numerr = ctype.Compile(handler, this);
\r
466 errorCount += numerr;
\r
469 XmlSchemaUtil.AddToTable (schemaTypes, ctype, ctype.QualifiedName, handler);
\r
472 else if(obj is XmlSchemaSimpleType)
\r
474 XmlSchemaSimpleType stype = (XmlSchemaSimpleType) obj;
\r
475 stype.islocal = false; //This simple type is toplevel
\r
476 int numerr = stype.Compile(handler, this);
\r
477 errorCount += numerr;
\r
480 XmlSchemaUtil.AddToTable (SchemaTypes, stype, stype.QualifiedName, handler);
\r
483 else if(obj is XmlSchemaElement)
\r
485 XmlSchemaElement elem = (XmlSchemaElement) obj;
\r
486 elem.parentIsSchema = true;
\r
487 int numerr = elem.Compile(handler, this);
\r
488 errorCount += numerr;
\r
491 XmlSchemaUtil.AddToTable (Elements, elem, elem.QualifiedName, handler);
\r
494 else if(obj is XmlSchemaGroup)
\r
496 XmlSchemaGroup grp = (XmlSchemaGroup) obj;
\r
497 int numerr = grp.Compile(handler, this);
\r
498 errorCount += numerr;
\r
501 XmlSchemaUtil.AddToTable (Groups, grp, grp.QualifiedName, handler);
\r
504 else if(obj is XmlSchemaNotation)
\r
506 XmlSchemaNotation ntn = (XmlSchemaNotation) obj;
\r
507 int numerr = ntn.Compile(handler, this);
\r
508 errorCount += numerr;
\r
511 XmlSchemaUtil.AddToTable (Notations, ntn, ntn.QualifiedName, handler);
\r
516 ValidationHandler.RaiseValidationEvent (
\r
518 "Object of Type "+obj.GetType().Name+" is not valid in Item Property of Schema",
\r
519 null, this, null, XmlSeverityType.Error);
\r
523 if (rootSchema == this)
\r
527 private string GetResolvedUri (string relativeUri)
\r
529 Uri baseUri = null;
\r
530 if (this.SourceUri != null && this.SourceUri != String.Empty)
\r
531 baseUri = new Uri (this.SourceUri);
\r
532 return new XmlUrlResolver ().ResolveUri (baseUri, relativeUri).ToString ();
\r
538 private void Validate(ValidationEventHandler handler)
\r
540 ValidationId = CompilationId;
\r
542 foreach(XmlSchemaAttribute attr in Attributes.Values)
\r
544 errorCount += attr.Validate(handler, this);
\r
546 foreach(XmlSchemaAttributeGroup attrgrp in AttributeGroups.Values)
\r
548 errorCount += attrgrp.Validate(handler, this);
\r
550 foreach(XmlSchemaType type in SchemaTypes.Values)
\r
552 errorCount += type.Validate(handler, this);
\r
554 foreach(XmlSchemaElement elem in Elements.Values)
\r
556 errorCount += elem.Validate(handler, this);
\r
558 foreach(XmlSchemaGroup grp in Groups.Values)
\r
560 errorCount += grp.Validate(handler, this);
\r
562 foreach(XmlSchemaNotation ntn in Notations.Values)
\r
564 errorCount += ntn.Validate(handler, this);
\r
570 public static XmlSchema Read(TextReader reader, ValidationEventHandler validationEventHandler)
\r
572 return Read(new XmlTextReader(reader),validationEventHandler);
\r
574 public static XmlSchema Read(Stream stream, ValidationEventHandler validationEventHandler)
\r
576 return Read(new XmlTextReader(stream),validationEventHandler);
\r
579 [MonoTODO ("Use ValidationEventHandler")]
\r
580 public static XmlSchema Read(XmlReader rdr, ValidationEventHandler validationEventHandler)
\r
583 string baseURI = rdr.BaseURI;
\r
584 XmlSerializer xser = new XmlSerializer (typeof (XmlSchema));
\r
585 XmlSchema schema = (XmlSchema) xser.Deserialize (rdr);
\r
586 schema.SourceUri = baseURI;
\r
587 schema.Compile (validationEventHandler);
\r
588 schema.nameTable = rdr.NameTable;
\r
591 XmlSchemaReader reader = new XmlSchemaReader(rdr, validationEventHandler);
\r
593 while(reader.ReadNextElement())
\r
595 switch(reader.NodeType)
\r
597 case XmlNodeType.Element:
\r
598 if(reader.LocalName == "schema")
\r
600 XmlSchema schema = new XmlSchema();
\r
601 schema.nameTable = rdr.NameTable;
\r
603 schema.LineNumber = reader.LineNumber;
\r
604 schema.LinePosition = reader.LinePosition;
\r
605 schema.SourceUri = reader.BaseURI;
\r
607 ReadAttributes(schema, reader, validationEventHandler);
\r
608 //IsEmptyElement does not behave properly if reader is
\r
609 //positioned at an attribute.
\r
610 reader.MoveToElement();
\r
611 if(!reader.IsEmptyElement)
\r
613 ReadContent(schema, reader, validationEventHandler);
\r
619 //Schema can't be generated. Throw an exception
\r
620 throw new XmlSchemaException("The root element must be schema", null);
\r
623 error(validationEventHandler, "This should never happen. XmlSchema.Read 1 ",null);
\r
627 throw new XmlSchemaException("The top level schema must have namespace "+XmlSchema.Namespace, null);
\r
630 private static void ReadAttributes(XmlSchema schema, XmlSchemaReader reader, ValidationEventHandler h)
\r
634 reader.MoveToElement();
\r
635 while(reader.MoveToNextAttribute())
\r
637 switch(reader.Name)
\r
639 case "attributeFormDefault" :
\r
640 schema.attributeFormDefault = XmlSchemaUtil.ReadFormAttribute(reader,out ex);
\r
642 error(h, reader.Value + " is not a valid value for attributeFormDefault.", ex);
\r
644 case "blockDefault" :
\r
645 schema.blockDefault = XmlSchemaUtil.ReadDerivationAttribute(reader,out ex, "blockDefault",
\r
646 XmlSchemaUtil.ElementBlockAllowed);
\r
648 warn(h, ex.Message, ex);
\r
650 case "elementFormDefault":
\r
651 schema.elementFormDefault = XmlSchemaUtil.ReadFormAttribute(reader, out ex);
\r
653 error(h, reader.Value + " is not a valid value for elementFormDefault.", ex);
\r
655 case "finalDefault":
\r
656 schema.finalDefault = XmlSchemaUtil.ReadDerivationAttribute(reader, out ex, "finalDefault",
\r
657 XmlSchemaUtil.FinalAllowed);
\r
659 warn(h, ex.Message , ex);
\r
662 schema.id = reader.Value;
\r
664 case "targetNamespace":
\r
665 schema.targetNamespace = reader.Value;
\r
668 schema.version = reader.Value;
\r
671 schema.language = reader.Value;
\r
674 if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
675 error(h, reader.Name + " attribute is not allowed in schema element",null);
\r
678 XmlSchemaUtil.ReadUnhandledAttribute(reader,schema);
\r
685 private static void ReadContent(XmlSchema schema, XmlSchemaReader reader, ValidationEventHandler h)
\r
687 reader.MoveToElement();
\r
688 if(reader.LocalName != "schema" && reader.NamespaceURI != XmlSchema.Namespace && reader.NodeType != XmlNodeType.Element)
\r
689 error(h, "UNREACHABLE CODE REACHED: Method: Schema.ReadContent, " + reader.LocalName + ", " + reader.NamespaceURI,null);
\r
691 //(include | import | redefine | annotation)*,
\r
692 //((simpleType | complexType | group | attributeGroup | element | attribute | notation | annotation)*
\r
694 while(reader.ReadNextElement())
\r
696 if(reader.NodeType == XmlNodeType.EndElement)
\r
698 if(reader.LocalName != xmlname)
\r
699 error(h,"Should not happen :2: XmlSchema.Read, name="+reader.Name,null);
\r
704 if(reader.LocalName == "include")
\r
706 XmlSchemaInclude include = XmlSchemaInclude.Read(reader,h);
\r
707 if(include != null)
\r
708 schema.includes.Add(include);
\r
711 if(reader.LocalName == "import")
\r
713 XmlSchemaImport import = XmlSchemaImport.Read(reader,h);
\r
715 schema.includes.Add(import);
\r
718 if(reader.LocalName == "redefine")
\r
720 XmlSchemaRedefine redefine = XmlSchemaRedefine.Read(reader,h);
\r
721 if(redefine != null)
\r
722 schema.includes.Add(redefine);
\r
725 if(reader.LocalName == "annotation")
\r
727 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
728 if(annotation != null)
\r
729 schema.items.Add(annotation);
\r
736 if(reader.LocalName == "simpleType")
\r
738 XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader,h);
\r
740 schema.items.Add(stype);
\r
743 if(reader.LocalName == "complexType")
\r
745 XmlSchemaComplexType ctype = XmlSchemaComplexType.Read(reader,h);
\r
747 schema.items.Add(ctype);
\r
750 if(reader.LocalName == "group")
\r
752 XmlSchemaGroup group = XmlSchemaGroup.Read(reader,h);
\r
754 schema.items.Add(group);
\r
757 if(reader.LocalName == "attributeGroup")
\r
759 XmlSchemaAttributeGroup attributeGroup = XmlSchemaAttributeGroup.Read(reader,h);
\r
760 if(attributeGroup != null)
\r
761 schema.items.Add(attributeGroup);
\r
764 if(reader.LocalName == "element")
\r
766 XmlSchemaElement element = XmlSchemaElement.Read(reader,h);
\r
767 if(element != null)
\r
768 schema.items.Add(element);
\r
771 if(reader.LocalName == "attribute")
\r
773 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
775 schema.items.Add(attr);
\r
778 if(reader.LocalName == "notation")
\r
780 XmlSchemaNotation notation = XmlSchemaNotation.Read(reader,h);
\r
781 if(notation != null)
\r
782 schema.items.Add(notation);
\r
785 if(reader.LocalName == "annotation")
\r
787 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
788 if(annotation != null)
\r
789 schema.items.Add(annotation);
\r
793 reader.RaiseInvalidElementError();
\r
800 public void Write(System.IO.Stream stream)
\r
802 Write(stream,null);
\r
804 public void Write(System.IO.TextWriter writer)
\r
806 Write(writer,null);
\r
808 public void Write(System.Xml.XmlWriter writer)
\r
810 Write(writer,null);
\r
812 public void Write(System.IO.Stream stream, System.Xml.XmlNamespaceManager namespaceManager)
\r
814 Write(new XmlTextWriter(stream,null),namespaceManager);
\r
816 public void Write(System.IO.TextWriter writer, System.Xml.XmlNamespaceManager namespaceManager)
\r
818 XmlTextWriter xwriter = new XmlTextWriter(writer);
\r
819 xwriter.Formatting = Formatting.Indented;
\r
820 Write(xwriter,namespaceManager);
\r
822 public void Write(System.Xml.XmlWriter writer, System.Xml.XmlNamespaceManager namespaceManager)
\r
824 if(Namespaces == null)
\r
826 Namespaces = new XmlSerializerNamespaces();
\r
828 //Add the xml schema namespace.
\r
829 if(Namespaces.Count == 0)
\r
831 if (writer.LookupPrefix (XmlSchema.Namespace) == null)
\r
832 Namespaces.Add("xs", XmlSchema.Namespace);
\r
833 if (TargetNamespace != null && TargetNamespace != String.Empty)
\r
834 Namespaces.Add("tns", TargetNamespace);
\r
836 if(namespaceManager != null)
\r
838 foreach(string name in namespaceManager)
\r
840 //xml and xmlns namespaced are added by default in namespaceManager.
\r
841 //So we should ignore them
\r
842 if(name!="xml" && name != "xmlns")
\r
843 Namespaces.Add(name,namespaceManager.LookupNamespace(name));
\r
847 XmlSerializer xser = new XmlSerializer(typeof(XmlSchema));
\r
848 xser.Serialize(writer,this,Namespaces);
\r