我关注了this和this示例,但效果很好。 然后我将xml和xsd文件更改为另一个导入3个其他xsd的文件,我继续这样做:
java.lang.ClassCastException: javax.xml.bind.JAXBElement cannot be cast to org.eclipse.persistence.dynamic.DynamicEntity
我实现了EntityResolver并检查了所有xml文件的位置,将noCorrectnessCheck属性设置为true,但无法使其正常工作。
这是第一个XSD:
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://mycompany.com/pmac/servico-saldo-req"
elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:pmac-saldo="http://mycompany.com/pmac/servico-saldo-req"
xmlns:pmac-entrada="http://mycompany.com/pmac/modo-entrada-siper"
xmlns:pmac-header="http://mycompany.com/pmac/header" xmlns:pmac-neg="http://mycompany.com/pmac/pmac-negocial">
<import schemaLocation="modo-entrada-siper.xsd"
namespace="http:/mycompany.com/pmac/modo-entrada-siper">
</import>
<import schemaLocation="header-pmac.xsd"
namespace="http://mycompany.com/pmac/header">
</import>
<import schemaLocation="pmac-negocial.xsd" namespace="http://mycompany.com/pmac/pmac-negocial"></import>
<complexType name="servico">
<sequence>
<element name="header" type="pmac-header:header-pmac"
minOccurs="1" maxOccurs="1">
</element>
<element name="modo-entrada"
type="pmac-entrada:entrada-siper" minOccurs="1" maxOccurs="1">
</element>
<element name="negocial" type="pmac-neg:consulta-saldo" minOccurs="1" maxOccurs="1"></element>
</sequence>
</complexType>
<element name="servico-canal" type="pmac-saldo:servico"></element>
</schema>
这是第一次导入:
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://mycompany.com/pmac/modo-entrada-siper" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:pmac-entrada="http://mycompany.com/pmac/modo-entrada-siper">
<complexType name="entrada-siper">
<sequence>
<element name="codigo-modo" type="int" minOccurs="1"
maxOccurs="1">
</element>
<element name="opcao" type="int" minOccurs="1"
maxOccurs="1">
</element>
<element name="cpf" type="string" minOccurs="1"
maxOccurs="1">
</element>
<element name="token" type="pmac-entrada:token-siper" minOccurs="1" maxOccurs="1"></element>
</sequence>
</complexType>
<complexType name="token-siper">
<sequence>
<element name="acao" type="int" minOccurs="1"
maxOccurs="1">
</element>
<element name="sessao" type="string" minOccurs="1"
maxOccurs="1">
</element>
<element name="endereco-ip" type="string" minOccurs="1"
maxOccurs="1">
</element>
<element name="token-sessao" type="string" minOccurs="1" maxOccurs="1"></element>
</sequence>
</complexType>
</schema>
第二次进口:
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://mycompany.com/pmac/header" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:pmac-header="http://mycompany.com/pmac/header">
<complexType name="header-pmac">
<sequence>
<element name="versao" type="int" minOccurs="1"
maxOccurs="1">
</element>
<element name="codigo-canal" type="int" minOccurs="1"
maxOccurs="1">
</element>
<element name="codigo-servico" type="int" minOccurs="1"
maxOccurs="1">
</element>
<element name="nsu-canal" type="int" minOccurs="1"
maxOccurs="1">
</element>
<element name="data-solicitacao" type="date" minOccurs="1"
maxOccurs="1">
</element>
<element name="hora-solicitacao" type="time" minOccurs="1"
maxOccurs="1">
</element>
<element name="data-contabil" type="date" minOccurs="0"
maxOccurs="1">
</element>
<element name="hora-contabil" type="time" minOccurs="0" maxOccurs="1"></element>
</sequence>
</complexType>
</schema>
第三次进口:
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://mycompany.com/pmac/pmac-negocial" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:pmac-neg="http://mycompany.com/pmac/pmac-negocial">
<complexType name="conta">
<sequence>
<element name="agencia-conta" minOccurs="1" maxOccurs="1">
<simpleType>
<restriction base="int">
<pattern value="[0-9]{4}"></pattern>
</restriction>
</simpleType>
</element>
<element name="operacao-conta" minOccurs="1"
maxOccurs="1">
<simpleType>
<restriction base="int">
<pattern value="[0-9]{3}"></pattern>
</restriction>
</simpleType>
</element>
<element name="numero-conta" maxOccurs="1" minOccurs="1">
<simpleType>
<restriction base="int">
<pattern value="[0-9]{8}"></pattern>
</restriction>
</simpleType>
</element>
<element name="dv-conta" minOccurs="1" maxOccurs="1">
<simpleType>
<restriction base="int">
<pattern value="[0-9]{1}"></pattern>
</restriction>
</simpleType>
</element>
</sequence>
</complexType>
<complexType name="consulta-saldo">
<sequence>
<element name="conta-sidec" type="pmac-neg:conta"
minOccurs="1" maxOccurs="1">
</element>
<element name="tipo-saldo" type="string" minOccurs="1" maxOccurs="1"></element>
</sequence>
</complexType>
</schema>
这是XML:
<?xml version="1.0" encoding="UTF-8"?>
<pmac-saldo:servico-canal xmlns:pmac-entrada="http://mycompany.com/pmac/modo-entrada-siper"
xmlns:pmac-header="http://mycompany.com/pmac/header" xmlns:pmac-neg="http://mycompany.com/pmac/pmac-negocial"
xmlns:pmac-saldo="http://mycompany.com/pmac/servico-saldo-req"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mycompany.com/pmac/servico-saldo-req ../schema/servico-saldo-req.xsd ">
<pmac-saldo:header>
<pmac-header:versao>1</pmac-header:versao>
<pmac-header:codigo-canal>3</pmac-header:codigo-canal>
<pmac-header:codigo-servico>000001</pmac-header:codigo-servico>
<pmac-header:nsu-canal>1</pmac-header:nsu-canal>
<pmac-header:data-solicitacao>2013-07-05</pmac-header:data-solicitacao>
<pmac-header:hora-solicitacao>18:00:00</pmac-header:hora-solicitacao>
<pmac-header:data-contabil>2013-07-18</pmac-header:data-contabil>
<pmac-header:hora-contabil>10:00:00</pmac-header:hora-contabil>
</pmac-saldo:header>
<pmac-saldo:modo-entrada>
<pmac-entrada:codigo-modo>1</pmac-entrada:codigo-modo>
<pmac-entrada:opcao>0</pmac-entrada:opcao>
<pmac-entrada:cpf>03432252200</pmac-entrada:cpf>
<pmac-entrada:token>
<pmac-entrada:acao>1</pmac-entrada:acao>
<pmac-entrada:sessao>3c95ce29b0d4d6c00b467a3871aac</pmac-entrada:sessao>
<pmac-entrada:endereco-ip>127.0.0.1</pmac-entrada:endereco-ip>
<pmac-entrada:token-sessao>WHUxpCMkyuF7xCXUJJt6tgFupGHXzg6HfX92rz4UBIK6AbvIcXH93sg7rNid</pmac-entrada:token-sessao>
</pmac-entrada:token>
</pmac-saldo:modo-entrada>
<pmac-saldo:negocial>
<pmac-neg:conta-sidec>
<pmac-neg:agencia-conta>1679</pmac-neg:agencia-conta>
<pmac-neg:operacao-conta>001</pmac-neg:operacao-conta>
<pmac-neg:numero-conta>00000155</pmac-neg:numero-conta>
<pmac-neg:dv-conta>8</pmac-neg:dv-conta>
</pmac-neg:conta-sidec>
<pmac-neg:tipo-saldo>disponivel</pmac-neg:tipo-saldo>
</pmac-saldo:negocial>
</pmac-saldo:servico-canal>