I had a look at the code in StringUtils.xmlNode and saw that just
adding an option won't do the trick. The functions are quite focused
on creating text and not XML-elements and formatting is directly done
in this function as well. In higher nodes it is not certain if line
ends in the content should be treated different or not.
For my use-case I now will create some aliases, that will convert the
line ends and re-add them later. Now I know how the functions work, I
can "remedy" it for my use-case.
For me it proves again the convenience of creating new functions with
simple Java-code in H2 :)
Here is what I probably am going to use:
drop alias if exists XMLCONVERTLINEENDS;
CREATE ALIAS XMLCONVERTLINEENDS AS $$ String xmlConvertLineEnds(String
s) { return s.replace("\r", "$chr13$").replace("\n", "$chr10$"); } $$;
drop alias if exists XMLREADDLINEENDS;
CREATE ALIAS XMLREADDLINEENDS AS $$ String xmlReAddLineEnds(String s)
{ return s.replace("$chr13$", "\r").replace("$chr10$", "\n"); } $$;
call
XMLREADDLINEENDS(
XMLNODE(
'a',
XMLATTR('href', 'http://h2database.com'),
XMLNODE(
'b',
null,
XMLCONVERTLINEENDS(
XMLTEXT('H' || CHR(13) || CHR(10) || '2')
)
)
)
)
Greetz,
Remco
On 16 dec, 16:51, Duvel <[email protected]> wrote:
> Hello,
>
> I'm still not sure if the parser is going to handle the extra
> whitespace correct yet, I'm still waiting to find that out.
>
> But I don't think the solution would be in escaping the newlines,
> because this should be undone in the parser and it could be beyond
> your control.
>
> Maybe an option for XMLTEXT for not adding whitespace could be a
> possibilty.
>
> Greetz,
>
> Remco
>
> On 12 dec, 19:07, Thomas Mueller <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > For my use case, it's a feature :-) The generated XHTML looks better.
>
> > Is it really a problem for you? Specially when generating XHTML.
>
> > By the way, you should use XMLTEXT or XMLCDATA to avoid XML injection:
>
> > CALL XMLNODE('a', XMLATTR('href', 'http://h2database.com'),
> > XMLNODE('b', null, XMLTEXT('H' || CHR(13) || CHR(10) || '2')));
>
> > Maybe the newline should be escaped (using &#x) when using XMLCDATA, what
> > do you think?
>
> > Regards,
> > Thomas
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.