public MessageTemplate[] Load(XmlElement root)
        {
            var templateParser = new TemplateParser(_loadTemplateIdFromAuxId);
            if (root != null)
            {
                if (root.LocalName.Equals("template"))
                {
                    return new[] {(MessageTemplate) templateParser.Parse(root, _initialContext)};
                }
                if (root.LocalName.Equals("templates"))
                {
                    var context = new ParsingContext(root, _initialContext);

                    XmlNodeList templateTags = root.GetElementsByTagName("template");
                    var templates = new MessageTemplate[templateTags.Count];
                    for (int i = 0; i < templateTags.Count; i++)
                    {
                        var templateTag = (XmlElement) templateTags.Item(i);
                        templates[i] = (MessageTemplate) templateParser.Parse(templateTag, context);
                    }
                    return templates;
                }
                _initialContext.ErrorHandler.OnError(
                    null, StaticError.InvalidXml, "Invalid root node {0}, 'template' or 'templates' expected.",
                    root.LocalName);
            }
            return new MessageTemplate[] {};
        }
        public MessageTemplate[] Load(System.IO.Stream source)
        {
            System.Xml.XmlDocument document = ParseXml(source);

            if (document == null)
            {
                return new MessageTemplate[]{};
            }

            var root = document.DocumentElement;

            var templateParser = new TemplateParser(loadTemplateIdFromAuxId);
            if (root != null)
            {
                if (root.Name.Equals("template"))
                {
                    return new[] {(MessageTemplate) templateParser.Parse(root, initialContext)};
                }
                if (root.Name.Equals("templates"))
                {
                    var context = new ParsingContext(root, initialContext);

                    System.Xml.XmlNodeList templateTags = root.GetElementsByTagName("template");
                    var templates = new MessageTemplate[templateTags.Count];
                    for (int i = 0; i < templateTags.Count; i++)
                    {
                        var templateTag = (System.Xml.XmlElement) templateTags.Item(i);
                        templates[i] = (MessageTemplate) templateParser.Parse(templateTag, context);
                    }
                    return templates;
                }
                initialContext.ErrorHandler.Error(Error.FastConstants.S1_INVALID_XML,
                                                  "Invalid root node " + root.Name +
                                                  ", \"template\" or \"templates\" expected.");

            }
            return new MessageTemplate[] { };
        }