[MarkLogic Dev General] Adding XML declaration

Ron Hitchens ron at ronsoft.com
Tue Aug 31 08:05:13 PDT 2010


   You can't, really.  The XML declaration is a
processing instruction that indicates how to interpret
the textual representation of XML that follows.  In XQuery,
you're already "inside" and you're creating XML data
structures directly - as opposed to generating a text
file that represents a serialization of XML.

   If, for some reason, it's necessary to place the
XML declaration at the beginning of a serialized XML
that you're producing, you can prepend it to a textual
representation of your XML, but that is technically
different than "adding" it to the XML.

   Try something like this (note that this is actually
producing a sequence of two items rather than a text
file):

xquery version "1.0-ml";

let $prolog := '<?xml version="1.0" encoding="UTF-8"?>'
let $newXML:=
element result
 {
  element header
  {
    element topic1 { "xyz"},
    element topic2 { "abc" },
    element topic3 {
      element subTopic { attribute checked {"true"}, text {""} }
    }
  }
}

return ($prolog, $newXML)

On Aug 31, 2010, at 1:22 PM, judie pearline wrote:

> Hi all,
>  
> I have generated an xml by creating elements.
>  
> xquery version "1.0-ml";
> let $newXML:=  element result
>  {
>   element header
>   {
>     element topic1 { "xyz"},
>     element topic2 { "abc" },
>     element topic3 {
>       element subTopic { attribute checked {"true"}, text {""} }
>     }
>   }
> }
> return $newXML
>  
> How do i add the XML declaration to this created XML.?
>  
> Regards,
> Judie
> 
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general

---
Ron Hitchens {mailto:ron at ronsoft.com}   Ronsoft Technologies
     +44 7879 358 212 (voice)          http://www.ronsoft.com
     +1 707 924 3878 (fax)              Bit Twiddling At Its Finest
"No amount of belief establishes any fact." -Unknown






More information about the General mailing list