468,309 Members | 1,075 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,309 developers. It's quick & easy.

ProcessSchemaLocation Validation schemaLocation "Not Working"

After two days I am at wits end, but I am too OCD'ed to give up.
Please tell me what I have got wrong because no Validation Error is
being thrown.

The element: "<datestamp>I should fail</datestamp>"
does not conform to schema. Adding the schema to the
XmlReaderSettings->Schemas field at runtime does result in error being
thrown. As I read it, this step should not be neccessary as the
ProcessSchemaLocation flag should automatically pick up the referenced
schemas in the XML file.

Note: the XML file is actually a node that will be inserted to an
existing XML file.

Below is XML file:

(
"<provenance xmlns=\"http://www.openarchives.org/OAI/
2.0/provenance\"" + "\n" +
"\t" + "xmlns:xsi=\"http://www.w3.org/2001/
XMLSchema-instance\"" + "\n" +
"\t" + "xsi:schemaLocation=\"http://
www.openarchives.org/OAI/2.0/provenance" + "\n" +
"\t" + "http://www.openarchives.org/OAI/2.0/
provenance.xsd\">" + "\n" +
"\t" + "<originDescription harvestDate=
\"2002-02-02T14:10:02Z\" altered=\"true\">" + "\n" +
"\t" + "<baseURL>http://the.oa.org</baseURL>" +
"\n" +
"\t" + "<identifier>oai:r2.org:klik001</
identifier>" + "\n" +
"\t" + "<datestamp>I should fail</datestamp>" +
"\n" +
"\t" + "<metadataNamespace>http://
www.openarchives.org/OAI/2.0/oai_dc/</metadataNamespace>" + "\n" +
"\t" + "\t" + "<originDescription harvestDate=
\"2002-01-01T11:10:01Z\" altered=\"false\">" + "\n" +
"\t" + "\t" + "\t" + "<baseURL>http://some.oa.org</
baseURL>" + "\n" +
"\t" + "\t" + "\t" +
"<identifier>oai:r2.org:klik001</identifier>" + "\n" +
"\t" + "\t" + "\t" + "<datestamp>2001-01-01</
datestamp>" + "\n" +
"\t" + "\t" + "\t" + "<metadataNamespace>http://
www.openarchives.org/OAI/2.0/oai_dc/</metadataNamespace>" + "\n" +
"\t" + "\t" + "</originDescription>" + "\n" +
"\t" + "</originDescription>" + "\n" +
"\t" + "</provenance>");

Here is XML validation class:

public class XmlValidator
{

public static bool isValid;

public static void Validate(String inFile)
{
XmlReader reader = null;
XmlReaderSettings settings = new XmlReaderSettings();

settings.ValidationType = ValidationType.Schema;
settings.ValidationEventHandler += new
ValidationEventHandler(validationEventHandler);

settings.ValidationFlags &=
XmlSchemaValidationFlags.ProcessSchemaLocation;
//settings.ValidationFlags &=
XmlSchemaValidationFlags.ProcessInlineSchema;
settings.ValidationFlags &=
XmlSchemaValidationFlags.ReportValidationWarnings;

System.IO.StringReader strReader = new
System.IO.StringReader(inFile);
reader = XmlReader.Create(strReader, settings);

isValid = true;

while (reader.Read())
{
}

}

static void validationEventHandler(object sender,
ValidationEventArgs args)
{
isValid = false;
}
}

Thanks in advance for granting peace to my mind.

Jim

Jul 10 '07 #1
1 3371
Well I get what I deserve for blindly copying code.

The offending lines were:

settings.ValidationFlags &=
XmlSchemaValidationFlags.ProcessSchemaLocation;
settings.ValidationFlags &=
XmlSchemaValidationFlags.ProcessInlineSchema;
settings.ValidationFlags &=
XmlSchemaValidationFlags.ReportValidationWarnings;

The fix was to replace those lines with:

settings.ValidationFlags |=
XmlSchemaValidationFlags.ProcessSchemaLocation
|
XmlSchemaValidationFlags.ProcessInlineSchema
|
XmlSchemaValidationFlags.ReportValidationWarnings;

Anyone with experience with compound assignment operators want to
explain?

Jul 10 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Vik Rubenfeld | last post: by
2 posts views Thread by Gary | last post: by
reply views Thread by tom777 | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.