Wiki

How to create your XML definition file

     First of all you need and editor, you can use any one, but I like to use Eclipse IDE, because I also use it for programing and Liferay IDE also works with it, but mainly because it has many helping details, like code completion, xml editor, and validation against .xsd definitions.

 
     Now we need to have an idea of what we want to do, lets say that we would like to make something easy like a to-do list.
 
     What fields will I need in a to-do list?
 
- Todo Id. The key of the row and should be the primary key.
- TodoDescription Text explaining what I have to do.
- TodoDueDate Last day to do.
- TodoFinished Check if it is finished.
 
     For this example we are to forget all optional things and go just for the minimun needed to work.
 
     So we open eclipse IDE, I am actually using Helios Service Release 2 (For java EE  developers) , but any other version will do.
 
 
     Now goto file --> new --> project --> general --> project, and call it MyXMLs
 
 
 
     Now right click on top of the project name and file --> new --> other --> XML --> XML File
 
 
     And create an empty xml file definition called To-do.xml
 
 
     Now copy xmlportletfactory.xsd file to the same folder your To-do.xml file is.
 
 
     Why? Because inside this file are the definitions of how a XMLPortletFactory xml file can and should be. This way you will see how we can check the validity of our xmls.
 
     The next step is to start inserting things on our to-do.xml, first the esencial code. You dont have to understand this first part just copy the content of empty.xml to your To-do.xml
 
     empty.xml is a well formed xmlportletfactory xml definition, without any data. This way you just need to “fill de blanks”
 
     This is how it shows now:
 
 
     So we now fill the blanks for the commonData and application classdef, fileDef –name and first field:
 
 
      And keep inserting fields, now to-do description. As you may noticed, this field is not numeric. With eclipse IDE, if you have correctly put your .xsd file, it can help you with code completion, so, if I position my cursor, behind the <type> tag and press ctrl-space, magic!!! Several options appear to help me complete the field type:
 
 
      Once I select <>varchar, I can press again for more help, and so on:
 
 
      You continue, till all fields are defined. If you made a mistake, the .xsd file will come to your help again. Just to show, I am going to omit the <name>  tag in field todoDueDate
 
     Before:
 
<field>
<name>todoDueDate</name>
<title>Due Date</title>
<type>
<date>
<order>true</order>
</date>
</type>
<showFieldInView>true</showFieldInView>
<required>true</required>
</field>
 
After:
 
<field>
<title>Due Date</title>
<type>
<date>
<order>true</order>
</date>
</type>
<showFieldInView>true</showFieldInView>
<required>true</required>
</field>
 
     And now we press right-button over project name and select validate:
 
 
     And the result is a message telling you what things could be wrong.
 
 
 
     Hope this is of help, find attached, the xml definition, and empty.xml (get the .xsd file from your xmlportletfactory instalation.
 
     Its better you get xmlportletfactory.xsd file from your xmlportletfactory instalation, you will find it under Resources/xml folder. This way you get sure that you are using the correct version.
 
     Note: Just generated from example above and looks good, see edit page:
 
2 Attachments
5482 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments