To load menu data from an XML file use the loadStruct() method:
var myMenu = new dhtmlXMenu();
myMenu.loadStruct("server/data.xml", function(){
// data loaded and rendered
// your code here
});
The first parameter of loadStruct() method is the path to the XML file, while the second parameter is an optional user-defined handler.
To load data from an XML string, use the same method - loadStruct():
var myMenu = new dhtmlXMenu();
myMenu.loadStruct('<data><node id="a1".../></data>', function(){
// data loaded and rendered
// your code here
});
The first parameter for loadStruct() method is the XML string from our html file, while the second parameter is an optional user-defined handler.
This section is created in order to give the user the idea of XML Format Template. It aims at helping users in creating XML files for dhtmlxMenu initialization.
<?xml version="1.0"?>
<menu> // a top xml tag, mandatory
<item id="file" text="File"> // a top-level item, each item must have a unique ID
<item id="new" text="New"/> // a sub-level item
<item id="ms1" type="separator"/> // a sub-level separator item
...
<item id="export" text="Export">
<item id="export_pdf" text="PDF"/> // a sub-level item
...
</item>
...
</item>
</menu>
<?xml version="1.0"?>
<menu>
<item id="file" text="File">
// a sub-level item with images for enabled/disabled states
<item id="new" text="New" img="new.gif" imgdis="new_dis.gif"/>
<item id="ms1" type="separator"/>
...
<item id="export" text="Export">
// a sub-level item disabled by default
<item id="export_pdf" text="PDF" enabled="false"/>
...
</item>
...
</item>
</menu>
<?xml version="1.0"?>
<menu>
<item id="file" text="File">
<item id="new" text="New" img="new.gif" imgdis="new_dis.gif">
<hotkey>Ctrl+N</hotkey> // a hotkey (just a text) to a menu item
</item>
<item id="ms1" type="separator"/>
<item id="udf" text="UDF">
<userdata name="align">left</userdata> // userdata
</item>
...
<item id="export" text="Export">
<item id="export_pdf" text="PDF" enabled="false"/>
...
</item>
...
<item id="eol" text="End Of Line">
// a radiobutton, group "eol", checked by default
<item id="eol_u" text="Unix (\n)" type="radio" group="eol" checked="true"/>
// a radiobutton, group "eol"
<item id="eol_w" text="DOS/Windows (\r\n)" type="radio" group="eol"/>
// a radiobutton, group "eol"
<item id="eol_m" text="MacOS (\r)" type="radio" group="eol"/>
// a radiobutton, group "eol", disabled
<item id="eol_m" text="MacOS (\r)" type="radio" group="eol"/>
// we got a radiogroup "eol" with 4 buttons, 1 disabled
</item>
<item id="ms2" type="separator"/>
// a disabled checked checkbox
<item id="ignorecase" text="Ignore Case" type="checkbox" checked="true"
enabled="false"/>
// an unchecked checkbox
<item id="checkspelling" text="Check Spelling" type="checkbox"/>
</item>
<item id="company" text="Company">
<href target="blank"><![CDATA[http://dhtmlx.com/docs/company.shtml]]></href>
// link, page will be opened in new window
</item>
</menu>
Back to top