1

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>
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
anuj_gupta
  • 131
  • 4

1 Answers1

0

@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 :)
    ()
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
  • Thanks, it helped. But in MarkLogic 4 version when I am using xdmp:document-get("file path") for svg file without xlink namesapce it throws error "No Name Spcae binding". Could you please let me know what could be the reason for this error? – anuj_gupta May 17 '23 at 13:20
  • I'm guessing it's because that document you are trying to read is not well-formed XML. You can't use the `xlink` namespace-prefix if you don't declare the namespace. You could add the option to the `xdmp:document-get()` to repair: `full` – Mads Hansen May 17 '23 at 14:08
  • svg doc does not have xlink namespace, I am not using anywhere but still xdmp:doc-get throws error. – anuj_gupta May 19 '23 at 06:47
  • It may not be the xlink namespace, but some other namespace-prefix being used on content without defining what namespace it belongs to. Post the full error message and it would be helpful to post an example of the offending doc. The second XML in your question does not throw that error. – Mads Hansen May 19 '23 at 11:50