tags:

views:

384

answers:

3

I have the following xml snippet:

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-2.dtd"&gt;
 <sqlMap namespace="reports">

   <typeAlias alias="Header" type="VerificationVO"/>
  </sqlMap>

While trying to parse this xml using:

def sqlMapOld = new XmlParser().parse(file)

I get the following error:

Exception thrown: Connection refused: connect
java.net.ConnectException: Connection refused: connect

This error goes away if I remove the DOCTYPE from the xml snippet. Is there a way to stop groovy script from trying to connect to the URL?

+1  A: 

Try

def sqlMapOld = new XmlParser(false, true).parse(file)

to make it non-validating

ammoQ
+1  A: 

If you're using an appropriate parser, try the load-external-dtd feature.

def parser= new XmlParser()
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
def sqlMapOld= parser.parse(new FileInputStream(file))

Otherwise I think you'd have to set an EntityResolver that does nothing.

bobince
+1  A: 

The parser is attempting to download the external DTD referenced in the DOCTYPE.

You have two options, disable the use of the external DTD or set up your Java/Groovy XML environment to use a local catalog of DTDs.

You can disable the external DTD loading with

def p = new XmlParser()
p.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
p.parse(file)

For information on setting up and using a local catalog see: http://www.sagehill.net/docbookxsl/WriteCatalog.html

http://www.sagehill.net/docbookxsl/UseCatalog.html

Alex Stoddard