This should do the trick:
document {
<result>
     <lst name="first">
         <elem1>1</elem1>
          <elem2>2</elem2>
     </lst>
</result>
}

Case you are interested about creating other PIs (or comments):

document {
  comment {'now this is a comment'},
  processing-instruction pi { 'textual content' },
  element rootNode {
    attribute id {'5'},
    text { 'The End!' }
  }
}

Nuno

On Mon, Feb 28, 2011 at 10:20 AM, Geert Josten <[email protected]>wrote:

> Hi Rojan,
>
>
>
> Personally, I wouldn’t add the xml-pi to the value returned from the
> function, but in the main body, since then you know for sure where the
> result is being sent to. But you could do it this way:
>
>
>
> xquery version "1.0-ml";
>
> (: buffer 1 :)
>
>
>
> declare function local:getSearchResult() as element(){
>
> <result>
>
>      <lst name="first">
>
>          <elem1>1</elem1>
>
>           <elem2>2</elem2>
>
>      </lst>
>
> </result>
>
> };
>
>
>
> declare function local:getResult() as item()+
>
> {
>
>   '<?xml version="1.0" encoding="utf-8"?>',
>
>   local:getSearchResult()
>
> };
>
>
>
> xdmp:set-response-content-type("application/xml"),
>
> xdmp:set-response-encoding("utf-8"),
>
> local:getResult()
>
>
>
> Kind regards,
>
> Geert
>
>
>
> *Van:* Rojan K K [mailto:[email protected]]
> *Verzonden:* maandag 28 februari 2011 9:53
> *Aan:* General MarkLogic Developer Discussion
> *CC:* Geert Josten
> *Onderwerp:* Re: [MarkLogic Dev General] prepend the xmlversion identifier
> with the resulted xml
>
>
>
> Hi Geert,
>
>
>
> Thanks for your support.
>
>
>
> But my actual problem is, i couldnt able to add processing instruction to
> the element.
>
>
>
> I am using a search functionality and has to append PI with  resulted xml
>
> sample code structure is  given below
>
>
>
> declare function ns:getResult(--- params--) as element()*
>
> {
>
> let $resultXml=ns:getSearchResult(--params--)
>
> return ($resultXml)
>
> }
>
> so that i am getting $resultXml as
>
>
>
>  <result>
>
>      <lst name="first">
>
>          <elm1>1<elem1>
>
>           <elm2>2<elem2>
>
>      </lst>
>
>        --
>
>        --
>
> </result>
>
> and output xml will be the same
>
> but expected output is as given below
>
> <?xml version="1.0" encoding="UTF-8>
>
>  <result>
>
>      <lst name="first">
>
>          <elm1>1<elem1>
>
>           <elm2>2<elem2>
>
>      </lst>
>
>        --
>
>        --
>
> </result>
>
> Please advice me how i can achieve this expected result by adding
> processing instruction to the element.
>
>
>
> regards,
>
> Rojan
>
>
>
> On Mon, Feb 28, 2011 at 12:55 PM, Geert Josten <[email protected]>
> wrote:
>
> Hi Rojan,
>
>
>
> If you precede your root element with a processing-instruction, comment or
> string, you are returning a multi-item sequence. You will have to at least
> add a + or * behind the return type. Secondly, a pi or string is not an
> element. Use item() instead.
>
>
>
> By the way, are you sure that MarkLogic Server doesn’t prepend the xml pi
> itself upon returning results? You can set the encoding of the response
> using xdmp:set-response-encoding (
> http://developer.marklogic.com/pubs/4.2/apidocs/AppServerBuiltins.html#xdmp:set-response-encoding)
> ..
>
>
>
> Kind regards,
>
> Geert
>
>
>
> *Van:* [email protected] [mailto:
> [email protected]] *Namens *Rojan K K
> *Verzonden:* maandag 28 februari 2011 7:52
> *Aan:* [email protected]
> *Onderwerp:* [MarkLogic Dev General] prepend the xmlversion identifier
> with the resulted xml
>
>
>
> Hi,
>
>
>
> I would like to prepend the xml version identifier and encoding(<?xml
> version="1.0" encoding="UTF-8"?>) with the ouput xml which i am giving as
> the result of a method having element() return type.I tried to append it
> as string then its showing" Invalid coercion: "<?xml version=&quot;1.0&quot;
> encoding=&quot;UTF-8&quot;?>" as element() " since its not node type. Please
> help me to resolve this.
>
>
>
>
>
> Regards,
>
> Rojan
>
>
>
>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
>
>
>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to