[Simple-support] Text with Element?
Brought to you by:
niallg
|
From: Lee J. <n0...@co...> - 2011-08-31 04:04:46
|
Per the tutorial: The rules that govern the use of the Text <http://simple.sourceforge.net/download/stream/doc/javadoc/org/simpleframework/xml/Text.html> annotation are that there can only be one per schema class. Also, this annotation cannot be used with the |Element| annotation. Only the Attribute <http://simple.sourceforge.net/download/stream/doc/javadoc/org/simpleframework/xml/Attribute.html> annotation can be used with it as this annotation does not add any content within the owning element. ... I fully understand why, and the reasons behind it. Now onto my problem, I'm trying to decode XML that is produced (I don't have to create it, just read), and they have the schema as such: <creation-center> <sub-center>subcenter info</sub-center> creationcenter info </creation-center> The schema that I need to decode is: ----- <xsd:complexType name="sourceType"> <xsd:all> ... <xsd:element name="creation-center" type="creation-centerType" minOccurs="0" maxOccurs="1"/> ... </xsd:all> </xsd:complexType> <xsd:complexType name="creation-centerType" mixed="true"> <xsd:sequence> <xsd:element name="sub-center" type="xsd:string" minOccurs="0" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> ----- My class that I'm currently trying to get to decode this XML is: import org.simpleframework.xml.Element; import org.simpleframework.xml.Text; @Element(name="creation-center") public class CreationCenter { // @Element(name="sub-center", required=false) // private String sub_center; @Text private String creation_center; //// // public String getSub_Center() { // return sub_center; // } public String getCreation_Center() { return creation_center; } } If I don't comment out the "sub-center" element, the XML fails to parse, obviously. How can I get both the main element text and the sub-element? Thanks. -Lee. |