es.instanceFromDocument( entity-document as Node ) as Sequence
This function is deprecated and will not be supported in MarkLogic 11.
Extract an in-memory entity instance from its envelope document
as a
JavaScript object.
Parameters | |
---|---|
entity-document | An envelope document that contains a canonical entity instance(s). |
Use this function to get an in-memory instance representation from
an envelope document that contains canonical instance data within
es:instance
elements. An envelope document is usually
created using the extract instance function in an instance converter
module created by the Entity Services API.
An in-memory instance contains nested objects if those objects were persisted as nested XML elements. This function returns a sequence of one or more instances, as JavaScript objects.
To extract an entity from an envelope document as an XML node, use es.instanceXmlFromDocument instead. To extract an entity from an envelope document as a JSON object, use es.instanceJsonFromDocument instead.
/* Assume /es-gs/env/1234.xml is an envelope document with * the following contents: <es:envelope xmlns:es="http://marklogic.com/entity-services"> <es:instance> <es:info> <es:title>Person</es:title> <es:version>0.0.1</es:version> </es:info> <Person> <id>1234</id> <firstName>George</firstName> <lastName>Washington</lastName> <fullName>George Washington</fullName> </Person> </es:instance> <es:attachments> <person> <pid>1234</pid> <first>George</first> <last>Washington</last> </person> </es:attachments> </es:envelope> */ const es = require('/MarkLogic/entity-services/entity-services'); fn.head( es.instanceFromDocument(cts.doc('/es-gs/env/1234.xml')) ); /* Returns the following, as a JavaScript object { "$type": "Person", "id":1234, "firstName":"George", "lastName":"Washington", "fullName":"George Washington" } */