我有5个xsd,其中1是父级,其余是子级,是导入的 所有xsd都在单一位置,我使用maven插件生成pojo类。
这是我的示例GenerateXML Class
MainMsg1 mmsrMessage = new MainMsg1();
//JAXBContext context = JAXBContext.newInstance(MainMsg1.class);
JAXBContext context = JAXBContext.newInstance(MainMsg1.class, ObjectFactory.class,
com.mypackage.appheader.ObjectFactory.class,
com.mypackage.doc1.ObjectFactory.class,
com.mypackage.doc2.ObjectFactory.class,
com.mypackage.doc3.ObjectFactory.class,
com.mypackage.doc4.ObjectFactory.class);
Marshaller jaxbMarshaller = context.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
//Document doc = objf.createDocument();
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
InputStream is = new FileInputStream(
new File("C:\\xsd\\main.xsd"));
StreamSource source = new StreamSource(is);
Schema schema = schemaFactory.newSchema(source); // This is where error occurs
jaxbMarshaller.setSchema(schema);
Main.xsd
<xs:schema xmlns="head.003.001.01" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ah="urn:random:xsd:head.001.001.01" xmlns:doc1="urn:random:xsd:doc1.1.1" xmlns:doc2="urn:random:xsd:doc2.2.2" xmlns:doc3="urn:random:xsd:doc3.3.3" xmlns:doc4="urn:random:xsd:doc4.4.4" targetNamespace="head.003.001.01" elementFormDefault="qualified">
<xs:import namespace="urn:random:xsd:head.001.001.01" schemaLocation="appHdr.xsd"/>
<xs:import namespace="urn:random:xsd:doc1.1.1" schemaLocation="doc1.1.1.xsd"/>
<xs:import namespace="urn:random:xsd:doc2.2.2" schemaLocation="doc2.2.2.xsd"/>
<xs:import namespace="urn:random:xsd:doc3.3.3" schemaLocation="doc3.3.3.xsd"/>
<xs:import namespace="urn:random:xsd:doc4.4.4" schemaLocation="doc4.4.4.xsd"/>
<xs:element name="MainMsg" type="MainMsg1"/>
<xs:complexType name="MainMsg1">
<xs:sequence>
<xs:element ref="ah:AppHdr"/>
<xs:choice>
<xs:element ref="doc1:Document"/>
<xs:element ref="doc2:Document"/>
<xs:element ref="doc3:Document"/>
<xs:element ref="doc4:Document"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
检索到错误:
src-resolve: Cannot resolve the name 'ah:AppHdr' to a(n) 'element declaration' component