spindle logo

<solidXML>. XML transformation framework for JAVA

SourceForge links | Home | Bugs | Downloads |

<Menu>
  <About>
      <Description/>
      <How it works/>
  </About>
  <Documentation>
      <Annotations/>
      <Mapping objects/>
  </Documentation>
</Menu>



hosted by:
SourceForge.net Logo

   Steps in order to put SolidXML to work :
1. Put your library in your CLASSPATH
2. At this step you should allready know the structure of the XML document that you with to map with your POJO's. Let's consider the following example :
3. Knowing the structure of the XML data file, the next step is to write Java classes with to map fields. One of the most important step in writing classes is to identify field types :
<?xml version="1.0"?>
<rss version="2.0">
  <testElem value="12" attribute="none">Testing element inside RSS</testElem>
  <testInteger>12</testInteger>
 <channel>
    <title>Example Channel</title>
     <value1>112.1</value1>
     <value2>221.2</value2>
    <link>http://example.com/</link>
    <description>My example channel</description>
    <item>
       <title>First item</title>
       <link>Item link 1</link>
       <description>Item 1 description</description>
    </item>
    <item value="item 2">
       <title>Second item</title>
       <link>link</link>             
    </item>
  </channel>
</rss> 
                  
The example represents an modified RSS field with two items.

3. The next important thing is to identify data types for each tag from the source XML document.
           <?xml version="1.0"?>
JAVA OBJECT |<rss version="2.0"> 
STRING      | <testElem value="12" attribute="none">Testing element inside RSS</testElem>
INTEGER     | <testInteger>12</testInteger>
JAVA OBJECT |   <channel>
STRING      |    <title>Example Channel</title>
INTEGER     |    <value1>112.1</value1>
INTEGER     |    <value2>221.2</value2>
STRING      |    <link>http://example.com/</link>
STRING      |    <description>My example channel</description>
JAVA OBJECT |    <item>
STRING      |      <title>First item</title>
STRING      |      <link>Item link 1</link>
STRING      |      <description>Item 1 description</description>
                 </item>
JAVA OBJECT |    <item value="item 2">
STRING      |      <title>Second item</title>
STRING      |      <link>link</link>
                 </item>
               </channel>
              </rss> 
                  
4. Next you must create your Java objects taking into consideration field type identification made at point 3
// rssRoot.java

import org.spindle.solidXML.annotations.*;

public class rssRoot {

	@element(XMLTag="testElem")
	private String testElem;
	
	@element(XMLTag="testInteger")
	private Integer testInteger;
	
	@element(XMLTag="channel")
	private channel chan;

   /*-------Setters & Getters ----------*/	
	
}

//channel.java

import java.util.ArrayList;
import org.spindle.solidXML.annotations.*;

@element(XMLTag="channel")
public class channel {	
	
	@element(XMLTag="title")	
	private String title;
	
	@element(XMLTag="value1")
	private Double value1;
	
	@element(XMLTag="value2")
	private double value2;
	
	@element(XMLTag="link")
	private String link;
	
	@element(XMLTag="description")
	private String description;
	
	@element(XMLTag="item")
	private ArrayList itm;

   /*-------Setters & Getters ----------*/	
	
}

//item.java
import org.spindle.solidXML.annotations.*;

@element(XMLTag="item")
public class item {
	
	@element(XMLTag="title")	
	private String title;
	
	@element(XMLTag="link")
	private String link;
	
	@element(XMLTag="description")
	private String description;

   /*-------Setters & Getters ----------*/	
	
}

5. And finnaly the main transformation class where make use of SolidXML's features
 //text is a variable of type String where the content of XML document is loaded before transformation 

 rssRoot result=(rssRoot) solidXML.transform(rssRoot.class, text);

 System.out.println(result.getChan().getValue1()); //Get value1 from channel object
 System.out.println(result.getChan().getValue2()); //Get value2 from channel object
 System.out.println(result.getTestElem()); //Get testElem from 
 System.out.println(result.getChan().getItm().get(0).getLink()); //Get link of first item from channel


This is a brief example presented as steps in order to understand better SolidXML's functionality and usage. Details of anotations, type mapping are explained further on the documenation section.