On 7/9/08, netBrackets <[EMAIL PROTECTED]> wrote:
> Is there any way to tell the CSVGenerator to use one or more contiguous
> spaces as a seperator? You can tell it to use a single space:
>
> <map:match pattern="importSSV/*">
> <map:generate type="csv" src="inputs/{1}">
> <map:parameter name="separator" value=" "/>
> </map:generate>
> <map:serialize type="xml"/>
> </map:match>
>
> But then when there are contiguous spaces separating values, it increments
> the field number for each space that it finds, e.g. if there are 28 spaces
> between the first field and the second field you get:
>
> <csv:record number="1">
> <csv:field number="1">G005</csv:field>
> <csv:field number="29">OR</csv:field>
> <csv:field number="30">G020</csv:field>
> <csv:field number="31">G021</csv:field>
> </csv:record>
>
> I'd like it to increment the field number only by 1 for each set of
> contigous spaces, so it would output the below instead:
>
> csv:record number="1">
> <csv:field number="1">G005</csv:field>
> <csv:field number="2">OR</csv:field>
> <csv:field number="3">G020</csv:field>
> <csv:field number="4">G021</csv:field>
> </csv:record>
> Thanks,
> Jeff
"Is there any way to tell the CSVGenerator to use one or more
contiguous spaces as a separator?"
No.
(Probably. You did not mention the version of Cocoon. I looked at
the source code from Cocoon-2.1.10 because that was easily accessible
on my PC so the following is based on that version.)
The separator variable is a char. The configuration code is:
this.separator = parameters.getParameter("separator",
DEFAULT_SEPARATOR).charAt(0);
which scares me because a String is being dumped into a char -- feels
like overflow errors should be common . The CSVGenerator compares
each byte of input to the separator; a match calls dumpField() which
increments the field count. This makes sense snce the Generator was
designed for COMMA separated files where every comma distinguishes a
field.
My recommendation is change your algorithm. The CSVGenerator is not
suitable for your purpose.
I am not certain this works (and cannot test today), but try using
map:aggregate setting a parent element and map:part with your data to
move your text into single-element XML. Another possible method is to
use an include (cinclude, xinclude. I forget which is recommended this
week) in an XML file to add your text. Once your text is XML, you can
use XSL to transform the text into better structured XML.
Or copy the CSVGenerator and remove the line that increments the field
count for empty fields:
private void dumpField() throws SAXException {
if (this.buffer.size() < 1) {
// Remove this line so empty fields are not counted.
// this.fieldnumber ++;
return;
}
OT: If you customize the Generator, you can also remove the namespaces
by changing the constant to the empty string:
public static final String NAMESPACE_PREFIX = "";
HTH,
solprovider
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]