JAXB entangled in root elements?

I am trying to organize a file using a Visio XML schema , which consists of 3 schema files and creates three packages when the java source is generated using XJC:

  • com.microsoft.schemas.visio._2003.core
  • com.microsoft.schemas.visio._2006.extension
  • com.microsoft.schemas.office.visio._2010.extension

The root element VisioDocument, and all the classes that I use, are in the package 2003.

Here is my approach to sorting my XML file:

VisioDocumentType visioDoc = new VisioDocumentType();
... manipulated here ...
JAXBContext jc = JAXBContext.newInstance("com.microsoft.schemas.visio._2003.core");
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(new JAXBElement<VisioDocumentType>(new QName("uri","local"), VisioDocumentType.class, visioDoc), bw);

On execution, I get this error:

javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "com.microsoft.schemas.visio._2003.core.PagePropsType" as an element because it is missing an @XmlRootElement annotation]

I use PagePropsType, but this is not the root element. Why does JAXB consider this?

+5
source share
2 answers

... manipulated here ... .

, ( - ).

// you create a page prop
PagePropsType pageProps = ...

// then you feed it to a shape sheet
ShapeSheetType shapeSheet = ...
shapeSheet.getTextOrXFormOrLine().add(pageProps);

(ShapeSheetType StyleSheetType ..)

, , pageProps .

getTextOrXFormOrLine(), , . JAXBElement<...>, pageProps, .

:

ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<PagePropsType> pagePropsElement = objectFactory.createShapeSheetTypePageProps(pageProps);

( , XJC 2.2.4 , Type. , VisioDocumentType VisioDocument , .)

+2

, ObjectFactory. , VisioDocument, JAXBElement, , .

, VisioDocument - <new ', ObjectFactory.

+1