Source:
<code>public static String dumpModelAsXml(CamelContext context, NamedNode definition) throws JAXBException { JAXBContext jaxbContext; if (context == null) { jaxbContext = createJAXBContext(); } else { jaxbContext = context.getModelJAXBContextFactory().newJAXBContext(); } final Map<String, String> namespaces = new LinkedHashMap<>(); if (definition instanceof RoutesDefinition) { List<RouteDefinition> routes = ((RoutesDefinition) definition).getRoutes(); for (RouteDefinition route : routes) { extractNamespaces(route, namespaces); } } else if (definition instanceof RouteDefinition) { RouteDefinition route = (RouteDefinition) definition; extractNamespaces(route, namespaces); } Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter buffer = new StringWriter(); marshaller.marshal(definition, buffer); Document dom = context.getTypeConverter().convertTo(Document.class, buffer.toString()); Element documentElement = dom.getDocumentElement(); for (String nsPrefix : namespaces.keySet()) { documentElement.setAttribute("xmlns:" + nsPrefix, namespaces.get(nsPrefix)); } <START> Exchange exchange = ExchangeBuilder.anExchange(context).build(); <END> exchange.setProperty(XmlConverter.OUTPUT_PROPERTIES_PREFIX + OutputKeys.INDENT, "yes"); exchange.setProperty(XmlConverter.OUTPUT_PROPERTIES_PREFIX + OutputKeys.STANDALONE, "yes"); String result = context.getTypeConverter().convertTo(String.class, exchange, dom); return result; }</code><technical_language>clever. I a convert this create a dummy exchange. add some methods xml converter accept indent options call converter directly. Creating exchange is intended for routing messages</technical_language>

Target:
public static String dumpModelAsXml(CamelContext context, NamedNode definition) throws JAXBException { JAXBContext jaxbContext = getJAXBContext(context); final Map<String, String> namespaces = new LinkedHashMap<>(); if (definition instanceof RoutesDefinition) { List<RouteDefinition> routes = ((RoutesDefinition) definition).getRoutes(); for (RouteDefinition route : routes) { extractNamespaces(route, namespaces); } } else if (definition instanceof RouteDefinition) { RouteDefinition route = (RouteDefinition) definition; extractNamespaces(route, namespaces); } Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter buffer = new StringWriter(); marshaller.marshal(definition, buffer); Document dom = context.getTypeConverter().convertTo(Document.class, buffer.toString()); Element documentElement = dom.getDocumentElement(); for (String nsPrefix : namespaces.keySet()) { documentElement.setAttribute("xmlns:" + nsPrefix, namespaces.get(nsPrefix)); } TypeConverterRegistry registry = context.getTypeConverterRegistry(); XmlConverter xmlConverter = registry.getInjector().newInstance(XmlConverter.class); Properties outputProperties = new Properties(); outputProperties.put(OutputKeys.INDENT, "yes"); outputProperties.put(OutputKeys.STANDALONE, "yes"); try { return xmlConverter.toStringFromDocument(dom, outputProperties); } catch (TransformerException e) { throw new IllegalStateException("Failed converting document object to string", e); } }