I've been searching for the answer and could not find one:
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With