Hallo
Thanks for your Help, but the SourceSchemaObj ect always returns null.
What's wrong here? I wrote a little Testapp for demonstration:
using System;
using System.Xml;
using System.Xml.Sche ma;
using System.Diagnost ics;
namespace ConsoleApplicat ion1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
Class1 c = new Class1();
c.ValidationTes t();
}
public void ValidationTest( )
{
try
{
string schematext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
";
schematext += "<xs:schema
xmlns:xs=\"http ://www.w3.org/2001/XMLSchema\"
elementFormDefa ult=\"qualified \">";
schematext += "<xs:elemen t name=\"document \"> ";
schematext += "<xs:complexTyp e> ";
schematext += "<xs:attrib ute name=\"type\" type=\"xs:strin g\"
use=\"required\ "/>";
schematext += "</xs:complexType> ";
schematext += "</xs:element>";
schematext += "</xs:schema>";
XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(new
NameTable());
XmlParserContex t context = new XmlParserContex t(null, nsmgr, null,
XmlSpace.None);
XmlTextReader tr = new
XmlTextReader(s chematext,XmlNo deType.Document ,context);
XmlSchema schema = XmlSchema.Read( tr,new
ValidationEvent Handler(this.Sc hemaValidationE vent));
schema.Compile( new ValidationEvent Handler(this.Co mpileEvent));
if (schema.IsCompi led)
{
string sXML = "<document type=\"\"></document>";
XmlValidatingRe ader reader = new XmlValidatingRe ader(sXML,
XmlNodeType.Doc ument, context);
reader.Validati onEventHandler += new
ValidationEvent Handler(this.Xm lValidationEven t);
reader.Schemas. Add(schema);
while (reader.Read()) {}
}
}
catch (Exception e)
{
Debug.WriteLine (e.Message + " " + e.StackTrace);
}
}
private void SchemaValidatio nEvent (object sender, ValidationEvent Args
args)
{
Debug.WriteLine ("Schema Validation Error: " + args.Message);
if (args.Exception .SourceSchemaOb ject != null)
{
Debug.WriteLine (args.Exception .SourceSchemaOb ject.SourceUri) ;
}
}
private void CompileEvent (object sender, ValidationEvent Args args)
{
Debug.WriteLine ("Schema Compile Error: " + args.Message);
if (args.Exception .SourceSchemaOb ject != null)
{
Debug.WriteLine (args.Exception .SourceSchemaOb ject.SourceUri) ;
}
}
private void XmlValidationEv ent (object sender, ValidationEvent Args
args)
{
Debug.WriteLine ("XML Validation Error: " + args.Message);
if (args.Exception .SourceSchemaOb ject != null)
{
Debug.WriteLine (args.Exception .SourceSchemaOb ject.SourceUri) ;
}
}
}
}
Thanks for your Help in advance
--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com