JAXB:Marshaller.JAXB_FORMATTED_OUTPUT工作不完美

时间:2016-12-19 13:22:15

标签: java xml jaxb

我正在尝试使用JAXB Marshaller将一个Object写入xml,内容很好,但是对于某些元素来说,格式化并不完美。我已经设置了属性marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true)

结果如下(tsi:mmt部分没有正确缩进):

<TransportFrame>
    <ServiceData>
        <SID>
            <tdt:SID_A>1</tdt:SID_A>
            <tdt:SID_B>1</tdt:SID_B>
            <tdt:SID_C>1</tdt:SID_C>
        </SID>
        <ServiceComponentMultiplex>
            <ServiceComponent applicationId="0" contentId="0" majorApplicationVersion="3" minorApplicationVersion="2" encId="0" safetyFlag="false">
                <ServiceComponentFrameContent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ServCompFrameCountedProtected">
                    <SCID>0</SCID>
                    <MessageCount>8</MessageCount>
                    <ApplicationRootMessage>
                        <ApplicationRootMessageML xsi:type="tsi:TSIMessage">
<tsi:mmt>
<mmt:messageID>1</mmt:messageID>
<mmt:versionID>1</mmt:versionID>
<mmt:messageExpiryTime>2017-01-19T13:13:14.637+01:00</mmt:messageExpiryTime>
<mmt:cancelFlag>false</mmt:cancelFlag>
</tsi:mmt>
                        </ApplicationRootMessageML>
                    </ApplicationRootMessage>
                </ServiceComponentFrameContent>
            </ServiceComponent>
        </ServiceComponentMultiplex>
    </ServiceData>
</TransportFrame>

关注我的代码,任何人都知道如何解决这个问题?

Marshaller marshaller = contextObj.createMarshaller();  
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.marshal(document, new FileOutputStream(selectedFile)); 

0 个答案:

没有答案