简体   繁体   中英

Load multiple XML file (MarkLogic)

I need to make search in many files but don't want to write the names of them in the query. In my case, I need to query 500 XML files with quite different names each. So, Is there any way.

I can say:

for $x in doc("ALL XML files under a specific directory")
return $x/Something

I'm using Ubuntu and MarkLogic5

If your documents are actually in a "directory" ... (ie they are of a form of URL like " /a/b/c.xml ") then you can use xdmp:directory()

http://docs.marklogic.com/xdmp:directory

for $x in xdmp:directory("/a/b/") 
return $x/something

Mads' answer is correct if by "directory" you mean a Marklogic directory. If you mean a filesystem path, then the answer is that before Marklogic can process the documents, you need to load them into the database.

To do this, look at port 8000 on the ML machine (localhost?) and select the "load content" option on that page. This will allow you to select a filesystem directory to load documents from.

By changing "document settings" before loading you can also select how much (if any) of that filesystem path should be maintained as part of the docuemnt URIs in Markloic and assign a collection to all loaded documents. I'd encourage you to do both of these; they will simplify referring to all of these documents exclusively once they're loaded (either for querying or deletion once you're done with them.)

Once the documents are loaded, you can query them using xdmp:directory() , fn:collection() or any other method you like.

From Marklogic you can look at the file system if the user has the correct permissions. You could load data into marklogic this way but wouldn't you shouldnt query for data this way.

Here is an example and might help you out for what your looking for.

 declare namespace dir = "http://marklogic.com/xdmp/directory";

  for $file in xdmp:filesystem-directory("/home/user/desktop/xml/")/dir:entry

  return xdmp:filesystem-file($file/dir:filename) 

For searching files within a particular directory, take a look at cts:directory-query() and the examples in the documentation.

http://docs.marklogic.com/cts:directory-query

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM