1

I have a situation where I need to parse an XML response using Karate, but the reference to the DTD is not accessible. In other words is DTD required for parsing?

Is there a way around this?

Amir Ghahrai
  • 618
  • 1
  • 7
  • 22

1 Answers1

0

To be honest I'm not sure. Are you facing an error if the XML has a DTD ?

Then maybe we need to make a change to Karate to skip DTD validation. I think this Stack Overflow question is relevant: Make DocumentBuilder.parse ignore DTD references

If you can raise a ticket and provide a sample XML that has a DTD, we can fix this pretty quickly.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Thanks Peter. Yes, if the XML has Then it tries to validate XML against that DTD – Amir Ghahrai Nov 14 '17 at 16:44
  • @AmirGhahrai just fixed this in dev. not sure if you are able to build from GitHub and try, I need to go offline now - but I can make a temp release tomorrow. – Peter Thomas Nov 14 '17 at 17:03
  • Thanks @PeterThomas A temp release would be much appreciated. Currently, I don't seem to be able to find a workaround on this. I tried sending the response to a Java function to remove the DOCTYPE but as soon as Karate sees that line it fails the test immediately, so I can't do anything further with the response. – Amir Ghahrai Nov 14 '17 at 21:06
  • OK, just now I found a workaround! I declare the response as a text (sometimes text is very useful :-D ) Then I send that to the Java function to remove the DOCTYPE and then convert back to XML. Seems to be working for now. – Amir Ghahrai Nov 14 '17 at 21:15
  • @AmirGhahrai great ! `string` should be better instead of `text` there is a very subtle difference. – Peter Thomas Nov 15 '17 at 02:39