Reputation: 3
I am trying to append one xml file to another using groovy XMLParser, but seems like as they have DOCTYPE define in their xml file, it is giving issue.
Here is the code , there is one XML file name cache1.xml:
<?xml version="1.0" ?>
<!DOCTYPE cache SYSTEM "cachespec.dtd">
<!-- All Commerce default command caching rules have been relocated under InitializationServlet.war -->
<cache>
<!-- Please insert your servlet/jsp cache rules here.-->
</cache>
and another cache file named cache2.xml
<?xml version="1.0" ?>
<!-- All Commerce default command caching rules have been relocated under InitializationServlet.war -->
<cache>
<!-- Please insert your servlet/jsp cache rules here.-->
</cache>
I want to merge cache2.xml to cache1.xml but getting issue :
[Fatal Error] cachespec.xml:2:10: DOCTYPE is disallowed when the feature "http://apache.org/xml/features/disallow-doctype-decl" set to true. DOCTYPE is disallowed when the feature "http://apache.org/xml/features/disallow-doctype-decl" set to true.
Any idea ?
Upvotes: 0
Views: 463
Reputation: 38865
The problem is that XmlParser out of the box does't allow DOCTYPE directives in XML. In order to enable DOCTYPE aware parser you need to use a different constructor:
new XmlParser( false, false, true ).parse( xml )
But you'll also need to set the system property on the JVM -Djavax.xml.accessExternalDTD=all
so it can resolve external DTDs. If you don't need DTD aware parser or you don't have the external DTD file you need then you could just remove the DOCTYPE at the top of the XML document and move on.
Upvotes: 0