• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 903
  • Last Modified:

Problems of noNamespaceSchemaLocation in VB.NET

Hi,

I want to learn XML, and copy the sample schema and XML data into VB.NET environment to validate.
the sample is simple, mainly copied form "professional XML" textbook.

The two files are named: noNs.xsd and noNs.xml, and put into same directory. and when I validate
the xml data file, there will be some errors.

I donot know where is the problem, is it because the VB environment does not support this kind
noNamespaceSchemaLocation usage? or we need do some changes to files or to VB setting?

(and if I let the schema has its targetNamespace,and without noNamespaceSchemaLocation, it works.)
Below is some related info:

1. When validate schema, no validation errors were found.
2. When validate XML data, there are 6 build errors:
   1. to 5. The element: customerList, customerName, FirstName, MiddleInitial,LastName, not declared.
   6. 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.
3. the schema and xml data file attached here:

noNs.xsd:
---------
<?xml version="1.0" encoding="utf-8" ?>
<schema id="noNs" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="customerList">
     <complexType>
     <sequence>
          <element name="customerName" minOccurs="0" maxOccurs="3">
               <complexType>
               <sequence>
                    <element name="FirstName" type="string"></element>
                    <element name="MiddleInitial" type="string"></element>
                    <element name="LastName" type="string"></element>
               </sequence>
               </complexType>
          </element>
     </sequence>
     </complexType>
</element>
</schema>
---------

noNs.xml:
---------
<?xml version="1.0" encoding="utf-8" ?>
<customerList xmlns:xsi="http://wwwv.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="noNs.xsd">
     <customerName>
          <FirstName>Raymond</FirstName>
          <MiddleInitial>G</MiddleInitial>
          <LastName>Bayliss</LastName>
     </customerName>
</customerList>
---------
ps: I also tried the absolute path and file for noNamespaceSchemaLocation, it has the same errors.

Thanks,
Gary
0
garyge
Asked:
garyge
  • 2
  • 2
1 Solution
 
Wayne BradneyIndependent ConsultantCommented:
garyge,

I think your problem is probably due to a typo in your xsi namespace prefix declaration:

http://wwwv.w3.org/2001/XMLSchema-instance

should be

http://www.w3.org/2001/XMLSchema-instance

Your schema is correctly referenced, but the validating parser won't recognise the grammars within it because it's in the wrong namespace.

Regards,
WMB
0
 
garygeAuthor Commented:
Hi WMB,
Thanks for your reply.
I have made a mistake in typewriting,(actually I copied it to post and maybe copied from wrong place). In my visual studio environment, I checked the namespace which is correct, without 'v', but same errors still existed.
0
 
Wayne BradneyIndependent ConsultantCommented:
garyge,

It would appear that VS.NET doesn't honour the schemaLocation/noNamespaceSchemaLocation attributes. According to the XML Schema spec, it doesn't have to honour those attributes: they're just a hint.

I don't use VS.NET to validate documents, but I did a little digging and found the following link:

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q307379&ID=kb;en-us;Q307379&SD=MSDN

Maybe you'll need to write a small application to load the document and the schema in order to validate.

Regards,
WMB
0
 
garygeAuthor Commented:
Hi WMB,
Thank you very much, I will check the link and write some code to validate it. Thanks for your direction.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now