To append an XML document fragment (XML sub-tree structure) to the data structure of an XML document, define the command using a vocabulary component with XVCD and describe a command instruction in it to insert the XML document fragment into the data structure of an XML document. In the command, describe and define xvcd:command element as a child element of xvcd:xvcd element.
The command instruction to append XML document fragment to the data structure of XML document is xvcd:insert command instruction. Describe this xvcd:insert command instruction in the command definition. Specify the reference node of insertion point in XPath expression for ref attribute of xvcd:insert command instruction. Specify the reference node of insertion point for position attribute of xvcd:insert command instruction.
Describe XML document fragment to insert for content of xvcd:insert command instruction. In this case, as child element of ab:addressbook element,
<ab:entry>
<ab:person/>
<ab:address/>
</ab:entry>
you only need to insert the above, so the command definition to append a new address entry is as follows: In addition, you need to name a command. Here, we call it AddEntry. To invoke a command, specify the command name.
<xvcd:command name="AddEntry">
<xvcd:insert ref="/ab:addressbook" position="last-child">
<ab:entry>
<ab:person/>
<ab:address/>
</ab:entry>
</xvcd:insert>
</xvcd:command>
The defined command cannot be executed so far. You can run the command when it is invoked from the main menu, context menu, tool bar, event, or other command. To specify a command to be invoked by selecting from the main menu, context menu or tool bar, describe the ui:ui element in xvcd:vocabulary element. For more information, see the User Interface Description Reference.
Here, let's create "Entry" menu in the main menu and make it possible to append an address entry in the "Add" sub-menu.
<xvcd:vocabulary name="AddressBook" match="ab:addressbook" call-template="root">
<ui:ui version="1.0">
<ui:main-menu>
<ui:menu label="Entry">
<ui:menu-item label="add" command="AddEntry"/>
</ui:menu>
</ui:main-menu>
</ui:ui>
<xvcd:vocabulary>
The result of applying these content to AddressBook.xvcd is listed below. The highlighted strings are appended and changed. As the description of mapping to the menu is added, so note that XML namespace declaration xmlns:ui="http://xmlns.xfytec.com/ui" is appended.
<?xml version="1.0"?>
<xvcd:xvcd
xmlns:xvcd="http://xmlns.xfytec.com/xvcd"
xmlns:ui="http://xmlns.xfytec.com/ui"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ab="http://xmlns.xfytec.com/tutorial/addressbook"
version="1.0">
<xvcd:vocabulary match="ab:addressbook" name="AddressBook" call-template="root">
<ui:ui version="1.0">
<ui:main-menu>
<ui:menu label="Entry">
<ui:menu-item label="add" command="AddEntry"/>
</ui:menu>
</ui:main-menu>
</ui:ui>
</xvcd:vocabulary>
<xvcd:command name="AddEntry">
<xvcd:insert ref="/ab:addressbook" position="last-child">
<ab:entry>
<ab:person/>
<ab:address/>
</ab:entry>
</xvcd:insert>
</xvcd:command>
<xvcd:template name="root">
<html>
<body>
<table border="1" width="100%">
<tr>
<th width="150">
Name
</th>
<th>
Address
</th>
</tr>
<xvcd:apply-templates select="ab:entry"/>
</table>
</body>
</html>
</xvcd:template>
<xvcd:template match="ab:entry">
<tr>
<td>
<xvcd:apply-templates select="ab:person"/>
</td>
<td>
<xvcd:apply-templates select="ab:address"/>
</td>
</tr>
</xvcd:template>
<xvcd:template match="ab:person">
<xvcd:text-of select="." filler="Enter the name here."/>
</xvcd:template>
<xvcd:template match="ab:address">
<xvcd:text-of select="." filler="Enter the address here."/>
</xvcd:template>
</xvcd:xvcd>
When editing is complete, save AddressBook.xvcd.
Now let's display it in xfy Basic Edition. Open AddressBook.xml in xfy Basic Edition. The [Entry] is added to the main menu.
Menu item is appended
Run [Entry-Add]. An address book entry is appended at the last row, "Enter the name here."/"Enter the address here." are displayed.
Address entry is appended