Re: Schema Validation, XMLCatalogResolver, rewriteURI

Christian Grün <[email protected]> Tue, 26 Nov 2019 11:29:39 +0100
Newsgroups gmane.text.xml.xerces-j.user
Message-ID <CAP94bnMNx9fWH1tFV=bb5naPei06687y6iAO6h4SFAD3E5N=sg@mail.gmail.com>
Anyone who could give me some hints here?


On Mon, Nov 11, 2019 at 12:15 PM Christian Grün
<[email protected]> wrote:
>
> Hi all,
>
> I’m trying to validate a document with Xerces. My schema has "http" includes that need to be rewritten to "https". I try to do this with an XML catalog and rewriteURI, but the rule seems to be ignored.
>
> I have attached some stripped-down Java code. The inclusion of "http://standards.iso.org/..." leads to a "Premature end of file" exception (presumably because the request returns a 302 redirect with an empty payload). Another (expected) error is raised if the URL is changed to https.
>
> My questions:
>
> • (Why) Is the rewriteURI rule ignored?
> • How can I enable some debugging output, or adjust the verbosity level, with the XMLCatalogResolver?
>
> I managed to get the validation running with Saxon EE.
>
> Thanks in advance,
> Christian
> ________________________________
>
> import java.nio.file.*;
> import javax.xml.validation.*;
> import org.apache.xerces.jaxp.validation.*;
> import org.apache.xerces.util.*;
>
> public class ValidateTest {
>   public static void main(final String... args) throws Exception {
>     String schemaString =
>       "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
>       "  <xs:include schemaLocation='" +
>       "https://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/gmd/gmd.xsd'/>" +
>       "</xs:schema>";
>     String catalogString =
>         "<catalog xmlns='urn:oasis:names:tc:entity:xmlns:xml:catalog'>" +
>         "  <rewriteURI uriStartString='http://standards.iso.org'" +
>         "              rewritePrefix='https://standards.iso.org'/>" +
>         "</catalog>";
>
>     String dir = System.getProperty("java.io.tmpdir") + '/';
>     Path schema = Paths.get(dir + "schema.xsd");
>     Files.write(schema, schemaString.getBytes());
>     Path catalog = Paths.get(dir + "catalog.xml");
>     Files.write(catalog, catalogString.getBytes());
>
>     SchemaFactory sf = new XMLSchema11Factory();
>     XMLCatalogResolver r = new XMLCatalogResolver(new String[] { catalog.toUri().toString() });
>     sf.setResourceResolver(r);
>     sf.newSchema(schema.toFile());
>   }
> }
>
>