Re: [Simple-support] Attribute always returning null or 0
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2012-05-26 02:18:12
|
Yes, use the @Path annotaiton like so
@Path("state")@Attribute(name= "code",required=false)private int code;
@Path("state")@Attribute(name="id", required=false)private int id;
--- On Fri, 25/5/12, Simon Brodt <sim...@if...> wrote:
From: Simon Brodt <sim...@if...>
Subject: Re: [Simple-support] Attribute always returning null or 0
To: sim...@li...
Received: Friday, 25 May, 2012, 1:40 PM
Hello Shobhit,
Maybe you should have a look at the tutorial in the beginning. It's quite good and obviously you did not spend much time on it. For example the @Root annotation is absolutely missplaced, it should be at the beginning of the class. And with respect to the "data " attribute look up the @Path annotation.
Use the tutorial to learn about the features of simple-xml step by step. You will find that your problem can easily be solved by adopting examples from the tutorial.
Best Regards,
Simon
Shobhit Sharda <sho...@gm...> hat geschrieben:
Hello,
I am new to Simple Framework and have written a simple program to
deserialize an xml file to java objects using Simple. I am able to do
it partially but the attribute always return null or 0. The code and
the test xml is shown below:
Below is the class
file-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.io.File;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
public class Deserialize {
/**
* @param args
*/
//@Attribute(name="code" , required=false)
@Root
private String datadef;
@Element
private String str;
@Element
private String state;
@Attribute(name= "code",required=false)
private int code;
@Attribute(name="id", required=false)
private int id;
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Serializer serializer = new Persister();
File source = new File("importFiles/test.xml");
Deserialize deserialize = serializer.read(Deserialize.class, source);
System.out.println("Str : " + deserialize.str);
System.out.println("State : " + deserialize.state);
System.out.println("Code : " + deserialize.code);
System.out.println("Id : " + deserialize.id);
}
}
Below is the sample xml file I am trying to
deserialize-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<datadef>
<str>123</str>
<state code="100" id="4">test</state>
</datadef>
I am not able to understand what is the mistake I am doing. Thus
seeking for immediate help.
thanks and regards
--
Shobhit Sharda
MSc in SSE
RWTH Aachen University
Aachen
Germany
blog: http://shobhitsharda.wordpress.com
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
-----Inline Attachment Follows-----
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
-----Inline Attachment Follows-----
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|