473,386 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 9482
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Duncan Smith | last post by:
Hello All, Has anyone found a way to specify an xsd schema programatically when using the apache xerces xml processor? I know that the validation works fine as long as the xml instance document...
12
by: Stefano | last post by:
Hi all, what is the correct use of the "default" attribute in XML Schema? For example: <xs:element name="myProperty" type="xs:string" default="myDefaultValue"/> What can I do with it? What...
1
by: Brad Wood | last post by:
Using 2.0, but I think this applies to 1.1. Given an XmlSchemaElement object (retrieved from an XmlSchema object), how do I get to it's attributes? I tried this against a document that has...
4
by: bibsoconner | last post by:
Hi, I hope someone can please help me. I'm having a lot of trouble with schema files in .NET. I have produced a very simple example that uses "include" to include other schema files. It all...
7
by: Oisin Grehan | last post by:
Hi, I have a UserControl derived class: <ns:votingbutton runat="server" id="btn1" onclick="votingbuttonclick" /> My question is, what code do I need in place in the codebehind for this to...
2
by: smachin1000 | last post by:
Hi All, In the sample schema & document below, I'd like the attribute "name" to be unique for all function elements under function_list. The tools I'm using (XML Spy and xmllint) all validate...
2
by: Mark | last post by:
Hi... I've been trying the .Validate() method on the XmlDocument to validate some xml against a schema, but one thing I noted was that unless the document explicitly declares the schema as a...
2
by: pstachy | last post by:
Hi all, I've got this problem declaring attribute for the element. W3C Validator doesn't find this ok. I really dont know how to declare the attribute for the tag which has simle content(doesn't...
3
by: jh3an | last post by:
Please give me your advice! I made two files according to xml book, but when validating these two files, it gives me an error that I totally don't understand. Is there a problem in these...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.