Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / February 2007

Tip: Looking for answers? Try searching our database.

attribute not declared for validating schema init

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
William Johnston - 16 Feb 2007 16:18 GMT
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
Martin Honnen - 16 Feb 2007 16:22 GMT
> 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/

William Johnston - 16 Feb 2007 17:50 GMT
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/

William Johnston - 17 Feb 2007 19:11 GMT
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/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.