XML : Groovy - creating a valid XML file is not possible with single quote

I'm using XmlTemplateEngine to create several XML files. Currently I have a case where the XML generation fails. It fails if a single quote is used as a value of a xml tag.

Here is the method:

      public static void mergeXmlTemplateToFile(File src, File dest, Map bindings){      File part = new File(FileUtils.getTempDirectoryPath()+"/"+src.name)      new XmlTemplateEngine().createTemplate(src).make(bindings).writeTo(new PrintWriter(part))      XMLMerger merger = new XMLMerger(part, dest)      merger.merge();      part.delete()  }    

call:

  BuildUtils.mergeXmlTemplateToFile(new File(template+"area/cms/sharepoint.xml"), new File(output+"area/conf/config_complete.xml"), [servers:Builder.config.area.cms.sharepoint.servers, hostnames:Builder.config.server.hostnames])    

The problem is, that the temporary file and the value of date.format has single quotes. The value of date.format need the single quotes. XmlTemplateEngine cannot use double quotes. I cannot use the temporary file for the next steps, because it's not valid. Temporary file:

   <config>    <cms>      <type name='SharePoint'>        <host ident=''>          <property name='user' value='demo'/>          <property name='password' value='pass'/>          <property name='domain' value='example.com'/>          <property name='date.format' value='yyyy-MMdd'T'HH:mm:ss'Z''/>        </host>      </type>    </cms>  </config>    

I have tried to use MarkupTemplateEngine instead of XmlTemplateEngine, but I had no success. http://www.groovy-lang.org/templating.html#_the_markuptemplateengine

  TemplateConfiguration config = new TemplateConfiguration();     config.useDoubleQuotes = true;        MarkupTemplateEngine engine = new MarkupTemplateEngine(config);   engine.createTemplate(src).make(bindings).writeTo(new PrintWriter(part))    

Thanks

No comments:

Post a Comment