XML Structure Diagrams

XML structure diagram enables you to create an XML structure definition from scratch. It is assumed that you are familiar with the basics of XML, since training is beyond the scope of this help topic. You can refer to the following books no XML:

You can also create a XML structure diagram by importing an existing Data Type Definition (DTD) file. This can be very useful if you are not familiar with the DTD and want to get a quick over of the elements it contains, and their relationships. For more information, see Import-Export Operations: DTD Import/Export .

Content

XML diagrams contain the following components, represented by the buttons on the toolbar:

Icon

Name

 

 Elements.

 

Groups.

 

Reference Links

 

Attribute Groups

 

Notes

 

Note Links

Creating XML structure diagrams

If you need to learn how to create new diagrams in a project, or the techniques for placing elements and drawing links, consult the User's Guide topics found under " Working with Diagrams: Basic Diagram Techniques" in the Table of Contents. Also refer to the topic Creating diagrams in projects.

Here we shall consider creation of a sample XML structure diagram that represents a structure of personnel management data.

  1. Activate the module XML Structure Diagram. To do this, select Options | Activatable modules | XML structure diagram and set this checkbox.

  1. To create a new XML diagram, select File | New Diagram and choose XML structure diagram from the New Diagram dialog.

  1. Select Element icon from the toolbar, create an element and change it's name to personnel. Create two elements and call them employee and chief executive respectively. Invoke the Inspector for each element (speedmenu | Properties) and see that the property "content" is set to "empty".

  2. Create a Reference link, using the button , from personnel to employee, and from personnel to chief executive. Right click on the employee link and check the box one or more in the link's speedmenu, which means that there can by any number of employees. Click on the chief executive link and check the box zero or one, to specify that there can one chief executive only.

Each link is marked with a character that corresponds to the content model declared for the elements. For example,

Symbol

Description

?

Follows an element or group of elements and indicates that it occurs zero times or once.

 *

Follows an element or group of elements and indicates that it occurs zero or more times.

+

Follows an element or group of elements and indicates that it occurs one or more times.

 1

Follows an element or group of elements and indicates that it is required.

  1. Add an Attribute to each element. Select New | New attribute on the speedmenu of this element and change it's name to identifier. This attribute is a unique identifier of an employee. In order to verify or change the attribute's properties, invoke it's speedmenu and set the field "occurs" to "required", which means that this property is mandatory.

  2. Besides unique identifier, each employee and the chief executive are characterized by name, position in the organization's hierarchy, url and email address. Now create the following elements:

  Invoke speedmenu of each element and see that the property "content" is set to "empty".

  1. Select Attribute Group button in the toolbar and create a new group of attributes - name. Add the attributes first name, second name, and last name to this group. All these attributes have "string" data type. Firstname and lastname are mandatory (the field "occurs" is set to "required"), while the attribute second name is optional (the field "occurs" is set to "implied"). Now right click on the element personal to invoke it's speedmenu, and select New | New Attribute Group Reference to refer to this attribute group.

  1. Next, you can try to create links from the employee and chief executive elements to each of the elements hiererchy, url, personal, email. However, the result looks too entangled. The more elegant way to link multiple elements to multiple elements lays with the Groups. Select the Groups icon from the toolbar and create a new group. By default AND group is created. Link the employee and chief executive elements to this group. Invoke the speedmenu of employee link and set the flag "required". If you now check the Properties of these elements, you see that the field "content" now changed value to "children".

  2. Next, link the group to each of the above elements. By default, the links have the property zero or one. Select the link to email element and set the checkbox zero or more, which means that a person may have unlimited number of email addresses. Same refers to url element. Select the link to personal element and check the box required, which indicates that personal information is unique and mandatory. At last, select the link to the hierarchy element and set the flag zero or one, thus indicating that a lucky one can easily do without any subordinates or supervisors.

  1. XML diagram enables creating Reusable attributes. Right click on the diagram background to invoke the Properties inspector and select Reusable Attributes tab. Press Add attribute button, enter the name job description, select type and data type from the drop down lists.

  1. To add this attribute to the elements employee and chief executive, right click on the appropriate element and select Attribute reference on the New speedmenu. Same way, you can create a reusable attribute comments, and add it to any element where needed.

  1. Besides reusable attributes, the Properties' Inspector provides tabs for creating Notations. Right click on the diagram background to invoke the Properties Inspector and select the tab Notations. Press the button Add notation and enter the notation name, public and system id. Repeat this procedure for each notation to be added. Press Ctrl+Enter to apply the changes and close the Inspector.

  1. To enter a General entity, select the tab General Entities on the Properties Inspector, press Add entity button and check the box external, if this entity is external, or leave it clear, if this is an internal entity. To specify notation for an Internal entity, press the File Chooser button in the notation column of the Inspector and select the required notation. Press Ctrl+Enter to apply the changes and close the Inspector.

  1. Processing instructions are defined same way: select the tab Processing instructions on the Properties Inspector, and press Add processing instruction button. To specify notation for processing instruction, press the File Chooser button in the notation column of the Inspector and select the required notation. Enter appropriate information in the data field. Press Ctrl+Enter to apply the changes and close the Inspector.

  1. Export to DTD on the Tools menu creates a DTD file in the specified location. Now you can view the resulting DTD file in any external editor:

<?xml version="1.0" encoding="ASCII"?>
<!-- Generated by Together -->
<!-- Processing instructions -->
<!-- Attribute entities -->
<!-- Reusable attribute is presented as an entity -->
<!ENTITY % comment "comment CDATA #IMPLIED " >
<!ENTITY % job_description "job_description CDATA #IMPLIED " >
<!-- Attribute group entities -->
<!-- Attribute groups are also presented as entity parameters-->
<!ENTITY % name "first_name CDATA 'ivan' last_name CDATA #REQUIRED second_name CDATA #IMPLIED " >
<!-- Model group entities -->
<!-- Model groups are presented as entity parameters as well -->
<!ENTITY % xmlModelGroup1 "hierarchy? , url* , personal , email* " >
<!-- Elements -->
<!-- This is an element whose content is described in the Model Group 1 -->
<!ELEMENT employee ( %xmlModelGroup1; )  >
<!-- Here are the sttributes of this element -->
<!ATTLIST employee identifier CDATA #REQUIRED >
<!ELEMENT chief_executive ( %xmlModelGroup1; )  >
<!ATTLIST chief_executive identifier CDATA #REQUIRED >
<!ELEMENT url EMPTY >
<!ATTLIST url %job_description; >
<!ELEMENT email (#PCDATA) >
<!ATTLIST email address CDATA #IMPLIED %comment; >
<!ELEMENT personal (#PCDATA) >
<!-- Attribute a-dtype describes non-standard types of the other attributes -->
<!ATTLIST personal date_of_birth CDATA #REQUIRED %name; a-dtype NMTOKENS "date_of_birth date " >
<!ELEMENT hierarchy EMPTY >
<!ATTLIST hierarchy subordinates IDREFS #IMPLIED supervisor ID #IMPLIED %comment; position CDATA #REQUIRED >
<!ELEMENT personnel (employee* , chief_executive? ) >
<!-- General entities -->
<!ENTITY Entity1 "111">
<!ENTITY Entity2 PUBLIC "e2" "e2" NDATA Notation1 >
<!ENTITY Entity3 PUBLIC "e3" "e3" NDATA Notation2 >
<!-- Notations -->
<!NOTATION Notation1 PUBLIC "n1" "n1" >
<!NOTATION Notation2 PUBLIC "n2" "n2" >
  1. You can import the resulting DTD for further use. On the Tools | Import menu choose Import from DTD option and select the required DTD file from the dialog window.

Presently DTD files are imported with the aid of IBM XML4J 2.0.15, which does not support the import of some parameters: comments (information entered in the Description tab of the Inspector), notations and processing instructions. In the further versions of Together this problem will be solved by a new parser that will support the import of all parameters.

See also: