Hi, Timely that CSV is being discussed. I have a question that has been stumping me... I want to be able to output something like: "text here", "<div><a href=""http://basex.org"">text, and more</a></div>", "text here again" What's stumping me is being able to double-quote escape the quotation marks that are in my markup. I've tried serializing my elements and then replacing the single quotes of the attributes to double quotes but then when I try to write that to a file (either serializing as text or xml) the tags are escaped to < etc. Here is a bit of what I've tried: declare option output:indent 'no'; declare variable $txtSer := <serialization-parameters xmlns="http://www.w3.org/2010/xslt-xquery-serialization"> <method value="text"/> </serialization-parameters>; declare variable $xmlSer := <serialization-parameters xmlns="http://www.w3.org/2010/xslt-xquery-serialization"> <method value="xml"/> <indent value="no"/> </serialization-parameters>; declare variable $outFile := 'out2.csv'; declare variable $xml := <sample><a href="http://basex.org">text, and more text</a></sample>; declare function local:writeEOL() { file:append($outFile, ' ', $txtSer) }; (: Trying to output markup so I can eventually output something like: "text", "<div><a href=""http://basex.org"">text, and more</a></div>", "text" :) ( file:append($outFile, $xml, $txtSer), (: only text of xml out :) local:writeEOL(), file:append($outFile, $xml, $xmlSer), (: xml out but can't escape quotes :) local:writeEOL(), file:append($outFile, serialize($xml), $txtSer), (: tags escaped :) local:writeEOL(), file:append($outFile, serialize($xml, $txtSer), $txtSer), (: only text out :) local:writeEOL(), file:append($outFile, serialize($xml), $xmlSer), (: tags escaped :) local:writeEOL(), file:append($outFile, serialize($xml), $txtSer), (: tags escaped :) local:writeEOL(), file:append($outFile, concat('<![CDATA[', serialize($xml), ']]>'), $xmlSer), (: tags escaped :) local:writeEOL(), file:append($outFile, concat('<![CDATA[', serialize($xml), ']]>'), $txtSer), (: tags escaped :) local:writeEOL(), file:append($outFile, '<,<', $txtSer) (: both are escaped :) ) I don't seem to be able to output the markup in either text or xml mode. What am I doing wrong? Thanks! Kevin
On Mon, Sep 26, 2011 at 12:19 PM, Kevin S. Clarke <ksclarke@gmail.com> wrote:
I don't seem to be able to output the markup in either text or xml mode. What am I doing wrong?
Oops, that was incorrect... I can output the markup in xml mode, of course... I just can't double escape the quotes that way. I'd be good if I could output the xml using single quotes for the attributes <href='http://basex.org'> but single quotes in my XQuery are output using double ones. Kevin
Oh, I think I may have found the answer... it seems I want the 'raw' serializer instead of the text one. That will output <, >, etc. without escaping it. I should be able to serialize the xml to string, double-quote the single quotes, and then write to file using 'raw'... Kevin On Mon, Sep 26, 2011 at 12:22 PM, Kevin S. Clarke <ksclarke@gmail.com> wrote:
On Mon, Sep 26, 2011 at 12:19 PM, Kevin S. Clarke <ksclarke@gmail.com> wrote:
I don't seem to be able to output the markup in either text or xml mode. What am I doing wrong?
Oops, that was incorrect... I can output the markup in xml mode, of course... I just can't double escape the quotes that way. I'd be good if I could output the xml using single quotes for the attributes <href='http://basex.org'> but single quotes in my XQuery are output using double ones.
Kevin
Hi Kevin,
Oh, I think I may have found the answer... it seems I want the 'raw' serializer instead of the text one. That will output <, >, etc. without escaping it. I should be able to serialize the xml to string, double-quote the single quotes, and then write to file using 'raw'...
yes, you were faster.. Those two examples should give you the expected result: file:write('test1', '<x/>', map { 'format':='no' }) file:write('test2', '<x/>', map { 'method':='raw' }) Both serialization parameters are BaseX-specific [1], as the official standard doesn't offer any help here.. Christian [1] http://docs.basex.org/wiki/Serialization
participants (2)
-
Christian Grün -
Kevin S. Clarke