Problem validating XML against XSD with Eclipse/ADT - no "Validate" context menu entry
Im trying to get Eclipse to validate an XML file I've created against a schema I've also created but it's not working, I don't have a "Validate" entry in the context menu.
I'm using Eclipse 3.6.2 with ADT 10.0.1 and in Help -> About -> Installation details, Plug-ins tab I have Eclipse XML Editors and Tools version 1.1.103.
According to what I've found on both Eclipse's website and other questions on SO I should be able to right click on the XML file and click on "Validate". My context menu has no "Validate" entry and everything I find assumes it's there. I've gone into Eclipse Preferences -> XML -> XML Files -> Validation and ticked "Enable markup validation" but that hasn't changed anything..
Also changing the noNamespaceSchemaLocation valu开发者_运维问答e to something incorrect doesn't give me any errors when saving the XML file. I have no idea what I'm missing here
The idea was for the properties pane in Eclipse to show a dropdown for the element "name" attribute showing the valid values, which I'm hoping will happen once I can validate against the XSD.
Similar questions
eclipse: validate xml with xsd just like me, no solution found even though the answer is accepted. Comments mention Web Tools Platform, which is installed.
XML validation and auto-complete in Eclipse I have done what the accepted answer mentions
Files
They're probably terrible, I haven't done much XML before.
res/xml/magicks.xml
:
<?xml version="1.0" encoding="utf-8"?>
<magicks xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="magicksschema.xsd">
<magick name="Haste" description="Increases the wizard's movement speed by up to double for 10 seconds.">
<combination>
<element name="Lightning"/>
<element name="Arcane" />
<element name="Fire" />
</combination>
</magick>
</magicks>
res/xml/magicksschema.xsd
:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="magicks">
<xs:complexType>
<xs:sequence>
<xs:element name="magick" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="combination">
<xs:complexType>
<xs:sequence>
<xs:element name="element" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Water" />
<xs:enumeration value="Life" />
<xs:enumeration value="Shield" />
<xs:enumeration value="Cold" />
<xs:enumeration value="Lightning" />
<xs:enumeration value="Arcane" />
<xs:enumeration value="Earth" />
<xs:enumeration value="Fire" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="description" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
Edit
- Updated schema to @Per Normann's version
Your schema is not correct, specifically w.r.t. how you declare attributes.
1) attributes are declared directly on the type, not as part of a sequence.
2) you defined the element <element> to be enumeration restricted, not the attribute "name".
This schema matches your XML (and eclipse validation works fine).
<xs:element name="magicks">
<xs:complexType>
<xs:sequence>
<xs:element name="magick" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="combination">
<xs:complexType>
<xs:sequence>
<xs:element name="element" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Water" />
<xs:enumeration value="Life" />
<xs:enumeration value="Shield" />
<xs:enumeration value="Cold" />
<xs:enumeration value="Lightning" />
<xs:enumeration value="Arcane" />
<xs:enumeration value="Earth" />
<xs:enumeration value="Fire" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="description" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
精彩评论