示例#1
0
        public XSLTValidator(string languageName, XsltArgumentList xsltArgumentList)
        {
            if(null == xsltArgumentList)
                throw new ArgumentNullException("xsltArgumentList");
            _xslArg = xsltArgumentList;
            _xslt = new XslCompiledTransform();

            var assembly = this.GetType().Assembly;
            var resolver = new XmlPreloadedResolver();

            string mainXSLT = null;
            string[] resourceNames = this.GetType().Assembly.GetManifestResourceNames();
            foreach(string resourceName in resourceNames)
            {
                if(resourceName.EndsWith(".xslt") && resourceName.Contains(languageName))
                {
                    string templateName = resourceName.Substring(resourceName.LastIndexOf(languageName) + languageName.Length);
                    if(templateName == ".xslt")
                    {
                        mainXSLT = resourceName;
                    }
                    else
                    {
                        using (var stream = assembly.GetManifestResourceStream(resourceName))
                        {
                            resolver.Add(resolver.ResolveUri(null, templateName), stream);
                        }
                    }
                }
            }
            using (var stream = assembly.GetManifestResourceStream(mainXSLT))
                using (var reader = XmlReader.Create(stream))
            {
                _xslt.Load(reader, null, resolver);
            }
        }
        /// <summary>
        /// Validate the OSTC certificate request document
        /// </summary>
        /// <param name="order">the OSTC certificate request document</param>
        public void Validate(byte[] order)
        {
            var resolver = new XmlPreloadedResolver();

            var ostcUri = "http://localhost/OSTC.xsd";
            var asm = typeof(OstcAntragValidator).Assembly;
            using (var stream = asm.GetManifestResourceStream(typeof(OstcAntragValidator), "Schemas.OSTC.xsd"))
            {
                resolver.Add(new Uri(ostcUri, UriKind.RelativeOrAbsolute), stream);
            }

            var settings = new XmlReaderSettings
            {
                ValidationType = ValidationType.Schema,
                ValidationFlags = XmlSchemaValidationFlags.ProcessSchemaLocation,
                XmlResolver = resolver,
            };

            var input = FixDocument(order, ostcUri);
            var reader = XmlReader.Create(input, settings);
            while (reader.Read())
            {
            }
        }