Re: [Simple-support] Check for empty element
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2013-05-18 00:58:37
|
You would have to write a converter (see org.simpleframework.xml.convert.Converter). StAX, DOM and XmlPull (the XML parsers that can be used by simple) can not tell the difference between <DROP/> and <DROP></DROP> so it has to be null rather than an empty string.
--- On Fri, 17/5/13, Joël Craenhals <jo...@cr...> wrote:
From: Joël Craenhals <jo...@cr...>
Subject: [Simple-support] Check for empty element
To: sim...@li...
Received: Friday, 17 May, 2013, 11:57 AM
Hello,
I'm trying to deserialize an IPTables XML configuration file. In the file there is a part like this:
<rule > <actions> <DROP /> </actions>
</rule>
The empty element inside the actions element can be one of these four: <DROP /> or <ACCEPT /> or <RETURN /> or <QUEUE />
When reading in the XML file, I have a Java class Rule.java like this:
package model;
import java.io.Serializable;
import org.simpleframework.xml.Element;import org.simpleframework.xml.Root;
@Root(name = "rule")public class Rule implements Serializable { private static final long serialVersionUID = 1L;
@Element(name = "actions", required = true) private Actions action;
}
The actions class looks like this:
package model;
import org.simpleframework.xml.Element;import org.simpleframework.xml.Root;import org.simpleframework.xml.convert.Convert;
@Root(name = "actions", strict = false)public class Actions { @Element(name = "DROP", required = false) private String aDrop;
@Element(name = "ACCEPT", required = false) private String aAccept;
@Element(name = "QUEUE", required = false) private String aQueue;
@Element(name = "RETURN", required = false) private String aReturn;
public String toString() { if (aDrop != null) { return "DROP"; } else if (aAccept != null) { return "ACCEPT"; } else if (aQueue != null) { return "QUEUE"; } else if (aReturn != null) { return "RETURN"; } else { return "NOTHING"; } }}
I want to check which element was present inside the actions element.However all the attributes of the Actions class stay NULL.
What am I doing wrong?
Thanks in advance.
Joël Craenhals
-----Inline Attachment Follows-----
------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
-----Inline Attachment Follows-----
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|