Michael Levy
Michael Levy

Reputation: 13297

Validating XML with standard XSD schema in Visual Studio 2017

How can I use Visual Studio 2017 to validate my XML with referenced public XSD schemas?

In Visual Studio 2017, first I enable "Automatic Download of DTDs and Schemas" under tools->Options->Text Editor->XML->Miscellaneous. Then, when I specify an XML document that includes and xsi:schemaLocation, Visual Studio fails to load the referenced schema and I can't take advantage of the Visual Studio features like XML validation and intellisense editing.

Here is an example, take the standard conforming example document from VXML 2.1

<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://www.w3.org/2001/vxml 
  http://www.w3.org/TR/2007/REC-voicexml21-20070619/vxml.xsd">

  <form>
    <block>hello</block>
  </form>

</vxml>

If I enter this as an XML document in Visual Studio a get a bunch of warnings:

The operation has timed out
The schema referenced from this location in your document contains errors

I think this answer from @Petru Gardea is similar to my problem - https://stackoverflow.com/a/21562249/90236 - W3C apparently throttles their servers and tools like Visual Studio will timeout. The suggestion in the answer above is to bring the XSD file local and update the xsd path. Unfortunately, a complex schema will bring in may other schemas by xsd:include or xsd:import. I have not been able to get all the included schemas properly download for this to work.

Isn't Visual Studio supposed to download and cache the referenced schemas as part of the XML Schema set? Do I have to manually download and add some schemas to the set as described in XML Validation with XSD in Visual Studio IDE ?

Other tools, most notably XMLSpy, just do the right thing and validation works great. Can I get this to work in Visual Studio?

-- update --

I found this post W3C’s Excessive DTD Traffic. But it isn't clear to me what the accepted solution is. Shouldn't Visual Studio manage an XML catalog for the schemas? I've also been told that w3.org won't respond to XSD requests without a valid user-agent header. Is this why my operation is timing out?

Upvotes: 2

Views: 2465

Answers (1)

Norbert Csibra
Norbert Csibra

Reputation: 31

I had a similar issue in VS2015: When I tried to use a dtd or xsd file for validation/intellisense, I received error messages. I tried to delete the schemas in the Schema selector, but some sharepoint related shema was remained (not deleted).

Finally I've renamed the folders where these shemas were located, and the intellisense started to work (after restart VS). The folder is the following:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\XML

Upvotes: 3

Related Questions