xpath: prefix must resolve to a namespace:xsd - java

I am a rookie in using jaxb2. I get this error:"xpath: prefix must resolve to a namespace:xsd" and I have no clue how to fix it.
This appen because I have two xsd files that trying to design the same class but in different packages of my java application
<jxb:bindings schemaLocation="../documentazione/xsd/Global/datatypes_global_v62.xsd">
<jxb:schemaBindings>
<jxb:package name="com.companyname.plugin.entities.global" />
</jxb:schemaBindings>
<jxb:bindings node="//xsd:complexType[#name='Contact']">
<jxb:class name="GlobalContact" />
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="../documentazione/xsd/Global/pickupdatatypes_global-3.0.xsd">
<jxb:schemaBindings>
<jxb:package name="com.companyname.plugin.entities.pickup" />
</jxb:schemaBindings>
<jxb:bindings node="xsd://complexType[#name='contact']" >
<jxb:class name="Contact" />
</jxb:bindings>
</jxb:bindings>
I already tried to run the plugin, but I don't know how to fix the error.

How I fix the problem?
Simple! In the name space of my xjb file I was using:
<jxb:bindings version="2.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2000/10/XMLSchema-instance"
xs:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd">
And this was fine for most of my xjb files, but in my case I want to use complexType node. In this case I have to use:
<jxb:bindings version="2.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2000/10/XMLSchema-instance"
xs:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd">
the xmlns:xsd="http://www.w3.org/2001/XMLSchema help me to fix all my issue.

Related

JAXB Generating Classes Issue

I am trying to use Eclipse to generate a few Java Classes. But somehow I am running into issues. When I try to do it, I get this error:
parsing a schema...
compiling a schema...
[ERROR] A class/interface with the same name "com.xml.apis.schemas.MPLSVPNListItem" is already in use. Use a class customization to resolve this conflict.
line 9 of file:/C:/Workspace/MyFiles/WebContent/WEB-INF/XSDFiles/jaxb_binding.xml
[ERROR] (Relevant to above error) another "MPLSVPNListItem" is generated from here.
line 3122 of file:/C:/Workspace/MyFiles/WebContent/WEB-INF/XSDFiles/APIcTypes.xsd
[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 9 of file:/C:/Workspace/MyFiles/WebContent/WEB-INF/XSDFiles/jaxb_binding.xml
[ERROR] (Related to above error) This is the other declaration.
line 3122 of file:/C:/Workspace/MyFiles/WebContent/WEB-INF/XSDFiles/APIcTypes.xsd
Failed to produce code.
I am using the JAXB Binding file (jaxb_binding.xml):
<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.1">
<jxb:bindings
schemaLocation="APIcTypes.xsd">
<jxb:bindings
node="//xs:complexType[#name='MPLS-VPNListItem']">
<jxb:class name="MPLS_VPNListItem" />
</jxb:bindings>
</jxb:bindings>
<jxb:bindings
schemaLocation="APIcTypes.xsd">
<jxb:bindings
node="//xs:complexType[#name='MPLSVPNListItem']">
<jxb:class name="MPLSVPNListItem" />
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
Because I think these two tags are causing the problem.
I have to say that APIcTypes.xsd is actually an import in the XSD that I am trying to generate the classes for.
The includes structure is like:
API.xsd --> APIRequests.xsd --> APIcTypes.xsd --> APIsTypes.xsd.
I hope this is understandable. If you need any more info, please do let me know. Just cant get it to work!

Multiple <schemaBindings> are defined for the target namespace when defining package

I have 3 XSD's in my project. Two in the namespace "A" and one in namespace "B".
I want to generate XSD-1, XSD-2 (same namespace) into one package.
Then generate XSD-3 in to an different package.
I am trying to do this via the bindings.xjb file.
If I declare
<jxb:bindings schemaLocation="xsd1-namespaceA.xsd">
<jxb:schemaBindings>
<jxb:package name="com.xsdPrimary" />
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="xsd2-namespaceA.xsd">
<jxb:schemaBindings>
<jxb:package name="com.xsdPrimary" />
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="xsd3-namespaceB.xsd">
<jxb:schemaBindings>
<jxb:package name="com.xsdSecondary" />
</jxb:schemaBindings>
</jxb:bindings>
Then I get the error:
com.sun.istack.SAXParseException2: Multiple <schemaBindings> are defined for the target
namespace "http://www.jeff-test.org/namespaceA/"
If I remove the first two entries in the bindings file, then the generation works, but it puts all my classes in a package called "jeff-test.namespaceA" for namespaceA and all those from namespaceB in the package "com.xsdSecondary".
I want all the classes from namespace-A into one package and all those from namespace-B into another package.
Is this possible?
Multiple are defined for the target namespace "http://www.jeff-test.org/namespaceA/"
If I remove the first two entries in the bindings file, then the generation works, but it puts all my classes in a package called "jeff-test.namespaceA" for namespaceA...
Just remove just one of the entries for namespaceA. What's the logic behind removing both?
<jxb:bindings schemaLocation="xsd1-namespaceA.xsd">
<jxb:schemaBindings>
<jxb:package name="com.xsdPrimary" />
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="xsd3-namespaceB.xsd">
<jxb:schemaBindings>
<jxb:package name="com.xsdSecondary" />
</jxb:schemaBindings>
</jxb:bindings>
schemaBindings is considered once per namespace, it does not matter which schema file is it bound to (as long as this file is a part of the compilation).

How to rename complex type in a WSDL during stub generation

I am using wsimport
I need to rename a xs:complextype name=Address to prevent some build conflicts.
Here is a snippet of the WSDL:
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://fedex.com/ws/rate/v13" xmlns:s1="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://fedex.com/ws/rate/v13" name="RateServiceDefinitions">
<types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://fedex.com/ws/rate/v13">
<xs:complexType name="Address">…</xs:complexType>
....
</types>
....
</definitions>
I am using an external binding file:
<jxb:bindings
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns="http://fedex.com/ws/rate/v13"
xmlns:s1="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.1"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<jxb:globalBindings>
<jxb:javaType name="java.util.Calendar" xmlType="xs:dateTime" parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" printMethod="javax.xml.bind.DatatypeConverter.printDateTime" />
</jxb:globalBindings>
<jxb:bindings node="definitions/types/xs:schema/xs:complexType[#name='Address']/xs:complexType">
<!-- change java method name from addNumbers() to add() -->
<jxb:class name="FedExAddress"/>
</jxb:bindings>
</jxb:bindings>
When I execute the build I get the following message:
[wsimport] [ERROR] XPath evaluation of "definitions/types/xs:schema/xs:complexType[#name='Address']/xs:complexType" results in empty target node
[wsimport] line 14 of file:/Users/davidboyd/projects/heritage/hybris/bin/custom/cpdeliveryservice/fedex_binding.xml
I have looked at the following postings here, here and a couple of references as well reference 1 and reference 2
But do not understand as to why this is not working.
After taking a breather I was able to solve the issue my taking a second look at this.
So my resulting binding is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxws:bindings
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.1"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
wsdlLocation="/RateService_v13.wsdl"
>
<enableWrapperStyle>true</enableWrapperStyle>
<enableAsyncMapping>false</enableAsyncMapping>
<!-- convert all xs:dateTime to java type of Calendar -->
<jaxws:globalBindings>
<jxb:javaType name="java.util.Calendar" xmlType="xs:dateTime" parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" printMethod="javax.xml.bind.DatatypeConverter.printDateTime" />
</jaxws:globalBindings>
<!-- Rename Address to FedExAddress -->
<jaxws:bindings node="//xs:complexType[#name='Address']">
<jxb:class name="FedExAddress"/>
</jaxws:bindings>
</jaxws:bindings>

Generating JAXB classes with multiple prefixes using an external binding

I have a group of XSD files, as follows:
http://www.iana.org/assignments/xml-registry/schema/contact-1.0.xsd
http://www.iana.org/assignments/xml-registry/schema/domain-1.0.xsd
http://www.iana.org/assignments/xml-registry/schema/epp-1.0.xsd
http://www.iana.org/assignments/xml-registry/schema/eppcom-1.0.xsd
http://www.iana.org/assignments/xml-registry/schema/host-1.0.xsd
Most of them are dependent on each other, so I created the following catalog file to allow the JAXB compiler (XJC) to generate the classes.
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<public publicId="urn:ietf:params:xml:ns:contact-1.0" uri="contact-1.0.xsd"/>
<public publicId="urn:ietf:params:xml:ns:domain-1.0" uri="domain-1.0.xsd"/>
<public publicId="urn:ietf:params:xml:ns:epp-1.0" uri="epp-1.0.xsd"/>
<public publicId="urn:ietf:params:xml:ns:eppcom-1.0" uri="eppcom-1.0.xsd"/>
<public publicId="urn:ietf:params:xml:ns:host-1.0" uri="host-1.0.xsd"/>
<public publicId="urn:ietf:params:xml:ns:rgp-1.0" uri="rgp-1.0.xsd"/>
</catalog>
Unfortunately, there are some collisions between some of the generated class names, which I must resolve - according to some research I need to create an external bindings file.
I would like to prefix all classes that are directly generated from each XSD.
Imported XSDs should be ignored (e.g. epp-1.0 imports eppcom-1.0.xsd), since they will already be generated if I repeat the process for each XSD. (i.e. prefix by XSD namespace if possible)
Does anyone know how I can solve this issue?
Since the XSD files are maintained by a 3rd party, I do not have the option of modifying the XSDs directly. I have tried the following external binding, but it does not work:
<jxb:bindings version="2.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings scd="x-schema:epp" node="/xs:schema">
<jxb:schemaBindings>
<jxb:nameXmlTransform>
<jxb:typeName prefix="Epp" />
<jxb:elementName prefix="Epp" />
<jxb:modelGroupName prefix="Epp" />
<jxb:anonymousTypeName prefix="Epp" />
</jxb:nameXmlTransform>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings scd="x-schema:eppcom" node="/xs:schema">
<jxb:schemaBindings>
<jxb:nameXmlTransform>
<jxb:typeName prefix="EppCom" />
<jxb:elementName prefix="EppCom" />
<jxb:modelGroupName prefix="EppCom" />
<jxb:anonymousTypeName prefix="EppCom" />
</jxb:nameXmlTransform>
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>
Output:
parsing a schema...
[ERROR] XPath evaluation of "/xs:schema" results in empty target node
line 4 of file:/C:/Users/Jin%20Kim/workspace/registry/server/src/main/resources/xsd/bindings.xjb
[ERROR] XPath evaluation of "/xs:schema" results in empty target node
line 14 of file:/C:/Users/Jin%20Kim/workspace/registry/server/src/main/resources/xsd/bindings.xjb
Failed to parse a schema.

how use xmlAdapter in maven-jaxb-plugin

Hi I have xsd schema with base64Binary. when this plugin genereted this elemen looks like
#XmlElement(name = "element")
protected byte[] element;
but how can I tell to this plugin to use #XmlJavaTypeAdapter(HexBinaryAdapter.class) so I need something like this
#XmlJavaTypeAdapter(HexBinaryAdapter.class)
#XmlElement(name = "element")
protected byte[] element;
I hope that this is possible thx for help
PS: I cant modify classes which were generated by these plugin because they are always rewrited
You should create a JAXB schema bindings file that instructs the JAXB implementation to use the built in javax.xml.bind.DatatypeConverter to perform conversions to/from hexBinary.
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jxb:bindings schemaLocation="YourSchema.xsd">
<jxb:bindings node="//xs:element[#name='element']">
<jxb:property>
<jxb:baseType>
<jxb:javaType name="byte[]"
parseMethod="javax.xml.bind.DatatypeConverter.parseHexBinary"
printMethod="javax.xml.bind.DatatypeConverter.printHexBinary"/>
</jxb:baseType>
</jxb:property>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
For More Information
http://blog.bdoughan.com/2011/08/xml-schema-to-java-generating.html

Categories

Resources