Beispiel #1
0
Datei: test.cs Projekt: mono/gert
	static XmlReader CreateValidatingReader (Stream stream, XmlSchemaCollection schemas, ValidationEventHandler eventHandler)
	{
		XmlValidatingReader reader = new XmlValidatingReader (new XmlTextReader (stream));
		reader.Schemas.Add (schemas);
		reader.ValidationType = ValidationType.Schema;
		if (eventHandler != null)
			reader.ValidationEventHandler += eventHandler;
		return reader;
	}
Beispiel #2
0
Datei: test.cs Projekt: mono/gert
	static void Main ()
	{
		string dir = AppDomain.CurrentDomain.BaseDirectory;

		using (Stream input = File.OpenRead (Path.Combine (dir, "test.xml"))) {
#if NET_2_0
			XmlSchemaSet schemas = new XmlSchemaSet ();
#else
			XmlSchemaCollection schemas = new XmlSchemaCollection ();
#endif
			schemas.Add (XmlSchema.Read (File.OpenRead (Path.Combine (dir, "spring-objects.xsd")), null));

			XmlReader reader = CreateValidatingReader (input, schemas, null);
			XmlDocument doc = new XmlDocument ();
			doc.Load (reader);
		}
	}
Beispiel #3
0
	protected void cmdValidate_Click(object sender, EventArgs e)
	{
		string filePath = "";
		if (optValid.Checked)
		{
			filePath = Server.MapPath("DvdList.xml");
		}
		else if (optInvalidData.Checked)
		{
			filePath += Server.MapPath("DvdListInvalid.xml");
		}

		lblStatus.Text = "";

		// Open the XML file.
		FileStream fs = new FileStream(filePath, FileMode.Open);
		XmlTextReader r = new XmlTextReader(fs);

		// Create the validating reader.
		XmlValidatingReader vr = new XmlValidatingReader(r);
		vr.ValidationType = ValidationType.Schema;

		// Add the XSD file to the validator.
		XmlSchemaCollection schemas = new XmlSchemaCollection();
		schemas.Add("", Server.MapPath("DvdList.xsd"));
		vr.Schemas.Add(schemas);

		// Connect the event handler.
		vr.ValidationEventHandler += new ValidationEventHandler(MyValidateHandler);

		// Read through the document.
		while (vr.Read())
		{
			// Process document here.
			// If an error is found, an exception will be thrown.
		}

		vr.Close();

		lblStatus.Text += "<br>Complete.";
	}
Beispiel #4
0
#pragma warning disable 618
        internal bool CompileSchema(XmlSchemaCollection xsc, XmlResolver resolver, SchemaInfo schemaInfo, string ns, ValidationEventHandler validationEventHandler, XmlNameTable nameTable, bool CompileContentModel) {

            //Need to lock here to prevent multi-threading problems when same schema is added to set and compiled
            lock (this) {
                //Preprocessing
                SchemaCollectionPreprocessor prep = new SchemaCollectionPreprocessor(nameTable, null, validationEventHandler);
                prep.XmlResolver = resolver;
                if (!prep.Execute(this, ns, true, xsc)) {
                    return false;
                }
            
                //Compilation
                SchemaCollectionCompiler compiler = new SchemaCollectionCompiler(nameTable, validationEventHandler);
                isCompiled = compiler.Execute(this, schemaInfo, CompileContentModel);
                this.SetIsCompiled(isCompiled);
                //
                return isCompiled;
            }
        }
Beispiel #5
0
    /// <summary>
    /// Main entry point for sample application.
    /// </summary>
    /// <param name="args"></param>
    public static void Main(string[] args)
    {
      XmlSchema myXmlSchema;
      XmlTextWriter myXmlTextWriter;
      try
      {
        Console.WriteLine ("Creating Schema in the Schema Object Model...");

        // Setup console output.
        myXmlTextWriter = new XmlTextWriter(Console.Out);
        myXmlTextWriter.Formatting = Formatting.Indented;
        myXmlTextWriter.Indentation = 2;

        //Create an XmlNameTable.
        XmlNameTable myXmlNameTable = new NameTable();

        //Add the nametable to the XmlSchemaCollection.
        XmlSchemaCollection myXmlSchemaCollection = new XmlSchemaCollection(myXmlNameTable);

        //Add some schemas to the XmlSchemaCollection.
        Console.WriteLine ("Reading and adding {0} schema.", BOOKSCHEMA);
        myXmlSchemaCollection.Add(null, BOOKSCHEMA);
        Console.WriteLine ("Reading and adding {0} schema.", POSCHEMA);
        myXmlSchemaCollection.Add(null, POSCHEMA);
        Console.WriteLine ("Added schemas successfully ...");

        Console.WriteLine ("Showing added schemas");

        foreach(XmlSchema myTempXmlSchema in myXmlSchemaCollection)
        {
          myXmlSchema = myTempXmlSchema;
          Console.WriteLine();
          string outfile = myTempXmlSchema.SourceUri.Replace("file:///", "");

          Console.WriteLine("Schema from: {0}", outfile);
          Console.WriteLine();
          Console.WriteLine("=== Start of Schema ===");
          Console.WriteLine();

          // Write out the various schema parts
          WriteXSDSchema(myXmlSchema, myXmlTextWriter);

          Console.WriteLine();
          Console.WriteLine();
          Console.WriteLine("=== End of Schema ===");
          Console.WriteLine();
          Console.WriteLine("Example of possible XML contents for: {0}", outfile);
          Console.WriteLine();
          Console.WriteLine("=== Start of Example ===");

          // Write out an example of the XML for the schema
          WriteExample(myXmlSchema, myXmlTextWriter);

          Console.WriteLine();
          Console.WriteLine();
          Console.WriteLine("=== End of Example ===");
        } //foreach
      } //try
      catch (Exception e)
      {
        Console.WriteLine ("Exception: {0}", e.ToString());
      } //catch
    } //Main()
 public void Add(XmlSchemaCollection schema)
 {
 }
        public void Create()
        {
            if (!this.ServiceBroker.MessageTypes.Contains(this.FullName))
            {
                // Create message types
                MessageType msgType = new MessageType(
                    this.ServiceBroker, this.FullName);

                msgType.MessageTypeValidation = this.MessageTypeValidation;

                if (msgType.MessageTypeValidation == MessageTypeValidation.XmlSchemaCollection)
                {
                    if(!this.ServiceBroker.Parent.XmlSchemaCollections.Contains
                        (this.ValidationXmlSchemaCollection) && ! String.IsNullOrEmpty(this.ValidationXmlSchemaCollectionSchema))
                    {
                        XmlSchemaCollection schema = new XmlSchemaCollection
                            (this.ServiceBroker.Parent, this.ValidationXmlSchemaCollection);
                        schema.Text = this.ValidationXmlSchemaCollectionSchema;
                        schema.Create();
                    }

                    msgType.ValidationXmlSchemaCollection = this.ValidationXmlSchemaCollection;
                }
                msgType.Create();
            }
        }