Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Including a schema in an xml file correctly

Status
Not open for further replies.

Kalisto

Programmer
Feb 18, 2003
997
0
0
GB
OK, using Vis Studio 2003 (if that has any bearing)

I have a folder on my localhost that contains a sample xml documeny, an XSLT and a schema

I can make the xslt do some basic formatting, no problem. But now I want to make sure that the data is validated agaisnt my schema. in my root node I have the following code
<registrationdetails
xmlns="
but visual studio claims it cannot find an associated schema (the file does definitely exist)

is this code correct, i.e. its a vis studio issue, or is it my crude xml that is at fault?

K
 
Code:
<registrationdetails xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xsi:noNamespaceSchemaLocation="[URL unfurl="true"]http://localhost/xmlproject/bdefinitions.xsd">[/URL]
Or if your schema has a target namespace:
Code:
<registrationdetails xmlns="mynamespace"
xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL]
xsi:schemaLocation="mynamespace bdefinitions.xsd">
More info:

 
Thanks, I now get a whole host of errors, but it still claims that it cant find a schema to validate against.

In addition to that I now get a whole load of
<namespace>:<element> is not declared, which I assume means that it accepts my namespace (which I thought was the default anyway) but wants to see <namespace>: before each element.

in my xml file I now have
Code:
<registrationdetails xmlns="[URL unfurl="true"]http://localhost/xmlproject"[/URL] 
xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL]
xsi:schemaLocation="[URL unfurl="true"]http://localhostxmlproject/bdefinitions.xsd">[/URL]

and in the xsd its
Code:
<xs:schema id="registrationdetails" targetNamespace="[URL unfurl="true"]http://localhost/xmlproject"[/URL] 
	xmlns="[URL unfurl="true"]http://localhost/xmlproject"[/URL] 
	xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL]
	xmlns:b="[URL unfurl="true"]http://localhost/xmlproject"[/URL] 
	attributeFormDefault="qualified" elementFormDefault="qualified">

As I understand it, I should now be able to prefix any elements that are defined in the schema with a b: in my xml document?
(If so then I have a bug elsewhere!)

K
 
Try this:
Code:
<registrationdetails xmlns="[URL unfurl="true"]http://localhost/xmlproject"[/URL] 
xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL]
xsi:schemaLocation="[URL unfurl="true"]http://localhost/xmlproject[/URL] bdefinitions.xsd">
 
Thanks for all your help, but no dice, same error messages

K
 
Double double check you have copied EXACTLY what Jon has put in the above post.

xsi:schemaLocation requires a SPACE between the namespace URI and the document name.


matt

 
I have, I cut and pasted it in to be sure.

so My xsd is now
Code:
<?xml version="1.0" encoding="utf-8" ?>

<xs:schema targetNamespace="[URL unfurl="true"]http://localhost/xmlproject"[/URL]
elementFormDefault="qualified"
xmlns="[URL unfurl="true"]http://localhost/xmlproject"[/URL]
xmlns:mstns="[URL unfurl="true"]http://tempuri.org/XMLSchema.xsd"[/URL]
xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL]
xmlns:becta="[URL unfurl="true"]http://localhost/xmlproject">[/URL]

my xml is
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="frmUserRegistration_1.xslt"?>

<registrationdetails xmlns="[URL unfurl="true"]http://localhost/xmlproject"[/URL] 
xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL]
xsi:schemaLocation="[URL unfurl="true"]http://localhost/xmlproject[/URL] bdefinitions.xsd">

All files exist in the path localhost/xmlproject/, and are lower case

Any more ideas anyone?

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top