This must be a dumb question

I'm very new to XML and am completely confused by namespaces. I've created a schema and xml data file but I'm having problems validating the data, I get the error "Visual Studio could not locate a schema for this document".
Here's a cut down copy of the schema and data file. I hope someone can show me the error of my ways!

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="GEMM_ConfigData">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="AppSettings" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="BaudRate" type="xsd:integer" minOccurs="0" />
<xsd:element name="ComPort" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="COM1" />
<xsd:enumeration value="COM2" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="LogPath" type="xsd:string" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

<?xml version="1.0" encoding="UTF-8"?>
<GEMM_ConfigData
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file:///C:/Program Files/Goodrich/GEMM/ConfigData.xsd">
<AppSettings>
<BaudRate>9600</BaudRate>
<ComPort>COM3</ComPort>
<LogPath>C:\GEMM\Logs</LogPath>
</AppSettings>
</GEMM_ConfigData>

[1758 byte] By [.Net.Not] at [2007-12-17]
# 1
you haven't set the schema in your xml file. quickest way to do this, is (assuming you're using visual studio) hit the properties window while you have the XML document as your active document. there will be a property for schema. drop down the available options and you should see your schema there (assuming they're a part of the same solution)

-ben

BadBadBadBadBen at 2007-9-9 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 2
The targetSchema dropdown does not contain my local schema, only some very generic sounding public schemas (Ad Rotator Schedule File, Web Forms Controls, Mobile Web Form, ...).
I added the path to my local schema and it added an xmlns attribute to the xml:
<?xml version="1.0" encoding="UTF-8"?>
<GEMM_ConfigData
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file://C://Program Files//Goodrich//GEMM//ConfigData.xsd"
xmlns="file:///C:/Program Files/Goodrich/GEMM/ConfigData.xsd">

The XML Validator still cannot find the schema.

.Net.Not at 2007-9-9 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 3

Would you mind zipping up the project folder, including the sln, xml, and xsd? I could take a look.

-Ben

BadBadBadBadBen at 2007-9-9 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 4
Thanks for the offer, but it's not code that I'm having a problem with, I deserialize the xml validating against the schema just fine by adding the schema to the XmlValidatingReader.Schemas collection.
What I'd like to do is use the Visual Studio "Validate XML Data" function on the "XML" menu to check my data before I even hit run.
-Bryan
.Net.Not at 2007-9-9 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 5

The Xml Editor in Visual Studio 2005 will automatically validate the xml file if it finds a schema for the file.
It uses the target namespace on the schema to auto associate a schema to an xml instance document.

In your case it tries to find a schema using xsi:noNamespaceSchemaLocation="file:///C:/Program Files/Goodrich/GEMM/ConfigData.xsd" which is defined in your xml file.

Have you saved your schema file at "C:/Program Files/Goodrich/GEMM/ConfigData.xsd"?

You can check the schema property on the xml file to see if a schema is associated.

You can add your own schema for validation by clicking on "Add" button in the schema dialog where you see the generic schemas. You could even manually type
the location of your schema into the schema properties.

Hope that helps.
Tejal.

Tejal at 2007-9-9 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 6
The schema is indeed saved at that location.
I'm not sure what you mean by the "schema property on the xml file" ... if I open the xml file in Visual Studio the property page shows 2 fields: Target Schema and Encoding.
If I set the Target Schema, an xmlns attribute gets added to the xml.
The Validate XML Data menu item still reports that it cannot locate the schema.
.Net.Not at 2007-9-9 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 7
You are using Visual Studio 2003 which does not automatically find matching schemas by namespace. Notice the reference to Visual Studio "2005" above. I highly recommend you get at least the C# Express version for editing and validating XML - it contains a completely new XML editor that is XML 1.0 compliant and full of lots of nifty new and useful features like xml snippet editing and so on.
ChrisLovett at 2007-9-9 > top of Msdn Tech,.NET Development,XML and the .NET Framework...

.NET Development

Site Classified