Skip to content

Commit

Permalink
Referenced RelaxNG schema not found via XML catalog
Browse files Browse the repository at this point in the history
Fixes redhat-developer/vscode-xml#804

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Nov 16, 2022
1 parent f6c8d9a commit d6a615d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static InputSource createInputSource(RelaxNGDescription description, XML
throws MalformedURIException, IOException {
XMLInputSource source = entityResolver.resolveEntity(description);
return source.getByteStream() != null ? new InputSource(source.getByteStream())
: new InputSource(description.getExpandedSystemId());
: new InputSource(source.getSystemId());
}

private static SchemaReader getSchemaReader(String systemId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,16 @@ public void incomplete_element_required_element_missing() throws Exception {
d(0, 1, 4, RelaxNGErrorCode.incomplete_element_required_element_missing));
}

@Test
public void unknown_element() throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<?xml-model href=\"http://canonical-uri/schema.rng\" type=\"application/xml\" schematypens=\"http://relaxng.org/ns/structure/1.0\"?>\r\n"
+ //
"<test> \r\n" + //
" <valid>I am valid element</valid>\r\n" + //
" <invalid>I am invalid b element</invalid>\r\n" + // <-- element "invalid" not allowed anywhere; expected the element end-tag or element "valid"
"</test>";
testDiagnosticsFor(xml, "src/test/resources/relaxng/catalog-relaxng.xml", //
d(4, 5, 12, RelaxNGErrorCode.unknown_element));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">

<uri name="http://www.tei-c.org/ns/1.0" uri="tei_all.rng" />

<rewriteURI uriStartString="http://canonical-uri/" rewritePrefix="./"/>

</catalog>
15 changes: 15 additions & 0 deletions org.eclipse.lemminx/src/test/resources/relaxng/schema.rng
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
xmlns:sch="http://purl.oclc.org/dsdl/schematron"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
ns="">
<start>
<element name="test">
<zeroOrMore>
<element name="valid">
<text/>
</element>
</zeroOrMore>
</element>
</start>
</grammar>

0 comments on commit d6a615d

Please sign in to comment.