我的XSD文件包含:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc"
elementFormDefault="qualified"
targetNamespace="http://example.org/">
<xsd:complexType name="Certificate">
<xsd:sequence>
<xsd:element name="certificate" type="xsd:base64Binary">
<xsd:annotation>
<xsd:appinfo>
<xjc:javaType name="java.security.cert.X509Certificate" adapter="adapters.X509CertificateAdapter" />
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<xsd:complexType name="User">
<xsd:sequence>
<xsd:element name="certificate" type="xsd:base64Binary">
<xsd:annotation>
<xsd:appinfo>
<xjc:javaType name="java.security.cert.X509Certificate" adapter="adapters.X509CertificateAdapter" />
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Server">
<xsd:sequence>
<xsd:element name="document" type="xsd:base64Binary" />
</xsd:sequence>
</xsd:complexType>
我想将xjc javaType适配器导出到外部.xjb文件。在此文件中,我想为certificate
类型的所有xsd:base64Binary
元素设置此适配器,但document
复杂类型中的Server
元素不适用xsd:base64Binary
元素} type。
我该怎么做?
答案 0 :(得分:12)
在
中更改您的xsd<xsd:complexType name="Certificate">
<xsd:sequence>
<xsd:element name="certificate" type="xsd:base64Binary"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="User">
<xsd:sequence>
<xsd:element name="certificate" type="xsd:base64Binary"/>
<xsd:element name="name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Server">
<xsd:sequence>
<xsd:element name="document" type="xsd:base64Binary" />
</xsd:sequence>
</xsd:complexType>
并添加此绑定配置
<bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:annox="http://annox.dev.java.net"
xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix">
<bindings schemaLocation="yourXSD.xsd">
<bindings node="//xsd:complexType[@name='Certificate']//xsd:sequence//xsd:element[@name='certificate']">
<xjc:javaType name="java.security.cert.X509Certificate" adapter="adapters.X509CertificateAdapter" />
</bindings>
<bindings node="//xsd:complexType[@name='User']//xsd:sequence//xsd:element[@name='certificate']">
<xjc:javaType name="java.security.cert.X509Certificate" adapter="adapters.X509CertificateAdapter" />
</bindings>
</bindings>
</bindings>