The RELAX NG validator currently does not handle XML documents with an XML declaration, such as <?xml version="1.0" encoding="UTF-8"?>.
As a first step to address this issue, I suggest adding the following test case to test/test_validation_rng.rb. This test case checks that the validator can successfully validate an XML document with a declaration. I haven't yet developed an implementation solution, but this test will help ensure that we cover this scenario:
def test_document_with_declaration
rng = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<element name="root"/>
</start>
</grammar>
XML
validator = REXML::Validation::RelaxNG.new(rng)
source = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<root/>
XML
no_error(validator, source)
end