Search code examples
javaschemamarklogic

adding and using xsd from marklogic java api


I`m using Marklogic 9.0.4 with Java Client API 4.0.4.

I'd like to use XSD from the Java API for

  • adding an XSD schema to an existing database
  • using a schema on reading/writing of data

Unfortunately I found no Java API methods for this.

UseCase: Scanning an external XML file we programmatically determine the underlying schema and then load the schema and document into the MarkLogic database. Afterwards we transform the data and validate on read/write on parts of the content.

  • How can I upload a schema from Java?
  • Do I have to know the schema database for the content and load it with an Manager.write(..) method?
  • How do I validate on read from Java?

Solution

  • Yes, the approach from the second bullet is correct approach when using the Java API. You can specify the schema database and write the schema as a document.

    Typically, you would validate on write from Java so the database contains only valid documents.

    My impression is that, if you write an XML document to a content database whose schema database has a schema that validates the root element namespace and name of the document:

    http://docs.marklogic.com/guide/app-dev/loading_schemas#id_70282

    If that impression is incorrect, you can install a transform that validates and returns the input document

    http://docs.marklogic.com/guide/app-dev/loading_schemas#id_42480

    and apply the transform when writing a document

    http://docs.marklogic.com/guide/rest-dev/transforms

    Hoping that helps,