问题
I have a set of XSD files from a client. I need to generate java classes from those. One of the XSDs imports another without namespace. That fails the mvn generate-sources with an error: src-resolve: Cannot resolve the name 'faultstring' to a(n) 'element declaration' component. org.xml.sax.SAXParseException; systemId: file:/src/main/resources/Common/SOAP_Fault_v4_0_0.xsd
I am using openjdk 11 with version 3.3.0 of cxf-xjc-plugin to generate classes. Attached is the project.
I have tried to generate the child XSD (SOAP_Fault_v4_0_0) separately and used bindings file to refer to the generated class from parent(Envelope). Doesnt work. I also tried to use a different plugin jaxb2-maven-plugin (v2.5.0) but it ends with the same error.
When I give a namespace to the child XSD SOAP_FaultElements_v4_0_0.xsd and refer in SOAP_Fault_v4_0_0.xsd using the prefix, it generates the classes fine but then it doesn't match with the client response. I cannot modify the client XSDs as that is out of my scope. However if a modification doesn't alter the namespaces and structure, I can give it a try.
Below are the XSDs for reference:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.xmlsoap.org/soap/envelope/"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="Common/SOAP_Fault_v4_0_0.xsd"/>
<xs:element name="Envelope">
<xs:complexType>
<xs:sequence>
<xs:element name="Body">
<xs:complexType>
<xs:choice>
<xs:element name="request">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="36"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element ref="env:Fault"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.xmlsoap.org/soap/envelope/"
elementFormDefault="qualified" attributeFormDefault="unqualified" version="4.0.0">
<xs:import schemaLocation="SOAP_FaultElements_v4_0_0.xsd"/>
<xs:element name="Fault">
<xs:complexType>
<xs:sequence>
<xs:element ref="faultstring"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified" version="4.0.0">
<xs:element name="faultstring">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="255"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
Looking for suggestions to resolve the issue.
来源:https://stackoverflow.com/questions/61372697/how-to-generate-java-classes-from-xsd-hierarchy-without-namespace