xmllint: Relax-NG parser error : xmlRelaxNGParse: xxx.rng is empty

I tried to validate my xml file against relax-ng file, using xmllint, and each time I got this error:

Relax-NG parser error : xmlRelaxNGParse: <my_file>.rng is empty

I’ve spent two hours searching the web without finding any answer. I’ve tried with relax-ng examples taken from official tutorial and still got the same error. Then I looked at relax-ng own .rng file (the one validating the validation-language itself! http://www.thaiopensource.com/relaxng/relaxng.rng) and looking at the source, I noticed that they defined an xmlns attribute on <grammar> node.

That’s the source of the problem! Simply add this xmlns attribute to your grammar node too, and xmllint works.

In the end, xmllint error message is clearly misleading, .rng file is not empty, it simply misses “xmlns” attribute on root <grammar> node.

example

wrong relax-ng file:

<?xml version="1.0"?>
<grammar>
<start>
<element name="address"><text/></element>
</start>
</grammar>

correct relax-ng file:

<?xml version="1.0"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<element name="address"><text/></element>
</start>
</grammar>

sources

  • http://www.thaiopensource.com/relaxng/relaxng.rng Relax-NG validation file for Relax-NG syntax

One Comment Trackback URL | Comments RSS

  1. Tim Says:

    Thanks for this, saved me a lot of time I guess!

Post a Comment

Your email is never published nor shared. You're allow to say what you want...