How to restrict particular namespace docs to load in MarkLogic?

35 views Asked by At

I have huge number of data and in that I have .svg file format as well, which has xlink namespace, but a few of the svg doc do not have xlink namespace and these documents have to be skipped while loading into MarkLogic.

So, which function can I use to read the namespace to filter or restrict while reading the data from file system.

I am using xdmp:document-get("file path") to read the doc from file system.

Sample xml with xlink NS -

<Books xmlns="http:books.com" xmlns:xlink="http://www.w3.org/1999/xlink">
  <book/>
</Books>

Sample xml without xlink NS -

<Books xmlns="http:books.com" >
  <book/>
</Books>
1

There are 1 answers

4
Mads Hansen On

@Vlad Rose answer should work in most cases. However, it relies upon the instance document having the xlink namespace-prefix. It might not be xlink, but still be the xlink namespace-uri. For instance: xmlns:x="http://www.w3.org/1999/xlink"

You could instead use the namespace:: axis and test if any of the namespaces have the xlink namespace-uri "http://www.w3.org/1999/xlink" like this:

let $doc := xdmp:document-get("file path")
return
  if (exists($doc//namespace::*[. eq "http://www.w3.org/1999/xlink"]))
  then xdmp:document-insert("/path/to/save/document.xml", $doc)
  else 
    (: Document does not have xlink namespace, skip this document :)
    ()