I am trying to create an xml file for Solr, but I run into a problem. I use the @XmlElement annotation to tell the marhaller which are the xml elements of my class like so:
@XmlElement(name = "field")
public String getAuthors() {
return authors;
}
public void setAuthors(List<String> authors) {
setValue(authors, "authors");
}
@XmlElement(name = "field")
public String getDate() {
return date;
}
public void setDate(List<String> date) {
setValue(date, "date");
}
@XmlElement(name = "field", required = false)
public String getContent() {
return content;
}
public void setContent(List<String> content) {
setValue(content, "content");
}
and so on.
Then I use the following to create the xml file:
XMLCreator collection = new XMLCreator(docs);
File fileOut = new File("docs.xml");
BufferedWriter writer = new BufferedWriter(new FileWriter(fileOut));
JAXBContext jaxbContext = JAXBContext.newInstance(XMLCreator.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(collection, writer);
It works, but I want my xml file to have the following format:
<add>
<doc>
<field name="authors">Patrick Eagar</field>
<field name="subject">Sports</field>
<field name="dd">796.35</field>
<field name="numpages">128</field>
<field name="desc"></field>
<field name="price">12.40</field>
<field name="title">Summer of the all-rounder: Test and championship cricket in England 1982</field>
<field name="isbn">0002166313</field>
<field name="yearpub">1982</field>
<field name="publisher">Collins</field>
</doc>
<doc>
...
</doc>
</add>
Mine is currently like the following:
<add>
<doc id="2">
<field></field>
<field>Sugai, I.</field>
<field></field>
<field>CACM December, 1958 </field>
<field>CA581202 JB March 22, 1978 8:29 PM </field>
<field></field>
<field>2 5 2
2 5 2
2 5 2
</field>
<field>Extraction of Roots by Repeated Subtractions for Digital
Computers </field>
</doc>
</add>
What I want to do is to add the name attribute in each field element. Is this possible by using the @Xml... annotations?