Hi Helen,

Take a look at the docs for xdmp:eval() and xdmp:invoke(), specifically the database option. Here's a quick example.

   xdmp:eval(
      'xquery version "1.0-ml";
       declare variable $URI as xs:string external;
       fn:doc($URI)
      ', (xs:QName("URI"), "/foo.xml"),
      <options xmlns="xdmp:eval">
        <database>{xdmp:database("OtherDatabase")}</database>
      </options>)

Note that a cross database eval/invoke will always run as a separate transaction (either a second update, or at a different commit timestamp if it's a query).

I've found the xdmp:function capability very useful in this context to call a function in the context of a different database.

   declare function local:foo($arg1, $arg2) { ... };

   xdmp:eval(
      'declare variable $FN as xdmp:function external;
       declare variable $ARG1 external;
       declare variable $ARG2 external;
       xdmp:apply($FN,$ARG1,$ARG2)
      ', (xs:QName("FN"), xdmp:function("local:foo"),
          xs:QName("ARG1"), $x,
          xs:QName("ARG2"), $y),
      <options xmlns="xdmp:eval">
        <database>{xdmp:database("OtherDatabase")}</database>
      </options>)

Both of those code snippets are from memory, so they may not be quite right.

Wayne.


On 08/19/2010 10:41 AM, helen chen wrote:
I'm inside marklogic and in database A, if I want to get some document from another 
database B and do something,  like if I want to get the list of document with uri  
pattern "/a/b/*xml" from database B,   how can I do it?

Thanks, Helen
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

--
Wayne Feick
Lead Engineer
MarkLogic Corporation
Phone +1 650 655 2378
Cell +1 408 981 4576
www.marklogic.com

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to