| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747 |
- //
- // System.Xml.Schema.XmlSchema.cs
- //
- // Author:
- // Dwivedi, Ajay kumar [email protected]
- // Atsushi Enomoto [email protected]
- //
- using System;
- using System.Collections;
- using System.Xml;
- using System.IO;
- using System.Xml.Serialization;
- using System.ComponentModel;
- namespace System.Xml.Schema
- {
- /// <summary>
- /// Summary description for XmlSchema.
- /// </summary>
- [XmlRoot("schema",Namespace=XmlSchema.Namespace)]
- public class XmlSchema : XmlSchemaObject
- {
- //public constants
- public const string Namespace = "http://www.w3.org/2001/XMLSchema";
- public const string InstanceNamespace = "http://www.w3.org/2001/XMLSchema-instance";
- //private fields
- private XmlSchemaForm attributeFormDefault ;
- private XmlSchemaObjectTable attributeGroups ;
- private XmlSchemaObjectTable attributes ;
- private XmlSchemaDerivationMethod blockDefault ;
- private XmlSchemaForm elementFormDefault ;
- private XmlSchemaObjectTable elements ;
- private XmlSchemaDerivationMethod finalDefault ;
- private XmlSchemaObjectTable groups ;
- private string id ;
- private XmlSchemaObjectCollection includes ;
- private XmlSchemaObjectCollection items ;
- private XmlSchemaObjectTable notations ;
- private XmlSchemaObjectTable schemaTypes ;
- private string targetNamespace ;
- private XmlAttribute[] unhandledAttributes ;
- private string version;
- private string language;
- // post schema compilation infoset
- private Hashtable idCollection;
- private Hashtable missingBaseSchemaTypeRefs;
- private Hashtable missingElementTypeRefs;
- // Compiler specific things
- private static string xmlname = "schema";
- public XmlSchema()
- {
- attributeFormDefault= XmlSchemaForm.None;
- blockDefault = XmlSchemaDerivationMethod.None;
- elementFormDefault = XmlSchemaForm.None;
- finalDefault = XmlSchemaDerivationMethod.None;
- includes = new XmlSchemaObjectCollection();
- isCompiled = false;
- items = new XmlSchemaObjectCollection();
- attributeGroups = new XmlSchemaObjectTable();
- attributes = new XmlSchemaObjectTable();
- elements = new XmlSchemaObjectTable();
- groups = new XmlSchemaObjectTable();
- notations = new XmlSchemaObjectTable();
- schemaTypes = new XmlSchemaObjectTable();
- idCollection = new Hashtable ();
- missingBaseSchemaTypeRefs = new Hashtable ();
- missingElementTypeRefs = new Hashtable ();
- }
- #region Properties
- [DefaultValue(XmlSchemaForm.None)]
- [System.Xml.Serialization.XmlAttribute("attributeFormDefault")]
- public XmlSchemaForm AttributeFormDefault
- {
- get{ return attributeFormDefault; }
- set{ this.attributeFormDefault = value;}
- }
- [DefaultValue(XmlSchemaDerivationMethod.None)]
- [System.Xml.Serialization.XmlAttribute("blockDefault")]
- public XmlSchemaDerivationMethod BlockDefault
- {
- get{ return blockDefault;}
- set{ blockDefault = value;}
- }
- [DefaultValue(XmlSchemaDerivationMethod.None)]
- [System.Xml.Serialization.XmlAttribute("finalDefault")]
- public XmlSchemaDerivationMethod FinalDefault
- {
- get{ return finalDefault;}
- set{ finalDefault = value;}
- }
- [DefaultValue(XmlSchemaForm.None)]
- [System.Xml.Serialization.XmlAttribute("elementFormDefault")]
- public XmlSchemaForm ElementFormDefault
- {
- get{ return elementFormDefault;}
- set{ elementFormDefault = value;}
- }
- [System.Xml.Serialization.XmlAttribute("targetNamespace")]
- public string TargetNamespace
- {
- get{ return targetNamespace;}
- set{ targetNamespace = value;}
- }
- [System.Xml.Serialization.XmlAttribute("version")]
- public string Version
- {
- get{ return version;}
- set{ version = value;}
- }
- [XmlElement("include",typeof(XmlSchemaInclude),Namespace="http://www.w3.org/2001/XMLSchema")]
- [XmlElement("import",typeof(XmlSchemaImport),Namespace="http://www.w3.org/2001/XMLSchema")]
- [XmlElement("redefine",typeof(XmlSchemaRedefine),Namespace="http://www.w3.org/2001/XMLSchema")]
- public XmlSchemaObjectCollection Includes
- {
- get{ return includes;}
- }
- [XmlElement("simpleType",typeof(XmlSchemaSimpleType),Namespace="http://www.w3.org/2001/XMLSchema")]
- [XmlElement("complexType",typeof(XmlSchemaComplexType),Namespace="http://www.w3.org/2001/XMLSchema")]
- [XmlElement("group",typeof(XmlSchemaGroup),Namespace="http://www.w3.org/2001/XMLSchema")]
- //Only Schema's attributeGroup has type XmlSchemaAttributeGroup.
- //Others (complextype, restrictions etc) must have XmlSchemaAttributeGroupRef
- [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroup),Namespace="http://www.w3.org/2001/XMLSchema")]
- [XmlElement("element",typeof(XmlSchemaElement),Namespace="http://www.w3.org/2001/XMLSchema")]
- [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace="http://www.w3.org/2001/XMLSchema")]
- [XmlElement("notation",typeof(XmlSchemaNotation),Namespace="http://www.w3.org/2001/XMLSchema")]
- [XmlElement("annotation",typeof(XmlSchemaAnnotation),Namespace="http://www.w3.org/2001/XMLSchema")]
- public XmlSchemaObjectCollection Items
- {
- get{ return items;}
- }
- [XmlIgnore]
- public bool IsCompiled
- {
- get{ return isCompiled;}
- }
- [XmlIgnore]
- public XmlSchemaObjectTable Attributes
- {
- get{ return attributes;}
- }
- [XmlIgnore]
- public XmlSchemaObjectTable AttributeGroups
- {
- get{ return attributeGroups; }
- }
- [XmlIgnore]
- public XmlSchemaObjectTable SchemaTypes
- {
- get{ return schemaTypes; }
- }
- [XmlIgnore]
- public XmlSchemaObjectTable Elements
- {
- get{ return elements;}
- }
- [System.Xml.Serialization.XmlAttribute("id")]
- public string Id
- {
- get{ return id;}
- set{ id = value;}
- }
- [XmlAnyAttribute]
- public XmlAttribute[] UnhandledAttributes
- {
- get
- {
- if(unhandledAttributeList != null)
- {
- unhandledAttributes = (XmlAttribute[]) unhandledAttributeList.ToArray(typeof(XmlAttribute));
- unhandledAttributeList = null;
- }
- return unhandledAttributes;
- }
- set
- {
- unhandledAttributes = value;
- unhandledAttributeList = null;
- }
- }
- [XmlIgnore]
- public XmlSchemaObjectTable Groups
- {
- get{ return groups;}
- }
- [XmlIgnore]
- public XmlSchemaObjectTable Notations
- {
- get{ return notations;}
- }
- // New attribute defined in W3C schema element
- [System.Xml.Serialization.XmlAttribute("xml:lang")]
- public string Language
- {
- get{ return language; }
- set{ language = value; }
- }
- internal Hashtable IDCollection
- {
- get { return idCollection; }
- }
- internal Hashtable MissingBaseSchemaTypeRefs
- {
- get { return missingBaseSchemaTypeRefs; }
- }
- internal Hashtable MissingElementTypeRefs
- {
- get { return missingElementTypeRefs; }
- }
- #endregion
- #region Compile
- // Methods
- /// <summary>
- /// This compile method does two things:
- /// 1. It compiles and fills the PSVI dataset
- /// 2. Validates the schema by calling Validate method.
- /// Every XmlSchemaObject has a Compile Method which gets called.
- /// </summary>
- /// <remarks>
- /// 1. blockDefault must be one of #all | List of (extension | restriction | substitution)
- /// 2. finalDefault must be one of (#all | List of (extension | restriction| union| list))
- /// 3. id must be of type ID
- /// 4. targetNamespace should be any uri
- /// 5. version should be a normalizedString
- /// 6. xml:lang should be a language
- /// </remarks>
- [MonoTODO]
- public void Compile(ValidationEventHandler handler)
- {
- CompilationId = Guid.NewGuid ();
- //1. Union and List are not allowed in block default
- if(BlockDefault != XmlSchemaDerivationMethod.All)
- {
- if((BlockDefault & XmlSchemaDerivationMethod.List)!=0 )
- error(handler, "list is not allowed in blockDefault attribute");
- if((BlockDefault & XmlSchemaDerivationMethod.Union)!=0 )
- error(handler, "union is not allowed in blockDefault attribute");
- }
- //2. Substitution is not allowed in finaldefault.
- if(FinalDefault != XmlSchemaDerivationMethod.All)
- {
- if((FinalDefault & XmlSchemaDerivationMethod.Substitution)!=0 )
- error(handler, "substitution is not allowed in finalDefault attribute");
- }
- //3. id must be of type ID
- XmlSchemaUtil.CompileID(Id, this, this.IDCollection, handler);
- //4. targetNamespace should be of type anyURI or absent
- if(TargetNamespace != null)
- {
- if(!XmlSchemaUtil.CheckAnyUri(TargetNamespace))
- error(handler, TargetNamespace+" is not a valid value for targetNamespace attribute of schema");
- }
- //5. version should be of type normalizedString
- if(!XmlSchemaUtil.CheckNormalizedString(Version))
- error(handler, Version + "is not a valid value for version attribute of schema");
- //6. xml:lang must be a language
- if(!XmlSchemaUtil.CheckLanguage(Language))
- error(handler, Language + " is not a valid language");
- // Compile the content of this schema
- foreach(XmlSchemaObject obj in Includes)
- {
- if(obj is XmlSchemaExternal)
- {
- //FIXME: Kuch to karo! (Do Something ;)
- }
- else
- {
- error(handler,"Object of Type "+obj.GetType().Name+" is not valid in Includes Property of XmlSchema");
- }
- }
- // It is hack, but types are required before element/attributes.
- foreach (XmlSchemaObject obj in Items)
- {
- if(obj is XmlSchemaComplexType)
- {
- XmlSchemaComplexType ctype = (XmlSchemaComplexType) obj;
- ctype.istoplevel = true;
- int numerr = ctype.Compile(handler, this);
- errorCount += numerr;
- if(numerr == 0)
- {
- schemaTypes.Add(ctype.QualifiedName, ctype);
- }
- }
- else if(obj is XmlSchemaSimpleType)
- {
- XmlSchemaSimpleType stype = (XmlSchemaSimpleType) obj;
- stype.islocal = false; //This simple type is toplevel
- int numerr = stype.Compile(handler, this);
- errorCount += numerr;
- if(numerr == 0)
- {
- SchemaTypes.Add(stype.QualifiedName, stype);
- }
- }
- }
- // Add missing references.
- foreach (XmlSchemaComplexType cType in missingBaseSchemaTypeRefs.Keys)
- cType.BaseSchemaTypeInternal =
- SchemaTypes [missingBaseSchemaTypeRefs [cType] as XmlQualifiedName];
- foreach(XmlSchemaObject obj in Items)
- {
- if(obj is XmlSchemaAnnotation)
- {
- int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this);
- errorCount += numerr;
- if( numerr == 0)
- {
- //FIXME: What PSVI set do we add this to?
- }
- }
- else if(obj is XmlSchemaAttribute)
- {
- XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
- attr.parentIsSchema = true;
- int numerr = attr.Compile(handler, this);
- errorCount += numerr;
- if(numerr == 0)
- {
- Attributes.Add(attr.QualifiedName, attr);
- }
- }
- else if(obj is XmlSchemaAttributeGroup)
- {
- XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup) obj;
- int numerr = attrgrp.Compile(handler, this);
- errorCount += numerr;
- if(numerr == 0)
- {
- AttributeGroups.Add(attrgrp.QualifiedName, attrgrp);
- }
- }
- else if(obj is XmlSchemaComplexType)
- {
- // Do nothing here.
- }
- else if(obj is XmlSchemaSimpleType)
- {
- // Do nothing here.
- }
- else if(obj is XmlSchemaElement)
- {
- XmlSchemaElement elem = (XmlSchemaElement) obj;
- elem.parentIsSchema = true;
- int numerr = elem.Compile(handler, this);
- errorCount += numerr;
- if(numerr == 0)
- {
- Elements.Add(elem.QualifiedName,elem);
- }
- }
- else if(obj is XmlSchemaGroup)
- {
- XmlSchemaGroup grp = (XmlSchemaGroup) obj;
- int numerr = grp.Compile(handler, this);
- errorCount += numerr;
- if(numerr == 0)
- {
- Groups.Add(grp.QualifiedName,grp);
- }
- }
- else if(obj is XmlSchemaNotation)
- {
- XmlSchemaNotation ntn = (XmlSchemaNotation) obj;
- int numerr = ntn.Compile(handler, this);
- errorCount += numerr;
- if(numerr == 0)
- {
- Notations.Add(ntn.QualifiedName, ntn);
- }
- }
- else
- {
- ValidationHandler.RaiseValidationError(handler,this,
- "Object of Type "+obj.GetType().Name+" is not valid in Item Property of Schema");
- }
- }
- foreach (XmlSchemaElement element in missingElementTypeRefs.Keys)
- {
- element.SetReferedElementInfo (
- FindElement (missingElementTypeRefs [element] as XmlQualifiedName));
- }
- Validate(handler);
- }
- #endregion
- [MonoTODO]
- private void Validate(ValidationEventHandler handler)
- {
- foreach(XmlSchemaAttribute attr in Attributes.Values)
- {
- attr.Validate(handler, this);
- }
- foreach(XmlSchemaAttributeGroup attrgrp in AttributeGroups.Values)
- {
- attrgrp.Validate(handler);
- }
- foreach(XmlSchemaType type in SchemaTypes.Values)
- {
- if(type is XmlSchemaComplexType)
- {
- ((XmlSchemaComplexType)type).Validate(handler);
- }
- else
- ((XmlSchemaSimpleType)type).Validate(handler, this);
- }
- foreach(XmlSchemaElement elem in Elements.Values)
- {
- elem.Validate(handler);
- }
- foreach(XmlSchemaGroup grp in Groups.Values)
- {
- grp.Validate(handler);
- }
- foreach(XmlSchemaNotation ntn in Notations.Values)
- {
- ntn.Validate(handler);
- }
- }
- internal XmlSchemaElement FindElement (XmlQualifiedName name)
- {
- if (name.Namespace != TargetNamespace)
- return null;
- foreach (XmlSchemaObject obj in Items) {
- XmlSchemaElement elem = obj as XmlSchemaElement;
- if (obj != null && elem.Name == name.Name)
- return elem;
- }
- return null;
- }
- #region Read
- public static XmlSchema Read(TextReader reader, ValidationEventHandler validationEventHandler)
- {
- return Read(new XmlTextReader(reader),validationEventHandler);
- }
- public static XmlSchema Read(Stream stream, ValidationEventHandler validationEventHandler)
- {
- return Read(new XmlTextReader(stream),validationEventHandler);
- }
- [MonoTODO ("Use ValidationEventHandler")]
- public static XmlSchema Read(XmlReader rdr, ValidationEventHandler validationEventHandler)
- {
- XmlSerializer xser = new XmlSerializer (typeof (XmlSchema));
- return (XmlSchema) xser.Deserialize (rdr);
- /*
- XmlSchemaReader reader = new XmlSchemaReader(rdr, validationEventHandler);
- while(reader.ReadNextElement())
- {
- switch(reader.NodeType)
- {
- case XmlNodeType.Element:
- if(reader.LocalName == "schema")
- {
- XmlSchema schema = new XmlSchema();
- schema.LineNumber = reader.LineNumber;
- schema.LinePosition = reader.LinePosition;
- schema.SourceUri = reader.BaseURI;
- ReadAttributes(schema, reader, validationEventHandler);
- //IsEmptyElement does not behave properly if reader is
- //positioned at an attribute.
- reader.MoveToElement();
- if(!reader.IsEmptyElement)
- {
- ReadContent(schema, reader, validationEventHandler);
- }
- return schema;
- }
- else
- {
- //Schema can't be generated. Throw an exception
- throw new XmlSchemaException("The root element must be schema", null);
- }
- default:
- error(validationEventHandler, "This should never happen. XmlSchema.Read 1 ",null);
- break;
- }
- }
- throw new XmlSchemaException("The top level schema must have namespace "+XmlSchema.Namespace, null);
- */
- }
- private static void ReadAttributes(XmlSchema schema, XmlSchemaReader reader, ValidationEventHandler h)
- {
- Exception ex;
- reader.MoveToElement();
- while(reader.MoveToNextAttribute())
- {
- switch(reader.Name)
- {
- case "attributeFormDefault" :
- schema.attributeFormDefault = XmlSchemaUtil.ReadFormAttribute(reader,out ex);
- if(ex != null)
- error(h, reader.Value + " is not a valid value for attributeFormDefault.", ex);
- break;
- case "blockDefault" :
- schema.blockDefault = XmlSchemaUtil.ReadDerivationAttribute(reader,out ex, "blockDefault");
- if(ex != null)
- warn(h, ex.Message, ex);
- break;
- case "elementFormDefault":
- schema.elementFormDefault = XmlSchemaUtil.ReadFormAttribute(reader, out ex);
- if(ex != null)
- error(h, reader.Value + " is not a valid value for elementFormDefault.", ex);
- break;
- case "finalDefault":
- schema.finalDefault = XmlSchemaUtil.ReadDerivationAttribute(reader, out ex, "finalDefault");
- if(ex != null)
- warn(h, ex.Message , ex);
- break;
- case "id":
- schema.id = reader.Value;
- break;
- case "targetNamespace":
- schema.targetNamespace = reader.Value;
- break;
- case "version":
- schema.version = reader.Value;
- break;
- case "xml:lang":
- schema.language = reader.Value;
- break;
- default:
- if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
- error(h, reader.Name + " attribute is not allowed in schema element",null);
- else
- {
- XmlSchemaUtil.ReadUnhandledAttribute(reader,schema);
- }
- break;
- }
- }
- }
- private static void ReadContent(XmlSchema schema, XmlSchemaReader reader, ValidationEventHandler h)
- {
- reader.MoveToElement();
- if(reader.LocalName != "schema" && reader.NamespaceURI != XmlSchema.Namespace && reader.NodeType != XmlNodeType.Element)
- error(h, "UNREACHABLE CODE REACHED: Method: Schema.ReadContent, " + reader.LocalName + ", " + reader.NamespaceURI,null);
- //(include | import | redefine | annotation)*,
- //((simpleType | complexType | group | attributeGroup | element | attribute | notation | annotation)*
- int level = 1;
- while(reader.ReadNextElement())
- {
- if(reader.NodeType == XmlNodeType.EndElement)
- {
- if(reader.LocalName != xmlname)
- error(h,"Should not happen :2: XmlSchema.Read, name="+reader.Name,null);
- break;
- }
- if(level <= 1)
- {
- if(reader.LocalName == "include")
- {
- XmlSchemaInclude include = XmlSchemaInclude.Read(reader,h);
- if(include != null)
- schema.includes.Add(include);
- continue;
- }
- if(reader.LocalName == "import")
- {
- XmlSchemaImport import = XmlSchemaImport.Read(reader,h);
- if(import != null)
- schema.includes.Add(import);
- continue;
- }
- if(reader.LocalName == "redefine")
- {
- XmlSchemaRedefine redefine = XmlSchemaRedefine.Read(reader,h);
- if(redefine != null)
- schema.includes.Add(redefine);
- continue;
- }
- if(reader.LocalName == "annotation")
- {
- XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
- if(annotation != null)
- schema.items.Add(annotation);
- continue;
- }
- }
- if(level <=2)
- {
- level = 2;
- if(reader.LocalName == "simpleType")
- {
- XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader,h);
- if(stype != null)
- schema.items.Add(stype);
- continue;
- }
- if(reader.LocalName == "complexType")
- {
- XmlSchemaComplexType ctype = XmlSchemaComplexType.Read(reader,h);
- if(ctype != null)
- schema.items.Add(ctype);
- continue;
- }
- if(reader.LocalName == "group")
- {
- XmlSchemaGroup group = XmlSchemaGroup.Read(reader,h);
- if(group != null)
- schema.items.Add(group);
- continue;
- }
- if(reader.LocalName == "attributeGroup")
- {
- XmlSchemaAttributeGroup attributeGroup = XmlSchemaAttributeGroup.Read(reader,h);
- if(attributeGroup != null)
- schema.items.Add(attributeGroup);
- continue;
- }
- if(reader.LocalName == "element")
- {
- XmlSchemaElement element = XmlSchemaElement.Read(reader,h);
- if(element != null)
- schema.items.Add(element);
- continue;
- }
- if(reader.LocalName == "attribute")
- {
- XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
- if(attr != null)
- schema.items.Add(attr);
- continue;
- }
- if(reader.LocalName == "notation")
- {
- XmlSchemaNotation notation = XmlSchemaNotation.Read(reader,h);
- if(notation != null)
- schema.items.Add(notation);
- continue;
- }
- if(reader.LocalName == "annotation")
- {
- XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
- if(annotation != null)
- schema.items.Add(annotation);
- continue;
- }
- }
- reader.RaiseInvalidElementError();
- }
- }
- #endregion
- #region write
- public void Write(System.IO.Stream stream)
- {
- Write(stream,null);
- }
- public void Write(System.IO.TextWriter writer)
- {
- Write(writer,null);
- }
- public void Write(System.Xml.XmlWriter writer)
- {
- Write(writer,null);
- }
- public void Write(System.IO.Stream stream, System.Xml.XmlNamespaceManager namespaceManager)
- {
- Write(new XmlTextWriter(stream,null),namespaceManager);
- }
- public void Write(System.IO.TextWriter writer, System.Xml.XmlNamespaceManager namespaceManager)
- {
- XmlTextWriter xwriter = new XmlTextWriter(writer);
- xwriter.Formatting = Formatting.Indented;
- Write(xwriter,namespaceManager);
- }
- public void Write(System.Xml.XmlWriter writer, System.Xml.XmlNamespaceManager namespaceManager)
- {
- if(Namespaces == null)
- {
- Namespaces = new XmlSerializerNamespaces();
- }
- //Add the xml schema namespace.
- if(Namespaces.Count == 0)
- {
- Namespaces.Add("xs", XmlSchema.Namespace);
- if (TargetNamespace != null && TargetNamespace != String.Empty)
- Namespaces.Add("tns", TargetNamespace);
- }
- if(namespaceManager != null)
- {
- foreach(string name in namespaceManager)
- {
- //xml and xmlns namespaced are added by default in namespaceManager.
- //So we should ignore them
- if(name!="xml" && name != "xmlns")
- Namespaces.Add(name,namespaceManager.LookupNamespace(name));
- }
- }
- XmlSerializer xser = new XmlSerializer(typeof(XmlSchema));
- xser.Serialize(writer,this,Namespaces);
- writer.Flush();
- }
- #endregion
- }
- }
|