开发者

java.net.ConnectException : Validating Xml against XSD : local machine

I need to validate an XML against a local XSD and I do not have a internet connection on the target machine (on which this process runs). The code look like below :

SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

File schemaLocation = new File(xsd);

Schema schema = factory.newSchema(schemaLocation);

Validator validator = schema.newValidator();

Source source = new StreamSource(new BufferedInputStream(new FileInputStream(new File(xml))));

validator.validate(source);

I always get a java.net.ConnectException when validate() is called.

Can y开发者_开发百科ou please let me know what is not being done correctly ?

Many Thanks. Abhishek


Agreed with Mads' comment - there are likely many references here that will attempt outgoing connections to the Internet, and you will need to download local copies for them. However, I'd advise against changing references within the XML or schema files, etc. - but instead, provide an EntityResolver to return the contents of your local copies instead of connecting out to the Internet. (I previously wrote a little bit about this at http://blogger.ziesemer.com/2009/01/xml-and-xslt-tips-and-tricks-for-java.html#InputValidation.)

However, in your case, since you're using a Validator instead of Validator.setResourceResolver(...) - and pass-in a LSResourceResolver, before calling validate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜