Table of Contents

XML

This is the documentation of the XML module that enables use programs to define their own native XML tags. For instance:

Use require( hop.xml )

This module also implements an XML pre-processor ables to load complete XML documents.

Use require( "./example.xml", hop.xml )

This will return the root element (as created by createElement) contained in the XML document ./example.xml.

Functions

xml.createElement( tag, attributes, children )

Creates a native tag xml element. Its attributes are described by the JavaScript attributes object. The children must be a JavaScript array.

Example

example.js

"use strict";

const xml = require( hop.xml );

function XML( attrs, ... nodes ) {
   return xml.createElement( "xml", attrs, nodes );
}

function BLOCK( attrs, ... nodes ) {
   return xml.createElement( "block", attrs, nodes );
}

function FIELD( attrs, ... nodes ) {
   return xml.createElement( "field", attrs, nodes );
}

const decl = <xml xmlns="https://developers.google.com/blockly/xml" id="toolbox" style="display: none">
    <block type="controls_if"></block>
    <block type="logic_compare"></block>
    <block type="controls_repeat_ext"></block>
    <block type="math_number">
      <field name="NUM">123</field>
    </block>
    <block type="math_arithmetic"></block>
    <block type="text"></block>
    <block type="text_print"></block>
</xml>;

console.log( decl.toString() );