Forum OpenACS Development: Re: Generating an XML file from a Query

Posted by Neophytos Demetriou on
Not sure there is a procedure to do it for you but you can come up with one using tdom by following the example below:

set records {{{Ayn Rand} {Atlas Shrugged}} {{Leo Tolstoy} {War and Peace}}}
set doc [dom createDocument "library"]
set root [$doc documentElement]
foreach rec $records {
  lassign $rec author title
  set el [$doc createElement "book"]
  set field1 [$doc createElement "author"]
  set text1 [$doc createTextNode $author]
  $field1 appendChild $text1
  set field2 [$doc createElement "title"]
  set text2 [$doc createTextNode $title]
  $field2 appendChild $text2
  $el appendChild $field1
  $el appendChild $field2
  $root appendChild $el
puts [$doc asXML]
Here's what the output looks like:

        <author>Ayn Rand</author>
        <title>Atlas Shrugged</title>
        <author>Leo Tolstoy</author>
        <title>War and Peace</title>
Of course, you can just append to string. You could also use appendFromScript (which I prefer) but it is somewhat more cumbersome to setup.
Posted by Juan Carlos on
Thanks that will do.