httpbuilder icon indicating copy to clipboard operation
httpbuilder copied to clipboard

setting xml parser features not possible

Open davecramer opened this issue 10 years ago • 3 comments

Using groovy 2.3.7 I get the following error when parsing an xml file with a DOCTYPE

DOCTYPE is disallowed when the feature "http://apache.org/xml/features/disallow-doctype-decl" set to true

Is there a way to set the parser features ?

davecramer avatar Jan 20 '15 12:01 davecramer

I am encountering this issue too. Any workarounds?

andrhahn avatar Mar 06 '15 03:03 andrhahn

I'm also getting this with Groovy 2.3.9. This will be a show stopper for anyone trying to use http builder in Gradle 2.x plugins.

stevesaliman avatar Mar 20 '15 20:03 stevesaliman

I figured out a a workaround for this issue. I had to replace the default XML parser with one that can handle the doctype in an XML file. The following code should do the trick:

restClient.parser.'application/xml' = { response ->
  def slurper = new XmlSlurper(false, false)
  slurper.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false)
  return slurper.parse(response.entity.content)
}

In my case, restParser is an instance of RESTClient, but I think that instances of HTTPBuilder would work the same way.

stevesaliman avatar Mar 20 '15 21:03 stevesaliman