Kahor Posted June 17, 2008 Share Posted June 17, 2008 There is a copy of this topic in java forum, since I do not exactly know where this problem belong, it is xml related but I think the issue is more java based so...Moderator feel free to delete the one topic in wrong place, thx.Hello,I have a little problem in my java SAX parser, I want to change the baseURI in my validator, so that my validator use a specific URL for xml files.For this, I use the setResourceResolver method of the Validator class, it takes a LSResourceResolver as argument :http://java.sun.com/j2se/1.5.0/docs/api/ja...sourceResolver) public abstract void setResourceResolver(LSResourceResolver resourceResolver) now LSResourceResolver is an interface (http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/ls/LSResourceResolver.html) with the LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) method, so what I do is ...Schema schema = compileSchema(xmlSchema);Validator validator = schema.newValidator();LSResourceResolver resourceResolver = new LSResourceResolver() { public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { LSInput ls = new LSInput(); ls.setBaseURI(url.getFile); //url is a final URL return ls; }}; validator.setResourceResolver(resourceResolver);validator.validate(new StreamSource(xmlFile.openStream()));... Right ? No, cuz LSInput is an interface too (http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/ls/LSInput.html)...so what now ? Do I try to implement the interface LSInput inside the LSResourceResolver interface ? Do I write over the setBaseURI method ?I tried to do this : ...Schema schema = compileSchema(xmlSchema);Validator validator = schema.newValidator();LSResourceResolver resourceResolver = new LSResourceResolver() { public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { LSInput ls = new LSInput(){ public InputStream getByteStream() { return null; } public boolean getCertifiedText() { return false; } public String getSystemId() { return null; } public String getPublicId() { return null; } public String getEncoding() { return null; } public Reader getCharacterStream() { return null; } public String getStringData() { return null; } public String getBaseURI() { return null; } public void setPublicId(String publicId) { } public void setCharacterStream(Reader characterStream) { } public void setSystemId(String systemId) { } public void setByteStream(InputStream byteStream) { } public void setStringData(String stringData) { } public void setBaseURI(String baseURI) { } public void setEncoding(String encoding) { } public void setCertifiedText(boolean certifiedText) { } }; ls.setBaseURI(url.getFile()); return ls; } }; validator.setResourceResolver(resourceResolver); validator.validate(new StreamSource(xmlFile.openStream()));... but the setBaseURI method is empty, I am not sure if it's supposed to work, I get a java.net.MalformedURLException exception (but if I leave the resolveResource method with a return null, no such error, so ls isn't considered a real LSInput ?), any idea ? Link to comment Share on other sites More sharing options...
Kahor Posted July 11, 2008 Author Share Posted July 11, 2008 In case anyone ever cared, it works by rewriting the methods called in the interface, but I scratched all this validator thing and now use the .setSchema, .setValidating properties to validate my xml schema while parsing Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.