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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML and XSDs in VS .NET

Status
Not open for further replies.

crazyfishpants

Programmer
Mar 30, 2004
18
US
Can anyone tell me how to get an XML document to validate against an XSD file in Visual Studio .NET? From the XML menu, when selecting Validate XML Data, I always get errors stating that Visual Studio cannot locate my schema. I'm not sure that I know how to use the namespaces correctly so this may be why I can't get even the most simple XML/XSDs to validate. Please help. Thank you.
 
I'm not sure that I understand your reply. Shouldn't the Validate XML Data option from the XML menu work? I would imagine there is a more simple way to validate XML against an XSD rather than utilizing the XmlValidatingReader class.
 
i had this problem with mine. the way i fixed it is open up your schema, note down the web addresses that come up at the top. then go to your xml document select view>properties (F4 shortcut). in the toolbar window that pops up on the right select target schema and then select the web address that is the same on the schema.

thats how i did it, hope this helps
 
sorry for the late reply, after giving you the advice i went and tried to do something and came up with the exact same problem again. its been bugging me all day, but i've finally cracked it!!!

i was getting the same message as you, but after lots of fiddling around, i saved the .xsd file in the directory
..visual studio.net2003\common7\packages\schemas\xml and it seemed to link ok.
 
also, what you're doing is looks right from where i'm sitting. the top of my .xsd file looks like:
Code:
<xs:schema targetNamespace="[URL unfurl="true"]http://tempuri.org/XMLSchema.xsd"[/URL]
                  elementFormDefault="qualified"
                  xmlns="[URL unfurl="true"]http://tempuri.org/XMLSchema.xsd"[/URL]
                  xmlns:mstns="[URL unfurl="true"]http://tempuri.org/XMLSchema.xsd"[/URL]
                  xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]

and i have the tempuri.org/XMLSchema.xsd part at the top of my xml file
 
Thank you very much for your very helpful post! It works! Now I just have to figure out of the namespace is somehow set to that directory.
 
thats ok, never say teachin yourself or fiddling around doesnt work :)

glad i could help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top