Problem
Given the following XML configuration file:
<main> <name>JET</name> <maxInstances>5</maxInstances> <parameters> <a>1</a> <b> <b1>test1</b1> <b2>test2</b2> </b> </parameters> </main>
I need to extract the value of the name and maxInstances elements, and then the entire inner text of the parameter element. eg.
name = "JET" maxInstances = 5 parameters = "<a>1</a><b><b1>test1</b1><b2>test2</b2></b>"
Ultimately, a parameter block can contain any well-formed XML.
Attempt to solve
The following code works for the name and maxInstances, but not for the parameters:
@XmlRootElement(name="main") public class Main { @XmlElement(name="name", required="true") private String name; @XmlElement(name="maxInstances", required="true") private Integer maxInstances; @XmlElement(name="parameters") private String parameters; }
I tried to search for solutions based on the following ideas, but I can not find something suitable.
Is there any other type that I can use for a parameter object representing an XML tree that I could parse to create a string? eg.
@XmlElement(name="parameters") private XmlNodeObject parametersNode; public String getParameters() {
Or do I need to use several different annotations?
@XmlSpecialAnnotation(...) @XmlElement(name="parameters") private String parameters;
Do I need to switch to a different parser style? Is it a good / bad idea to use two parser styles?
Karle
source share