Mega Search
23.2 Million


Sign Up

Make a donation  
newbie: Visual Studio could not locate a schema for this doc  
News Group: microsoft.public.dotnet.xml

Hi

IDE: VS 2003 .Net
OS: XP Pro + MSXML 4

I'm experimented with xml in .net for the porpose of learning it...

Below I have two questions:
***********************************************************
Question 1:
When I in visual studio choose to validate my xml file I get this message:
C:\MyProjects\Visual Studio
Projects\ReadXml\lesson_getelementbyid\country.xml(1): Visual Studio could
not locate a schema for this document. Validation can only ensure this is a
well formed XML document and cannot validate the data against a schema.


Here is my xml file (country.xml):


    
        Norway
        Oslo
    
    
        France
        Paris
    


Here is my xsd file (country.xsd):


    
        
            
                
                    
                        
                            
                            
                        
                    
                    
                
            
        
    



I have tryed to set schemaLocation="testing country.xsd". But Visual Studio
still gives the same error message!

But when I test the xml file in XmlSpy (with schemaLocation="testing
country.xsd"), it seems to find the .xsd file. but then I get an error
message saying this:
"This file is not valid:"
"Invalid value for datatype ID attribute Countryid"... This don't need to
mean that xmlspy did find the .xsd file...

******************************************************************

Question 2:
I use this code to set the attribute Countryid of the node Country: (C#)
XmlNode parent = xmldoc.DocumentElement;
XmlAttributeCollection attrcol = book.Attributes;
XmlAttribute newAttr = xmldoc.CreateAttribute("Countryid");
newAttr.Value = "5";       //yes hardcoded, but this is just for
experimenting
attrcol.Append(newAttr);
parent.InsertAfter(book, parent.LastChild);

This code works but, when I validate the xml-file in XmlSpy I get this
message:
This file is not valid:"
"Invalid value for datatype ID attribute Countryid"
Indicating that something aint 100% correct... But in Visual Studio, I can
swicth to Data-view on the xml-file without any problem... anyway I don't
know if switching to Data-view in VS is an important information...

****************************************************************************
**
Any clues to my questions will be appreciated!

Jeff






Vote for best question.
Score: 0  # Vote:  0
Date Posted: 5-Jul-2004, at 10:59 PM EST
From: Jeff
 
Re: newbie: Visual Studio could not locate a schema for this  
News Group: microsoft.public.dotnet.xml
"Jeff"  wrote in message news:#OLeEMtYEHA.712@TK2MSFTNGP11.phx.gbl...
>     xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
>     xmlns:schemaLocation="file:///C:/MyProjects/Visual Studio
> Projects/ReadXml/lesson_getelementbyid/country.xsd">

The ability to qualify element and attribute names with the prefix,
schemaLocation, is probably not what you want.  Remember,
namespace URIs are only used to distinguish elements and
attributes as belonging to that namespace; they are not required
to be a real, tangible resource; since they can be totally imaginary,
it's not surprising for an XML processor not to resolve them.

Instead of using a namespace declaration, you need an
attribute in the http://www.w3.org/2001/XMLSchema-instance
namespace.  In the preceding line, you associated the 'xsi' prefix
with that namespace URI, which XML Schema-aware processors
use to pick-up "hints" in the instance document.  The attribute
should look like (please ignore the linebreak on the long URL):

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="testing file:///C:/MyProjects/Visual%20Studio%20Projects/ReadXml/lesson_getelementbyid/country.xsd">

The XML Schema Primer, section 5.6,

    http://www.w3.org/TR/xmlschema-0/#schemaLocation

can provide you with further details and examples.

> XmlAttribute newAttr = xmldoc.CreateAttribute("Countryid");
> newAttr.Value = "5";       //yes hardcoded, but this is just for
: :
> This code works but, when I validate the xml-file in XmlSpy I get this
> message:
> This file is not valid:"
> "Invalid value for datatype ID attribute Countryid"
> Indicating that something aint 100% correct... But in Visual Studio, I can
> swicth to Data-view on the xml-file without any problem... anyway I don't
> know if switching to Data-view in VS is an important information...

The error message is correct (I suspect you will receive the same
validation error in VS once it knows where the schema is located.)

The xs:ID data type for the CountryId attribute requires that the attribute
value cannot start with a digit.  Therefore, '5' (or any "number") is an
invalid ID, whereas 'country-5'  (any "number" prefixed by one or more
letters) is a valid ID.


Derek Harmon



Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 5-Jul-2004, at 7:50 PM EST
From: Derek Harmon
 
Re: newbie: Visual Studio could not locate a schema for this  
News Group: microsoft.public.dotnet.xml
Thank you for your reply, it helped me a step futher... but now I get these
messages when I in Visual Studio choose to validate the xml file (Xml |
Validate XML Data)..

Something I find strange is that I get similar errors when validating xml
files included in my book about xml
I have the book "Applied xml programming for microsoft .net"... This lead me
to think that these errors might not be caused by my xml/xsd file afterall

I have version 7.1.3088 of VS 2003 .net and version 1.1.4322 of the .net
framework

Error/warning messages I get in Visual Studio:

C:\MyProjects\xml\country.xml(11): The 'testing:Capital' element is not
declared. An error occurred at , (11, 6).

C:\MyProjects\xml\country.xml(7): The 'testing:Capital' element is not
declared. An error occurred at , (7, 6).

C:\MyProjects\xml\country.xml(5): The 'testing:Country' element is not
declared. An error occurred at , (5, 4).

C:\MyProjects\xml\country.xml(9): The 'testing:Country' element is not
declared. An error occurred at , (9, 4).

C:\MyProjects\xml\country.xml(10): The 'testing:Name' element is not
declared. An error occurred at , (10, 6).

C:\MyProjects\xml\country.xml(6): The 'testing:Name' element is not
declared. An error occurred at , (6, 6).

C:\MyProjects\xml\country.xml(2): The 'testing:Test' element is not
declared. An error occurred at , (2, 2).

C:\MyProjects\xml\country.xml(1): Visual Studio could not locate a schema
for this document. Validation can only ensure this is a well formed XML
document and cannot validate the data against a schema.

Here is my .xsd file again:


 
  
   
    
     
      
       
       
      
      
     
    
   
  
 


Here is my .xml file again:


  
    Norway
    Oslo
  
  
    France
    Paris
  


Do you have any hints to why I get these error/warning messages??

(I validated the xml file in XmlSpy, and XmlSpy reported no errors/warnings,
it reported that the xml file was valid.)

Jeff



"Derek Harmon"  wrote in message
news:%23UZs2quYEHA.2520@TK2MSFTNGP12.phx.gbl...
> "Jeff"  wrote in message
news:#OLeEMtYEHA.712@TK2MSFTNGP11.phx.gbl...
> >     xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
> >     xmlns:schemaLocation="file:///C:/MyProjects/Visual Studio
> > Projects/ReadXml/lesson_getelementbyid/country.xsd">
>
> The ability to qualify element and attribute names with the prefix,
> schemaLocation, is probably not what you want.  Remember,
> namespace URIs are only used to distinguish elements and
> attributes as belonging to that namespace; they are not required
> to be a real, tangible resource; since they can be totally imaginary,
> it's not surprising for an XML processor not to resolve them.
>
> Instead of using a namespace declaration, you need an
> attribute in the http://www.w3.org/2001/XMLSchema-instance
> namespace.  In the preceding line, you associated the 'xsi' prefix
> with that namespace URI, which XML Schema-aware processors
> use to pick-up "hints" in the instance document.  The attribute
> should look like (please ignore the linebreak on the long URL):
>
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="testing
file:///C:/MyProjects/Visual%20Studio%20Projects/ReadXml/lesson_getelementbyid/country.xsd">
>
> The XML Schema Primer, section 5.6,
>
>     http://www.w3.org/TR/xmlschema-0/#schemaLocation
>
> can provide you with further details and examples.
>
> > XmlAttribute newAttr = xmldoc.CreateAttribute("Countryid");
> > newAttr.Value = "5";       //yes hardcoded, but this is just for
> : :
> > This code works but, when I validate the xml-file in XmlSpy I get this
> > message:
> > This file is not valid:"
> > "Invalid value for datatype ID attribute Countryid"
> > Indicating that something aint 100% correct... But in Visual Studio, I
can
> > swicth to Data-view on the xml-file without any problem... anyway I
don't
> > know if switching to Data-view in VS is an important information...
>
> The error message is correct (I suspect you will receive the same
> validation error in VS once it knows where the schema is located.)
>
> The xs:ID data type for the CountryId attribute requires that the
attribute
> value cannot start with a digit.  Therefore, '5' (or any "number") is an
> invalid ID, whereas 'country-5'  (any "number" prefixed by one or more
> letters) is a valid ID.
>
>
> Derek Harmon
>
>



Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 6-Jul-2004, at 1:47 PM EST
From: Jeff
 
Re: newbie: Visual Studio could not locate a schema for this  
News Group: microsoft.public.dotnet.xml
You have a namespace conflict.
Add -elementFormDefault="qualified"- to your schema declaration:



See also:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxml/html/xmlschemacomplex.asp
under
-Why you should always set elementFormDefault to "qualified"-.

gerben abbink
xmlBlueprint XML Editor
www.xmlBlueprint.com

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 7-Jul-2004, at 5:53 AM EST
From: Gerben Abbink