Thursday, December 19, 2013

MarkLogic - Query to find out a sample DOC/XML from database


MarkLogic - Query to find out a sample Document from MarkLogic database to understand the structure of the data. There are two ways to fetch a sample data.

1st way -
                 Query:  fn:doc()[n] 
             
Syntax -  fn:doc()[nth number document that you want to fetch] 

Explanation - fn is a namespace and doc() is a marklogic function which 
comes within fn namespace.

2nd way -  
                    Query:  (/RootNode)[n]

we can fetch a sample data with this way only when we know the root tag/parent tag of the XML(which is in the database).

 Syntax - (/rootnode)[nth number document that you want to fetch]

Explanation - Its totally Marklogic supported Xpath.