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 whole inner text of the parameters element. e.g.
name = "JET"
maxInstances = 5
parameters = "<a>1</a><b><b1>test1</b1><b2>test2</b2></b>"
Ultimately the parameters block can contain any well formed XML.
Attempted Solution
The following code works for name and maxInstances but not 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've tried looking at solutions based on the following ideas but can't find something appropriate.
Is there a different type I can use for the parameters object representing the XML Tree that I could parse to produce a string? e.g.
@XmlElement(name="parameters")
private XmlNodeObject parametersNode;
public String getParameters() {
// Collapse node to single line of text
return innerText;
}
Or do I need to use some different kind of annotation?
@XmlSpecialAnnotation(...)
@XmlElement(name="parameters")
private String parameters;
Do I need to switch to a different style of parser? Is it a good/bad idea to use two styles of parser?