MarkLogic 10 Product Documentation
op.xmlElement

op.xmlElement(
   name as String,
   [attributeValue as attributeNode],
   [childContent as String]
) as elementNode

Summary

This function constructs an XML element with the name (which can be a string or QName), zero or more attributes, and child content. The child content can include a sequence or array of atomic values or an element, comment, or processing instruction nodes. Atomic values are converted to text nodes.

Parameters
name The string or QName for the constructed element.
attributeValue Any element attributes returned from op.xmlAttribute, or null if no attributes.
childContent A sequence or array of atomic values or an element, a comment from op.xmlComment, or processing instruction nodes from op.xmlPI.

Example

const op = require('/MarkLogic/optic');

const literals = op.fromLiterals([
            {row:1, gp: 1, nm:"alpha", str:"a", num:10, bool:true},
            {row:2, gp: 1, nm:"beta", str:"b", num:20, bool:false},
            {row:3, gp: 2, nm:"gamma", str:"c", num:30, bool:true},
            {row:4, gp: 2, nm:"delta", str:"d", num:40, bool:false}
	          ])
literals.where(op.eq(op.col('gp'), 1))
        .select(['row',
                 op.as('node',
                       op.xmlDocument(
                          op.xmlElement(op.col('nm'),
                                        null,
                                        op.xmlElement(op.col('str'),
                                        null,
                                        op.xmlText(op.col('bool')))
	                       )
	                )),
                 op.as('kind', op.xdmp.nodeKind(op.col('node')))
               ])
        .orderBy('row')
        .result();
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy