groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From garneke <kenton.gar...@issinc.com>
Subject StreamingMarkupBuilder attempting to stream input strips CR & LF characters.
Date Tue, 31 May 2016 17:16:30 GMT

I need to wrap an existing file's contents within an XML tag.  In this case
the file being wrapped is also XML.
I would like to minimize the memory requirements as the input file maybe
large.  With the StreamingMarkupBuilder class I can include a Reader as
input and bind to an output file.  This seems to be the ideal solution,
however, this is modifying the original files contents.  It is escaping all
of the special XML characters but stripping CR and LF characters.  I cannot
alter the wrapped contents like this.

Does anyone have a suggestion.  Here is some sample code of what I am
attempting.
(Note:  the metadata is just a GPathResult object containing required
metadata .)
--------------------------------------------------------------------
Reader inputReader = inputFile.newReader("UTF-8");
def sbuilder = new StreamingMarkupBuilder()
sbuilder.encoding = 'UTF-8';

sbuilder.bind{
  mkp.pi('xml':['version':'1.1', 'encoding':'UTF-8'])
  mkp.declareNamespace( 'xsi' : "http://www.w3.org/2001/XMLSchema" )
  'TM'({
	mkp.yield metadata.get()
	'Payload'(['length':"${(inputFile.length()-skipVal)}"], inputReader)
  })
}.writeTo( outWriter );

outWriter.close();
inputReader.close();




--
View this message in context: http://groovy.329449.n5.nabble.com/StreamingMarkupBuilder-attempting-to-stream-input-strips-CR-LF-characters-tp5733139.html
Sent from the Groovy Users mailing list archive at Nabble.com.

Mime
View raw message