Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSD key/keyref intellisense validation support in Visual Studio 2010

I've been searching for the answer and could not find one:

  • Is there a XSD key/keyref validation support via Intellisense in Visual Studio 2010?
  • If so, how to make it work?
  • If no, is there a (built-in) way in Visual Studio to do key/references validation in an XML having an XSD schema at all?

Thanks!

UPDATE: Please note the question isn't about how to validate an XML having an XSD file. I am asking specifically about the key/keyref intellisense/whatever support in Visual Studio, which doesn't seem to be added at all.

like image 977
Trident D'Gao Avatar asked Mar 09 '12 18:03

Trident D'Gao


People also ask

How do you test for XSD?

Simply go to the XML Tools > Validate Now option and click on it. You can also press Ctrl + Alt + Shift + M key combination to open Validate Now option. Now, select the XSD file against which you want to validate the opened XML document.


1 Answers

Visual Studio 2012 now supports validation of XML document instances that are subject to key/keyref constraints as defined in a referenced schema.

However, Visual Studio doesn't give any errors for the schema document itself, when that schema document uses key/keyref incorrectly - independent of whether some document meets the schema.

Specifically, key/keyref elements as defined in the schema must use namespaces in the selector xpath statements, according to the following SO post:

https://stackoverflow.com/a/4492004/344638

To quote:

Furthermore - this is a gotcha - key constraints don't recognise the default namespace. You must always prefix every part of the selector xpath with the namespace prefix of the element you're looking up. If you don't have a namespace prefix - tough, you'll need to add one. This is a limitation of the standard.

The following SO post provides a complete example of a schema that uses key/keyref, an XML document instance, and a manual C#-based validater. The schema and the XML document instance validate correctly in Visual Studio - Visual Studio will generate errors if the document violates the schema's key/keyref constraints:

https://stackoverflow.com/a/2866428/344638

like image 176
antiduh Avatar answered Sep 20 '22 20:09

antiduh