java - Read in empty element -


i trying parse iptables xml configuration in java using simple xml framework.

i'm stuck read in actions elements in piece of config:

   <actions>        <drop  />    </actions> 

how can check in java drop element present in xml file?

assuming actions mapped class similar one:

@root(name = "actions") public class actions {     @element(name = "drop", required = false)     private string drop;       // ...      public string getdrop()     {         return drop;     } } 

if don't want drop empty can annotate required:

@element(name = "drop", required = true) private string drop; 

the parameter required = true throw exception if drop empty. can use if empty drop not allowed.

a second way set required = false; deserialized null if it's empty:

@element(name = "drop", required = false) private string drop;  // test if 'drop' empty: actions = ... boolean isempty = ( a.getdrop() == null ); 

you can check whether drop null (= empty) or not null (= set). can use if drop may empty , that's not problem / required.

as third way can implement converter implement serialization / deserialization own.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -