HandCoded.Meta.SchemaRelease.NewInstance C# (CSharp) Method

NewInstance() public method

Creates a new instance the XML grammar represented by this instance using the indicated element name as the root element for the document.
public NewInstance ( string rootElement ) : XmlDocument
rootElement string The name of the root element.
return System.Xml.XmlDocument
        public override XmlDocument NewInstance(string rootElement)
        {
            List<SchemaRelease>	releases	= new List<SchemaRelease> ();
            SchemaRelease		mainSchema	= null;

            FindAllImports (releases);
            foreach (SchemaRelease	release in releases) {
                if (release.HasRootElement (rootElement)) {
                    if (mainSchema != null) {
                        log.Fatal ("Multiple schemas define root element '" + rootElement + "'");
                        return (null);
                    }
                    mainSchema = release;
                }
            }
            if (mainSchema == null) {
                log.Fatal ("No schema recognised '" + rootElement + "' as a root element.");
                return (null);
            }

            XmlDocument		document = new XmlDocument ();
            XmlElement		element  = document.CreateElement (rootElement, namespaceUri);

            element.SetAttribute ("xmlns:xsi", INSTANCE_URL);
            document.AppendChild (element);

            foreach (SchemaRelease	release in releases)
                release.initialiser.Initialise (release, element, release == mainSchema);

            return (document);
        }