1

I have some jaxb objects that are generated from an xsd I created. Previously when I marshalled the content, the xml output looked like this:

<report xmlns="urn:com-test-person-data:v3">
<person-data>
    .......(Data)
</person-data>
</report>

I have recently change over from coding on a Windows machine to a Mac. Nothing has changed in the jaxb objects I'm using. But now my marshalled output looks like this.

<report>
<person-data>
    .......(Data)
</person-data>
</report>

I've tried doing some digging to see what could've removed the xmlns attribute, but have had no luck. I use that attribute to check what version of my schema is being used, so it's important it's in the outputted xml fragment.

Here's the code snippet where I call the marshaller:

final JAXBContext context = JAXBContext.newInstance(Report.class);
final Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); //$NON-NLS-1$
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(reportJaxBObject, sw);

Any ideas?

4

1 回答 1

0

此问题通常是package-info.java未与其余模型类一起编译或打包的结果。package-info类是@XmlSchema指定包含命名空间信息的地方。

于 2012-06-14T01:27:19.153 回答