<?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>
<?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>
// 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 ----------*/ }
//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