Loading TOC...

MarkLogic Server 11.0 Product Documentation
es:init-source

es:init-source(
   $source-nodes as item()*,
   $entity-type-name as xs:string
) as item()*

Summary

This function is deprecated and will be removed in a future release.
Return the root node of an entity instance or document. This function is meant for use in code generated by Entity Services.

Parameters
source-nodes The nodes to be normalized. These can be XML element nodes, JSON object nodes, or document nodes.
entity-type-name The name of the entity type for which this function is to generated a source node.

Usage Notes

If an input node is already canonicalized, this function returns the contents of the canonicalized node. Otherwise, this function returns the node as-is. For example, if you pass in an XML element node or JSON object node, this function returns that node. If you pass in a document node, this function returns the XML element node or JSON object node that is the document root.

You will not usually call this function outside of code generated by Entity Services. The generated code uses this function to normalize references to incoming source data to simplify the code. For example, when you generate an instance converter module, the extract-instance-T function for some entity type T calls this function to normalize its input, which might be an XML element node, a JSON object node, or a document node.

See Also

Example

xquery version "1.0-ml";
import module namespace es = "http://marklogic.com/entity-services"
    at "/MarkLogic/entity-services/entity-services.xqy";
    
let $node := fn:doc('/es-gs/raw/1234.xml')
return ($node, 
        xdmp:describe($node), $node, 
        xdmp:describe(es:init-source($node, 'Person')))

(: Assuming the input document node contains raw source to be used in
 : constructing a Person entity instance, this example returns the
 : following. Note that the input data type is a document node, but the
 : output data type is an element node.
 :  
 : ( <?xml version="1.0" encoding="UTF-8"?>
 :   <person>
 :     <pid>1234</pid>
 :     <given>George</given>
 :     <family>Washington</family>
 :   </person>,
 :   fn:doc("/es-gs/raw/1234.xml"), 
 :   fn:doc("/es-gs/raw/1234.xml")/person )
 :)
(: Returns the following JSON array: ["1", "2"] :)
  

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.