当前位置: 首页>>代码示例>>C#>>正文


C# Schema.XmlSchemaCollection类代码示例

本文整理汇总了C#中System.Xml.Schema.XmlSchemaCollection的典型用法代码示例。如果您正苦于以下问题:C# XmlSchemaCollection类的具体用法?C# XmlSchemaCollection怎么用?C# XmlSchemaCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XmlSchemaCollection类属于System.Xml.Schema命名空间,在下文中一共展示了XmlSchemaCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestAdd

		public void TestAdd ()
		{
			XmlSchemaCollection col = new XmlSchemaCollection ();
			XmlSchema schema = new XmlSchema ();
			XmlSchemaElement elem = new XmlSchemaElement ();
			elem.Name = "foo";
			schema.Items.Add (elem);
			schema.TargetNamespace = "urn:foo";
			col.Add (schema);
			col.Add (schema);	// No problem !?

			XmlSchema schema2 = new XmlSchema ();
			schema2.Items.Add (elem);
			schema2.TargetNamespace = "urn:foo";
			col.Add (schema2);	// No problem !!

			schema.Compile (null);
			col.Add (schema);
			col.Add (schema);	// Still no problem !!!

			schema2.Compile (null);
			col.Add (schema2);

			schema = GetSchema ("Test/XmlFiles/xsd/3.xsd");
			schema.Compile (null);
			col.Add (schema);

			schema2 = GetSchema ("Test/XmlFiles/xsd/3.xsd");
			schema2.Compile (null);
			col.Add (schema2);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:31,代码来源:XmlSchemaCollectionTests.cs

示例2: Execute

        public bool Execute(XmlSchema schema, string targetNamespace, bool loadExternals, XmlSchemaCollection xsc) {
            this.schema = schema;
            Xmlns = NameTable.Add("xmlns");

            Cleanup(schema);
            if (loadExternals && xmlResolver != null) {
                schemaLocations = new Hashtable(); //new Dictionary<Uri, Uri>();
                if (schema.BaseUri != null) {
                    schemaLocations.Add(schema.BaseUri, schema.BaseUri);
                }
                LoadExternals(schema, xsc);
            }
            ValidateIdAttribute(schema);
            Preprocess(schema, targetNamespace, Compositor.Root);
            if (!HasErrors) {
                schema.IsPreprocessed = true;
                for (int i = 0; i < schema.Includes.Count; ++i) {
                    XmlSchemaExternal include = (XmlSchemaExternal)schema.Includes[i];
                    if (include.Schema != null) {
                        include.Schema.IsPreprocessed = true;
                    }
                }
            }
            return !HasErrors;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:25,代码来源:SchemaCollectionpreProcessor.cs

示例3: consultaNFe

        private string consultaNFe()
        {
            XmlSchemaCollection myschema = new XmlSchemaCollection();
            string sxdoc = "";
            XNamespace pf = "http://www.portalfiscal.inf.br/nfe";

            try
            {
                XDocument xdoc = new XDocument(new XElement(pf + "consSitNFe", new XAttribute("versao", sversaoLayoutCons),//sversaoLayoutCons),
                                                  new XElement(pf + "tpAmb", Acesso.TP_AMB.ToString()),
                                                   new XElement(pf + "xServ", "CONSULTAR"),
                                                   new XElement(pf + "chNFe", objPesquisa.sCHAVENFE)));

                string sCaminhoConsulta = Pastas.PROTOCOLOS + "Consulta_" + objPesquisa.sCHAVENFE + ".xml";
                if (File.Exists(sCaminhoConsulta))
                {
                    File.Delete(sCaminhoConsulta);
                }
                StreamWriter writer = new StreamWriter(sCaminhoConsulta);
                writer.Write(xdoc.ToString());
                writer.Close();
                //belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/nfe", Pastas.SCHEMA_NFE + "\\2.01\\consSitNFe_v2.01.xsd", sCaminhoConsulta);
                sxdoc = xdoc.ToString();

            }
            catch (XmlException x)
            {
                throw new Exception(x.Message.ToString());
            }
            catch (XmlSchemaException x)
            {
                throw new Exception(x.Message.ToString());
            }
            return sxdoc;
        }
开发者ID:dramosti,项目名称:GeraXml_3.0,代码行数:35,代码来源:belConsultaStatusNota.cs

示例4: ValidaSchema

        /// <summary>
        ///     Valida se um Xml está seguindo de acordo um Schema
        /// </summary>
        /// <param name="arquivoXml">Arquivo Xml</param>
        /// <param name="arquivoSchema">Arquivo de Schema</param>
        /// <returns>True se estiver certo, Erro se estiver errado</returns>
        public void ValidaSchema(String arquivoXml, String arquivoSchema)
        {
            //Seleciona o arquivo de schema de acordo com o schema informado
            //arquivoSchema = Bll.Util.ContentFolderSchemaValidacao + "\\" + arquivoSchema;

            //Verifica se o arquivo de XML foi encontrado.
            if (!File.Exists(arquivoXml))
                throw new Exception("Arquivo de XML informado: \"" + arquivoXml + "\" não encontrado.");

            //Verifica se o arquivo de schema foi encontrado.
            if (!File.Exists(arquivoSchema))
                throw new Exception("Arquivo de schema: \"" + arquivoSchema + "\" não encontrado.");

            // Cria um novo XMLValidatingReader
            var reader = new XmlValidatingReader(new XmlTextReader(new StreamReader(arquivoXml)));
            // Cria um schemacollection
            var schemaCollection = new XmlSchemaCollection();
            //Adiciona o XSD e o namespace
            schemaCollection.Add("http://www.portalfiscal.inf.br/nfe", arquivoSchema);
            // Adiciona o schema ao ValidatingReader
            reader.Schemas.Add(schemaCollection);
            //Evento que retorna a mensagem de validacao
            reader.ValidationEventHandler += Reader_ValidationEventHandler;
            //Percorre o XML
            while (reader.Read())
            {
            }
            reader.Close(); //Fecha o arquivo.
            //O Resultado é preenchido no reader_ValidationEventHandler

            if (validarResultado != "")
            {
                throw new Exception(validarResultado);
            }
        }
开发者ID:njmube,项目名称:NFeEletronica.NET,代码行数:41,代码来源:Xml.cs

示例5: clsSValidator

 public clsSValidator(string sXMLFileName, string sSchemaFileName)
 {
     m_sXMLFileName = sXMLFileName;
     m_sSchemaFileName = sSchemaFileName;
     m_objXmlSchemaCollection = new XmlSchemaCollection ();
     //adding the schema file to the newly created schema collection
     m_objXmlSchemaCollection.Add (null, m_sSchemaFileName);
 }
开发者ID:jeremyhallpdx,项目名称:pdxwrex,代码行数:8,代码来源:clsSValidator.cs

示例6: TestAddDoesCompilation

		public void TestAddDoesCompilation ()
		{
			XmlSchema schema = new XmlSchema ();
			Assert (!schema.IsCompiled);
			XmlSchemaCollection col = new XmlSchemaCollection ();
			col.Add (schema);
			Assert (schema.IsCompiled);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:8,代码来源:XmlSchemaCollectionTests.cs

示例7: ParseString

        public NSTScorePartwise ParseString(string dataString)
        {
            //todo: parse string
            IList<NSTPart> partList = new List<NSTPart>();
            XmlTextReader textReader = new XmlTextReader(new FileStream("C:\\NM\\ScoreTranscription\\NETScoreTranscription\\NETScoreTranscriptionLibrary\\OtherDocs\\musicXML.xsd", System.IO.FileMode.Open)); //todo: pass stream in instead of absolute location for unit testing
            XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
            schemaCollection.Add(null, textReader);

            NSTScorePartwise score;

            using (XmlValidatingReader reader = new XmlValidatingReader(XmlReader.Create(new StringReader(dataString), new XmlReaderSettings() { DtdProcessing = DtdProcessing.Parse }))) //todo: make unobsolete
            {
                reader.Schemas.Add(schemaCollection);
                reader.ValidationType = ValidationType.Schema;
                reader.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(ValidationEventHandler);

                XmlSerializer serializer = new XmlSerializer(typeof(NSTScorePartwise), new XmlRootAttribute("score-partwise"));
                score = (NSTScorePartwise)serializer.Deserialize(reader);

                /*
                while (reader.Read())
                {
                    if (reader.IsEmptyElement)
                        throw new Exception(reader.Value); //todo: test

                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            switch (reader.Name.ToLower())
                            {
                                case "part-list":
                                    break;
                                case "score-partwise":
                                    break;
                                case "part-name":
                                    throw new Exception("pn");
                                    break;
                            }
                            break;
                        case XmlNodeType.Text:

                            break;
                        case XmlNodeType.XmlDeclaration:
                        case XmlNodeType.ProcessingInstruction:

                            break;
                        case XmlNodeType.Comment:

                            break;
                        case XmlNodeType.EndElement:

                            break;
                    }
                }*/
            }

            return score;
        }
开发者ID:NathanMagnus,项目名称:NETScoreTranscription,代码行数:58,代码来源:XMLParser.cs

示例8: XmlSchemaCompiler

        /// <summary>
        /// Instantiate a new XmlSchemaCompiler class.
        /// </summary>
        /// <param name="outputDir">The output directory for all compiled files.</param>
        /// <param name="versionNumber">The version number to append to Elements.</param>
        public XmlSchemaCompiler(string outputDir, string versionNumber)
        {
            this.outputDir = outputDir;
            this.versionNumber = versionNumber;

            this.elements = new Hashtable();
            this.schemaFiles = new StringCollection();
            this.schemas = new XmlSchemaCollection();
        }
开发者ID:sillsdev,项目名称:FwSupportTools,代码行数:14,代码来源:XmlSchemaCompiler.cs

示例9: XmlSchemaCompiler

        /// <summary>
        /// Instantiate a new XmlSchemaCompiler class.
        /// </summary>
        /// <param name="outputDir">The output directory for all compiled files.</param>
        public XmlSchemaCompiler(string outputDir)
        {
            this.mainSchemas = new XmlSchemaCollection();
            this.outputDir = outputDir;

            this.elements = new Hashtable();
            this.attributes = new Hashtable();
            this.schemas = new XmlSchemaCollection();
        }
开发者ID:Jeremiahf,项目名称:wix3,代码行数:13,代码来源:XmlSchemaCompiler.cs

示例10: BaseValidator

 public BaseValidator(XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling) {
     Debug.Assert(schemaCollection == null || schemaCollection.NameTable == reader.NameTable);
     this.reader = reader;
     this.schemaCollection = schemaCollection;
     this.eventHandling = eventHandling;
     nameTable = reader.NameTable;
     positionInfo = PositionInfo.GetPositionInfo(reader);
     elementName = new XmlQualifiedName();
 }
开发者ID:uQr,项目名称:referencesource,代码行数:9,代码来源:BaseValidator.cs

示例11: BaseValidator

 public BaseValidator(XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling)
 {
     this.reader = reader;
     this.schemaCollection = schemaCollection;
     this.eventHandling = eventHandling;
     this.nameTable = reader.NameTable;
     this.positionInfo = System.Xml.PositionInfo.GetPositionInfo(reader);
     this.elementName = new XmlQualifiedName();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:9,代码来源:BaseValidator.cs

示例12: Main

        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("Invalid parameter count. Exiting...");
                return;
            }

            string xmlFile = args[0];
            string xdsFile = args[1];
            string xdsNamespace = args[2];
            string outputFile = args[3];

            try
            {
                XmlSchemaCollection cache = new XmlSchemaCollection();
                cache.Add(xdsNamespace, xdsFile);

                XmlTextReader r = new XmlTextReader(xmlFile);
                XmlValidatingReader v = new XmlValidatingReader(r);
                v.Schemas.Add(cache);

                v.ValidationType = ValidationType.Schema;

                v.ValidationEventHandler +=
                    new ValidationEventHandler(MyValidationEventHandler);

                while (v.Read()) { } // look for validation errors
                v.Close();
            }
            catch (Exception e)
            {
                encounteredFatalError = true;
                fatalError = e;
            }

            StreamWriter file = new StreamWriter(outputFile);

            if (isValid && !encounteredFatalError)
                file.WriteLine("PASSED: Document is valid");
            else
                file.WriteLine("FAILED: Document is invalid");

            // Printing
            foreach (string entry in list)
            {
                file.WriteLine(entry);
            }
            if (encounteredFatalError)
            {
                file.WriteLine("Error: a FATAL error has occured " +
                        "while reading the file.\r\n" + fatalError.ToString());
            }
            file.Close();
        }
开发者ID:GerhardMaier,项目名称:COLLADA-CTS,代码行数:55,代码来源:SchemaValidate.cs

示例13: CreateValidatingReader

		/// <summary>
		/// Gets an appropriate <see cref="System.Xml.XmlReader"/> implementation
		/// for the supplied <see cref="System.IO.Stream"/>.
		/// </summary>
		/// <param name="stream">The XML <see cref="System.IO.Stream"/> that is going to be read.</param>
		/// <param name="xmlResolver"><see cref="XmlResolver"/> to be used for resolving external references</param>
		/// <param name="schemas">XML schemas that should be used for validation.</param>
		/// <param name="eventHandler">Validation event handler.</param>
		/// <returns>
		/// A validating <see cref="System.Xml.XmlReader"/> implementation.
		/// </returns>
		public static XmlReader CreateValidatingReader(Stream stream, XmlResolver xmlResolver, XmlSchemaCollection schemas, ValidationEventHandler eventHandler)
		{
			XmlValidatingReader reader = new XmlValidatingReader(new XmlTextReader(stream));
			reader.XmlResolver = xmlResolver;
			reader.Schemas.Add(schemas);
			reader.ValidationType = ValidationType.Schema;
			if (eventHandler != null)
			{
				reader.ValidationEventHandler += eventHandler;
			}
			return reader;
		}
开发者ID:fuadm,项目名称:spring-net,代码行数:23,代码来源:XmlUtils.cs

示例14: Page_Load

        private void Page_Load(object sender, System.EventArgs e)
        {
            XmlValidatingReader reader = null;
            XmlSchemaCollection myschema = new XmlSchemaCollection();
            ValidationEventHandler eventHandler = new ValidationEventHandler(ShowCompileErrors );
            try
            {

                String xmlFrag = @"<?xml version='1.0' ?>
                                                <item>
                                                <xxx:price xmlns:xxx='xxx' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
                                                xsi:schemaLocation='test.xsd'></xxx:price>
                                                </item>";
                    /*"<author xmlns='urn:bookstore-schema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
                                            "<first-name>Herman</first-name>" +
                                            "<last-name>Melville</last-name>" +
                                            "</author>";*/
                string xsd = @"<?xml version='1.0' encoding='UTF-8'?>
            <xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema' targetNamespace='xxx'>
            <xsd:element name='price' type='xsd:integer' xsd:default='12'/>
            </xsd:schema>";

                //Create the XmlParserContext.
                XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);
                //Implement the reader.
                reader = new XmlValidatingReader(xmlFrag, XmlNodeType.Element, context);
                //Add the schema.
                myschema.Add("xxx", new XmlTextReader(new StringReader(xsd)));

                //Set the schema type and add the schema to the reader.
                reader.ValidationType = ValidationType.Schema;
                reader.Schemas.Add(myschema);
                while (reader.Read()){Response.Write(reader.Value);}
                Response.Write("<br>Completed validating xmlfragment<br>");
            }
            catch (XmlException XmlExp)
            {
                Response.Write(XmlExp.Message + "<br>");
            }

            catch(XmlSchemaException XmlSchExp)
            {
                Response.Write(XmlSchExp.Message + "<br>");
            }
            catch(Exception GenExp)
            {
                Response.Write(GenExp.Message + "<br>");
            }
            finally
            {}
            XmlDocument doc;
        }
开发者ID:rags,项目名称:playground,代码行数:52,代码来源:frmValidatingReader.aspx.cs

示例15: v2

        //[Variation(Desc = "v2 - Contains with not added schema")]
        public void v2()
        {
            XmlSchemaSet sc = new XmlSchemaSet();
#pragma warning disable 0618
            XmlSchemaCollection scl = new XmlSchemaCollection();
#pragma warning restore 0618

            XmlSchema Schema = scl.Add(null, TestData._XsdAuthor);

            Assert.Equal(sc.Contains(Schema), false);

            return;
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:14,代码来源:TC_SchemaSet_Contains_schema.cs


注:本文中的System.Xml.Schema.XmlSchemaCollection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。