ParseXSD.cs
using System;
using System.Collections;
using System.Xml;
using System.Xml.Schema;
class XmlSchemaTraverseExample
{
static void Main()
{
// Add the customer schema to a new XmlSchemaSet and compile it.
// Any schema validation warnings and errors encountered reading or
// compiling the schema are handled by the ValidationEventHandler delegate.
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
schemaSet.Add("http://www.w3.org/2001/XMLSchema", "tmp.xsd");
schemaSet.Compile();
// Retrieve the compiled XmlSchema object from the XmlSchemaSet
// by iterating over the Schemas property.
XmlSchema customerSchema = null;
foreach (XmlSchema schema in schemaSet.Schemas())
{
customerSchema = schema;
}
// inserted more code here....
}
}
Currently, my ConsoleApp worked very well.
And i want to remove the hard code (xsd file path) out from my code below.
// i don't know how to update this line.
schemaSet.Add("http://www.w3.org/2001/XMLSchema", "tmp.xsd");
Then i could run my ParseXSD.cs file at the building time with the CSC command below.
// i don't know the correct command format. I could update the path parameter easily. NO hard code.
CSC ParseXSD.cs d:/tmp/tmp.xsd
Please give me some guide. thanks in advance.
Do you want to specify it at compile time or at run time?
to do it at runtime change
static void Main()
to
static void Main(string[] args)
and then
schemaSet.Add("http://www.w3.org/2001/XMLSchema", args[0]);
If you want to specify it at compile time you might be able to use precompile directives to do it, but I am not sure if they can be specified for csc. Your other option is to do the injection before compile with commandline scripts or similar.