Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress prolog from XML during marshalling

I am using Mule XML module jaxb-object-to-xml-transformer to convert my object to XML. Then this XML is embedded into another XML using templates.

But the issue here is the object to XML transformer is giving an XML output with prolog:

 <?xml version="1.0" encoding="UTF-8"?>

I need an XML without this. So that it can be embedded into another template without issues.

    <flow name="main.flow">
    ....
    ....
    <mule-xml:jaxb-object-to-xml-transformer name="obj2xml" jaxbContext-ref="myJaxbContext"  returnClass="java.lang.String" />
    <custom-transformer ..... >
    ....
    ....
</flow>

In plain JAXB there is a way to do this. But in Mule XML module I couldn't find any property to do this. Please advise if there is any property to achieve this behaviour.

like image 708
user1760178 Avatar asked Oct 28 '25 16:10

user1760178


1 Answers

The documentation indicates that you can intercept JAXB transforms (see: http://www.mulesoft.org/documentation/display/current/JAXB+Bindings). The following example is taken from that documentation.

@Transformer(sourceTypes = {String.class, InputStream.class})
public Person toPerson(Document doc, JAXBContext context) throws JAXBException
{
    return (Person) context.createUnmarshaller().unmarshal(doc);
}

Assuming there is a corresponding thing you can do for marshalling you would be able to set the necessary JAXB property.

marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
like image 66
bdoughan Avatar answered Oct 31 '25 07:10

bdoughan