> I get the following error when instanciating an XmlReader that
> performs validation:
[quoted text clipped - 8 lines]
>
> What am I missing?
If you want to specify the schema location(s) then that attribute
schemaLocation needs to be in the namespace
http://www.w3.org/2001/XMLSchema-instance and needs to have URL pairs
namespaceURL schemaURL as its value e.g.
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.com/2007/ns1
http://example.com/schema1.xsd"
xmlns="http://example.com/2007/ns1">
If you happen to have your own attribute named schemaLocation then you
need to make sure your schema defines that for the DVDTimestamps element.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Thanks for your reply.
I am still getting the error.
The modified tag is now:
<DVDTimestamps xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tenbase2.com/DVDTimestamps DVDTimestampXmlSchema.xsd"
xmlns="http://tenbase2.com/DVDTimestamps">
I also used a url and full path for schema file name.
Regards,
William Johnston
Martin Honnen - 16 Feb 2007 17:59 GMT
> I am still getting the error.
>
[quoted text clipped - 5 lines]
>
> I also used a url and full path for schema file name.
Please show the exact error message and the relevant code setting up the
validating XmlReader and show the relevant parts of the schema.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Thanks again for your reply.
The init code for the validating XML reader is:
StreamReader stream = new StreamReader(strFilename);
// Create the XmlSchemaSet class.
DVDXmlSchemaSet sc = new DVDXmlSchemaSet(strTargetNamespace, strSchemaFilename);
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.ValidationFlags |= XmlSchemaValidationFlags.None;
settings.Schemas = sc;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
reader = XmlReader.Create(stream, settings);
/// <summary>
/// schema filename
/// </summary>
private static string strTargetNamespace = "urn:DVDTimestamps";
/// <summary>
/// schema filename
/// </summary>
private static string strSchemaFilename = "DVDTimestampXmlSchema.xsd";
The DVDXmlSchemaSet class has a base class of XmlSchemaSet and has a constructor of:
class DVDXmlSchemaSet : MyXmlSchemaSet
{
public DVDXmlSchemaSet(string strTargetNamespace, string strFileName)
: base(strTargetNamespace, strSchemaPath, strFileName)
{
}
/// <summary>
/// field that contains the XML schema path
/// </summary>
public static string strSchemaPath = "G:\\DVD\\MyPrograms output\\xml schemas\\";
}
Finally, the MyXmlSchemaSet constructor is:
public MyXmlSchemaSet(string strTargetNamespace, string strPath, string strFilename) : base()
{
object[] formatParams = new object[2];
formatParams[0] = strPath;
formatParams[1] = strFilename;
string strSchemaFile = string.Format("{0}{1}", formatParams);
Add(strTargetNamespace, strSchemaFile);
}
The exact exception and error message is:
System.Xml.Schema.XmlSchemaValidationException: "The 'http://tenbase2.com/DVDTimestamps:schemaLocation' attribute is not declared."
Regards,
William Johnston
Martin Honnen - 18 Feb 2007 12:50 GMT
> settings.ValidationType = ValidationType.Schema;
> settings.ValidationFlags |= XmlSchemaValidationFlags.None;
> settings.Schemas = sc;
> settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
>
> reader = XmlReader.Create(stream, settings);
> private static string strTargetNamespace = "urn:DVDTimestamps";
So the target namespace you use in your C# code is "urn:DVDTimestamps".
The XML document sample you have shown earlier has
DVDTimestamps xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tenbase2.com/DVDTimestamps
DVDTimestampXmlSchema.xsd"
xmlns="http://tenbase2.com/DVDTimestamps">
so there the elements ae in the namespace
"http://tenbase2.com/DVDTimestamps". That is one issue at least that
does not make sense to me.
> The exact exception and error message is:
>
> System.Xml.Schema.XmlSchemaValidationException: "The 'http://tenbase2.com/DVDTimestamps:schemaLocation' attribute is not declared."
Show the relevant parts of the XML document and the schema, the snippet
above does not have an attribute named schemaLocation in the namespace
http://tenbase2.com/DVDTimestamps.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/