Is it possible to create TDE View in XML metadata

34 Views Asked by At

I am adding set of metadata to XML and i want to expose this data to Power BI through a View (Basically creating a TDE).Is it possible to create TDE View in XML metadata

1

There are 1 best solutions below

0
David Ennis  -CleverLlamas.com On

If by "metadata" and "XML metadata", You are referring to metadata attached to documents, then absolutely. This can be achieved using xdmp:node-metadata-value(). This is documented in the TDE function section under Miscellaneous.

In general, the xdmp:node-xxx() functions are available for TDE usage.

The following example should explain what You are trying to achieve:

    (: Load the sample doc  - storing "Wendy" as the Medata Value "llamaName":)
    xdmp:document-insert("/my-sample.xml", <llama/>, map:entry("metadata", map:entry("llamaName", "Wendy")))
    ; (:Semicolon here on purpose - end of statement:)

    (: Accessing metadata value by referenced node is listed in docs: https://docs.marklogic.com/guide/app-dev/TDE#id_76693) :)
    let $template :=
      <template xmlns="http://marklogic.com/xdmp/tde">
        <context>llama</context>
        <rows>
          <row>
            <schema-name>llama</schema-name>
            <view-name>details</view-name>
            <columns>
              <column>
                <name>name</name>
                <scalar-type>string</scalar-type>
                <val>xdmp:node-metadata-value(., "llamaName")</val>
              </column>
            </columns>
          </row>
        </rows>
      </template>
    return tde:node-data-extract(fn:doc("/my-sample.xml"), $template)

In the result, We can see that Wendy was extracted:

    {
      "/my-sample.xml": [
        {
          "row": {
              "schema": "llama", 
              "view": "details", 
              "data": {
              "rownum": "1", 
              "name": "Wendy" // extracted using xdmp:node-metadata-value()
            }
          }
        }
      ]
    }