Groups | Blog | Home
all groups > dotnet xml > august 2004 >

dotnet xml : Help associate xml to xsd (schema) file...


Vagabond Software
8/4/2004 11:01:07 AM
I have translated a DTD to an XML Schema (XSD) file by hand, and the =
Schema View in Visual Studio .NET 2003 seems to diplay everything =
properly.

However, when I specify the schemalocation in my xml files, VS.NET still =
reports that no schema could be located. Here are the relevant (maybe) =
portions of the files:

FROM THE SCHEMA FILE (mydoc-v2.xsd)

<?xml version=3D"1.0" encoding=3D"utf-8" ?>
<xs:schema targetNamespace=3D"http://tempuri.org/XMLSchema.xsd"
elementFormDefault=3D"qualified"
xmlns=3D"http://tempuri.org/XMLSchema.xsd"
xmlns:mstns=3D"http://tempuri.org/XMLSchema.xsd"
xmlns:xs=3D"http://www.w3.org/2001/XMLSchema">

FROM THE XML FILE (myTestDoc.xml):

<mydoc=20
xmlns=3D"http://tempuri.org/mydoc-v2.xsd"=20
xmlns:xs=3D"http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation=3D"file:///C:/Dev/mydoc-v2.xsd">

VISUAL STUDIO .NET 2003 ERROR MSG:

C:\Dev\myTestDoc.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.

Any help with this is greatly appreciated.

- VSW

Priscilla Walmsley
8/4/2004 3:07:39 PM
Hi,

You have two problems in your instance XML:

1. The namespace in your instance must match the target namespace of your
schema. So, you should change xmlns="http://tempuri.org/mydoc-v2.xsd" to
xmlns="http://tempuri.org/XMLSchema.xsd".

2. The schemaLocation attribute should be the namespace, followed by
whitespace, followed by the schema location. You have only specified the
schema location. So, you should change it to
xs:schemaLocation="http://tempuri.org/XMLSchema.xsd
file:///C:/Dev/mydoc-v2.xsd"

Also, usually people use the prefix "xsi" rather than "xs" for the
http://www.w3.org/2001/XMLSchema-instance namespace. It's not incorrect the
way you have it, but it might be more clear if you used xs instead of xsi in
your instance.

Hope that helps,
Priscilla
------------------------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema / XML in Office 2003
http://www.datypic.com
------------------------------------------------------------------

[quoted text, click to view]
I have translated a DTD to an XML Schema (XSD) file by hand, and the Schema
View in Visual Studio .NET 2003 seems to diplay everything properly.

However, when I specify the schemalocation in my xml files, VS.NET still
reports that no schema could be located. Here are the relevant (maybe)
portions of the files:

FROM THE SCHEMA FILE (mydoc-v2.xsd)

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

FROM THE XML FILE (myTestDoc.xml):

<mydoc
xmlns="http://tempuri.org/mydoc-v2.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="file:///C:/Dev/mydoc-v2.xsd">

VISUAL STUDIO .NET 2003 ERROR MSG:

C:\Dev\myTestDoc.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.

Any help with this is greatly appreciated.

- VSW


metaphis2k2 NO[at]SPAM hotmail.com
8/5/2004 6:15:18 AM
I Must add that if you use the validation in Visual Studio using the
menu the xsd must be in the same project as the xml.

I never got it too work without putting both in a project.

Hope this help

[quoted text, click to view]
AddThis Social Bookmark Button