Just tried in VS 2013 and VS 2015. They really confirmed the / refkey key now. He found warnings at the parent level.
But, as @antiduh said, they still do not check the xsd file. So you really need to make sure the / refkey in xsd is correct .
It took me a while to figure out a simple example. Even the sample in MSDN does not work. I had to change it a bit.
First, make sure you know to let Visual Studio check the xml on xsd of your choice .
Then use the following xsd and xml example to verify the / refkey switch. Keep in mind that the warning is on closing the root element, and not on the element that violates the / ref key rule.
The xsd file is as follows:
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="namespace1" xmlns:r="namespace1" elementFormDefault="qualified"> <xs:element name="root"> <xs:complexType> <xs:sequence> <xs:element name="A" type="r:A" maxOccurs="unbounded"/> <xs:element name="B" type="r:B"/> </xs:sequence> </xs:complexType> <xs:keyref name="dummy" refer="r:pNumKey"> <xs:selector xpath="r:A/r:part"/> <xs:field xpath="@ref-number"/> </xs:keyref> <xs:key name="pNumKey"> <xs:selector xpath="r:B/r:part"/> <xs:field xpath="@key-number"/> </xs:key> </xs:element> <xs:complexType name="A"> <xs:sequence> <xs:element name="part" maxOccurs="unbounded"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="ref-number" type="xs:integer"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> <xs:complexType name="B"> <xs:sequence> <xs:element name="part" maxOccurs="unbounded"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="key-number" type="xs:integer"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:schema>
And the xml file looks like this:
<?xml version="1.0" encoding="utf-8" ?> <root xmlns="namespace1"> <A> <part ref-number="1"/> </A> <A> <part ref-number="5"/> </A> <B> <part key-number="1"/> <part key-number="2"/> <part key-number="3"/> </B> </root>
Bruce wang
source share