insert arbitrary files

Wednesday, 9 May 2012 · 9 messages · last reply 10 May 2012
J
jidanni9 May 2012 15:28 #
How does one insert an arbitrary file. doc('q') parses it. How does one just, you know, #include q as in C?
CG
Christian Grün9 May 2012 15:32 #
Quoted text · jidanni · 6 lines
On Wed, May 9, 2012 at 3:28 PM, <jidanni at jidanni.org> wrote: > How does one insert an arbitrary file. > doc('q') > parses it. How does one just, you know, > #include q > as in C?
Hm, where do you want to include your file? Do you have a small, concise example? C.
J
jidanni9 May 2012 15:56 #
Quoted text · Christian Grün · 1 line
>>>>> "CG" == Christian Grün <christian.gruen at gmail.com> writes:
CG> Hm, where do you want to include your file? Do you have a small, CG> concise example? CG> C.
  <body>
  {insert_file("blob_of_bytes")}
    <h1>
CG
Christian Grün9 May 2012 15:57 #
Quoted text · jidanni · 3 lines
> <body> > {insert_file("blob_of_bytes")} > <h1>
J
jidanni9 May 2012 20:05 #
Quoted text · Christian Grün · 1 line
>>>>> "CG" == Christian Grün <christian.gruen at gmail.com> writes:
CG> ..try file:read-text() or file:read-binary(): CG> http://docs.basex.org/wiki/File#file:read-text They don't work. The first ruins all brackets it encounters, escaping them. The latter just returns base64. There is no way to get the darn file just inserted without mangling.
CG
Christian Grün9 May 2012 20:11 #
Quoted text · jidanni · 1 line
> The first ruins all brackets it encounters, escaping them.
That's what XML serialization is about; everything else would be invalid. Once again, you may want to switch to "text" as output method to avoid escaping: http://docs.basex.org/wiki/Serialization Christian
J
jidanni9 May 2012 20:24 #
Quoted text · Christian Grün · 2 lines
>>>>> "CG" == Christian Grün <christian.gruen at gmail.com> writes: >> The first ruins all brackets it encounters, escaping them.
CG> That's what XML serialization is about; everything else would be CG> invalid. Once again, you may want to switch to "text" as output method CG> to avoid escaping: CG> http://docs.basex.org/wiki/Serialization It is a mixed document. I just need to import my english.html that is created by txt2html. I need a way to turn of the mangling.
declare namespace atom='http://www.w3.org/2005/Atom';
declare option db:parser "html";
declare option db:htmlopt "method=html,nons=true";
declare option output:method "html";
declare option output:version "4.01";
declare option output:doctype-public "-//W3C//DTD HTML 4.01//EN";
declare option output:doctype-system "http://www.w3.org/TR/html4/strict.dtd";
declare option output:include-content-type "yes";
<html lang="zh-tw">
  <head>
    <title>jidanni2 YouTube™ 播放清單 playlists</title>
  </head>
  <body>
  {file:read-text("english.html")}
    <h1>
      <a href="http://www.youtube.com/user/jidanni2">jidanni2 YouTube™</a> 播放清單 playlists</h1>
    <ol>
      <li>
        <a href="http://www.youtube.com/playlist?list=LLu1NBeZA_KwhPyXJKLAfDsQ">[喜歡的影片 Liked videos]</a>
      </li>
{
for $e in doc("playlists.xml")/atom:feed/atom:entry,
    $t in $e/atom:title/text()
    where $t ne "testing"
    order by $t
return
      <li>
        <a href="{$e/atom:link[@rel="alternate"][@type="text/html"]/@href}">{$t}</a>
      </li>
}
    </ol>
    <hr/>
    <address>
      <a href="../index.html">積丹尼</a>(<a href=
      "../index_en.html">Dan Jacobson</a>)
    </address>
    <p>Updated {adjust-date-to-timezone(current-date(), ())} 製</p>
  </body>
</html>
CG
Christian Grün9 May 2012 21:34 #
Note that XQuery was designed to *always* generate well-formed XML fragments - which is why it's hardly possible to create arbitrary copy-and-pasted results, as one is used to from other scripting languages. If you still want to do so, you will have to resort to the "text" output method, and compose your results via serialize() and numerous string operations. This is of course possible, but it's somewhat contrary to the original paradigm of XML languages, and XQuery may not be the best language for such a use case.
Quoted text · jidanni · 59 lines
On Wed, May 9, 2012 at 8:24 PM, <jidanni at jidanni.org> wrote: >>>>>> "CG" == Christian Grün <christian.gruen at gmail.com> writes: >>> The first ruins all brackets it encounters, escaping them. > > CG> That's what XML serialization is about; everything else would be > CG> invalid. Once again, you may want to switch to "text" as output method > CG> to avoid escaping: > > CG> http://docs.basex.org/wiki/Serialization > > It is a mixed document. > > > I just need to import my english.html that is created by txt2html. > > > I need a way to turn of the mangling. > > > declare namespace atom='http://www.w3.org/2005/Atom'; > declare option db:parser "html"; > declare option db:htmlopt "method=html,nons=true"; > declare option output:method "html"; > declare option output:version "4.01"; > declare option output:doctype-public "-//W3C//DTD HTML 4.01//EN"; > declare option output:doctype-system "http://www.w3.org/TR/html4/strict.dtd"; > declare option output:include-content-type "yes"; > <html lang="zh-tw"> > <head> > <title>jidanni2 YouTube™ 播放清單 playlists</title> > </head> > <body> > {file:read-text("english.html")} > <h1> > <a href="http://www.youtube.com/user/jidanni2">jidanni2 YouTube™</a> 播放清單 playlists</h1> > <ol> > <li> > <a href="http://www.youtube.com/playlist?list=LLu1NBeZA_KwhPyXJKLAfDsQ">[喜歡的影片 Liked videos]</a> > </li> > { > for $e in doc("playlists.xml")/atom:feed/atom:entry, > $t in $e/atom:title/text() > where $t ne "testing" > order by $t > return > <li> > <a href="{$e/atom:link[@rel="alternate"][@type="text/html"]/@href}">{$t}</a> > </li> > } > </ol> > <hr/> > <address> > <a href="../index.html">積丹尼</a>(<a href= > "../index_en.html">Dan Jacobson</a>) > </address> > <p>Updated {adjust-date-to-timezone(current-date(), ())} 製</p> > </body> > </html> >
J
jidanni10 May 2012 06:50 #
Quoted text · Christian Grün · 1 line
>>>>> "CG" == Christian Grün <christian.gruen at gmail.com> writes:
CG> XQuery may not be the best language for such a use case. OK, I put a @@@ marker in a comment to trigger sed to read it in in my Makefile lyrics.html:playlists.xquery playlists.xml english.html basex $< |sed '/@@@/r english.html' > $@ validate $@ w3m -dump $@

⚡Generated with XQuery