472,122 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

attribute not declared for validating schema init


Hello,

I get the following error when instanciating an XmlReader that performs validation:

"The 'http://tenbase2.com/DVDTimestamps:schemaLocation' attribute is not declared."

My beginning XML tag starts as follows:

<DVDTimestamps xmlns:tb2="http://tenbase2.com/DVDTimestamps" tb2:schemaLocation="DVDTimestampXmlSchema.xsd">

What am I missing?

Thanks,
William Johnston

Feb 16 '07 #1
5 9364
William Johnston wrote:
I get the following error when instanciating an XmlReader that
performs validation:

"The 'http://tenbase2.com/DVDTimestamps:schemaLocation' attribute is
not declared."

My beginning XML tag starts as follows:

<DVDTimestamps xmlns:tb2="http://tenbase2.com/DVDTimestamps"
tb2:schemaLocation="DVDTimestampXmlSchema.xsd">

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.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 16 '07 #2
"William Johnston" <wi******@tenbase2.comwrote:
>
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

Feb 16 '07 #3
William Johnston wrote:
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.
Please show the exact error message and the relevant code setting up the
validating XmlReader and show the relevant parts of the schema.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 16 '07 #4
"William Johnston" <wi******@tenbase2.comwrote:
>
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
Feb 17 '07 #5
William Johnston wrote:
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.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 18 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Oisin Grehan | last post: by
2 posts views Thread by pstachy | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.