use of javax.xml.bind.ValidationEvent in project onebusaway-application-modules by camsys.
the class SiriXmlSerializer method getXml.
public String getXml(Siri siri) throws Exception {
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
marshaller.setEventHandler(new ValidationEventHandler() {
public boolean handleEvent(ValidationEvent event) {
throw new RuntimeException(event.getMessage(), event.getLinkedException());
}
});
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Writer output = new StringWriter();
marshaller.marshal(siri, output);
// FIXME: strip off ns5 namespaces on siri root namespace. super hack, please fix me!
String outputAsString = output.toString();
outputAsString = outputAsString.replaceAll("<ns5:", "<");
outputAsString = outputAsString.replaceAll("</ns5:", "</");
outputAsString = outputAsString.replaceAll("xmlns:ns5", "xmlns");
outputAsString = outputAsString.replaceAll("<siriExtensionWrapper>", "");
outputAsString = outputAsString.replaceAll("</siriExtensionWrapper>", "");
return outputAsString;
}
Aggregations