Jump to content
Sign in to follow this  
Kahor

SAX validator

Recommended Posts

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 ?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...