raymondgoose
New Member
Our class uses XStream to serialize, I'd like to use JAXP for one of the methods, as I'm infinitely more familiar with it. However, when I do so, XStream takes it upon itself to wrap it in XML and then escapes my JAXP-generated XML. How do I disable this? Code snippet follows:\[code\]@Controller@RequestMapping(value = "http://stackoverflow.com/req")public class RequirementController extends GenericController {@RequestMapping(value = "http://stackoverflow.com/{id}/log", method = RequestMethod.GET)public RestResponseObject<String> getLog(@PathVariable("id") Long id){ List<RequirementsLog> logs = requirementService.getLog(id); Collections.sort(logs, new Comparator<RequirementsLog>() { @Override public int compare(RequirementsLog o1, RequirementsLog o2) { return o2.getPerformedOn().compareTo(o1.getPerformedOn()); } }); // SQL Filtering does not work, so filter in Java for (RequirementsLog logEntry : logs) { if (logEntry.getRequirement().getRequirementId() != new Long(id)) { logs.remove(logEntry); } } StringWriter retProducer = new StringWriter(); StreamResult retSrc = http://stackoverflow.com/questions/11105684/new StreamResult(retProducer); SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler th = null; try { th = factory.newTransformerHandler(); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } th.setResult(retSrc); try { th.startDocument(); th.startElement(null, null,"response", null); th.startElement(null, null, "requirementsLogs", null); for (RequirementsLog r : logs) { th.startElement(null, null, "requirementsLog", null); th.startElement(null, null, "requirementLogId", null); th.characters(r.getRequirementLogId().toString().toCharArray(), 0, r.getRequirementLogId().toString() .length()); th.endElement(null, null, "requirementLogId"); th.startElement(null, null, "name", null); th.characters(r.getName().toCharArray(), 0, r.getName().toCharArray().length); th.endElement(null, null, "name"); th.startElement(null, null, "description", null); th.characters(r.getDescription().toCharArray(), 0, r.getDescription().length()); th.endElement(null, null, "description"); th.startElement(null, null, "reqData", null); th.characters(r.getReqData().toCharArray(), 0, r.getReqData().length()); th.endElement(null, null, "reqData"); th.startElement(null, null, "documentURI", null); th.characters(r.getDocumentURI().toCharArray(), 0, r.getDocumentURI().length()); th.endElement(null, null, "documentURI"); th.startElement(null, null, "notes", null); th.characters(r.getNotes().toCharArray(), 0, r.getNotes().length()); th.endElement(null, null, "notes"); th.startElement(null, null, "priority", null); th.characters(r.getPriority().toString().toCharArray(), 0, r.getPriority().toString().length()); th.endElement(null, null, "priority"); th.startElement(null, null, "version", null); th.characters(new Integer(r.getVersion()).toString().toCharArray(), 0, new Integer(r.getVersion()) .toString().length()); th.endElement(null, null, "version"); th.startElement(null, null, "isApproved", null); th.characters("true".toCharArray(), 0, 4); th.endElement(null, null, "isApproved"); th.startElement(null, null, "createdOn", null); th.characters(r.getPerformedOn().toString().toCharArray(), 0, r.getPerformedOn().toString().length()); th.startElement(null, null, "verificationTypeId", null); th.characters(r.getVerificationType().getVerificationTypeId().toString().toCharArray(), 0, r .getVerificationType().getVerificationTypeId().toString().length()); th.endElement(null, null, "verificationTypeId"); th.startElement(null, null, "setNodeId", null); th.characters(r.getSetNode().getSetNodeId().toString().toCharArray(), 0, r.getSetNode().getSetNodeId() .toString().length()); th.endElement(null, null, "setNodeId"); th.startElement(null, null, "requirementTypeId", null); th.characters(r.getRequirementType().getRequirementTypeId().toString().toCharArray(), 0, r .getRequirementType().getRequirementTypeId().toString().length()); th.endElement(null, null, "requirementTypeId"); th.startElement(null, null, "categoryId", null); th.characters(r.getCategory().getCategoryId().toString().toCharArray(), 0, r.getCategory() .getCategoryId().toString().length()); th.endElement(null, null, "categoryId"); th.startElement(null, null, "actorId", null); th.characters(r.getActor().getActorId().toString().toCharArray(), 0, r.getActor().getActorId() .toString().length()); th.endElement(null, null, "actorId"); th.startElement(null, null, "name", null); th.characters(r.getActor().getName().toCharArray(), 0, r.getActor().getName().length()); th.endElement(null, null, "name"); th.startElement(null, null, "action", null); th.startElement(null, null, "actionId", null); th.characters(r.getAction().getActionId().toString().toCharArray(), 0, r.getAction().getActionId() .toString().length()); th.endElement(null, null, "actionId"); th.startElement(null, null, "name", null); th.characters(r.getAction().getName().toCharArray(), 0, r.getAction().getName().length()); th.endElement(null, null, "name"); // TODO what's a projectsList look like? th.startElement(null, null, "projectsLogList", null); th.endElement(null, null, "projectsLogList"); th.startElement(null, null, "initialized", null); th.characters("false".toCharArray(), 0, "false".length()); th.endElement(null, null, "initialized"); th.endElement(null, null, "requirementsLog"); } th.endElement(null, null, "requirementsLogs"); th.endElement(null, null, "response"); th.endDocument(); } catch (SAXException e) { e.printStackTrace(); } String ret_ = retProducer.toString().replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", ""); return ret_;}\[/code\]ret_ does contain the format I'd like, but then XStream goes and sods it up by escaping it. Many thanks!