20

I'm trying to use xmllint to check my work while developing a basic XSD i.e. XML Schema schema. However it's giving me an error

Validation failed: no DTD found.

What am I doing wrong?

My xmllint command:

xmllint --noout --valid --schema simple.xsd lucas-basic.xml
lucas-basic.xml:5: validity error : Validation failed: no DTD found !
        >
        ^
lucas-basic.xml validates

Test XSD file:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="vehicles">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="nickname" type="xsd:string" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

Test XML file:

<?xml version="1.0"?>
<vehicles xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="http://lucas.ucs.ed.ac.uk/xml-schema/xmlns/simple.xsd">
  <nickname>Bog Hopper</nickname>
  <nickname>Wee Beastie</nickname>
  <nickname>Count Zero</nickname>
</vehicles>

The URL at xsi:noNamespaceSchemaLocation does return the above XSD. Also, I downloaded the XSD file and put it into the current directory as an extra measure, but this didn't seem to have changed anything.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Tristan
  • 1,730
  • 3
  • 20
  • 25
  • Now that I have it working I should comment that using a local file or specifying a remote schema works equally well e.g. --schema simple.xsd OR --schema http://lucas.ucs.ed.ac.uk/xml-schema/xmlns/simple.xsd – Tristan Mar 30 '16 at 20:40

2 Answers2

28

--valid is for DTDs, not XSDs.

This will work for you instead:

xmllint --noout --schema http://lucas.ucs.ed.ac.uk/xml-schema/xmlns/simple.xsd lucas-basic.xml
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • That seems to work thanks! Does this mean that a document written using an XSD rather than a DTD is technically not valid XML? – Tristan Mar 30 '16 at 20:27
  • 3
    Haha, no, it means their choice of command line switch names was imperfect. – kjhughes Mar 30 '16 at 20:30
3

The OP attempt and accepted answer "validate" the XSD by testing it against a sample file. To validate the XSD file against the XSD specification, the following command may be used:

xmllint --noout --schema http://www.w3.org/2001/XMLSchema.xsd my_schema.xsd

... and for v1.1 the schema is https://www.w3.org/2009/XMLSchema/XMLSchema.xsd

NOTE: the v1.0 schema has some qualifications at the top about the normative structure schema so it's possible another file should actually be used but this worked fine for me.

claytond
  • 1,061
  • 9
  • 22