Hello evebody, I would like to know if anybody have alreary had the same problem.
I have a XML file that aro going to be validated from two XSD files using include tag because one of than uses elements from the other one.
So, when I´m trying to run it, an exception is launched, but if I build only onr XSD file with all the elements it works fine.
I´ll show you my code.
Thank´s if anybody can help.
Pessoa.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:obj="http://domain.com/xsd"
targetNamespace="http://domain.com/xsd"
elementFormDefault="qualified">
<xs:complexType name="Pessoa">
<xs:sequence>
<xs:element name="nome" type="xs:string"/>
<xs:element name="telefone" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
PessoaFisica.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:obj="http://domain.com/xsd"
targetNamespace="http://domain.com/xsd"
elementFormDefault="qualified">
<xs:include schemaLocation="Pessoa.xsd" />
<xs:complexType name="PessoaFisica">
<xs:complexContent>
<xs:extension base="obj:Pessoa">
<xs:sequence>
<xs:element name="cpf" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Simple.xml
<?xml version="1.0" encoding="UTF-8"?>
<xsd:PessoaFisica
xsi:type="xsd:PessoaFisica"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://domain.com/xsd">
<xsd:nome>Gabriel Oliveira</xsd:nome>
<xsd:telefone>12345678</xsd:telefone>
<xsd:cpf>12345678900</xsd:cpf>
</xsd:PessoaFisica>
The validation Test on Method Class
@Test
public void testeSimples() throws SAXException, IOException {
InputStream xml = TesteValidacao.class.getResourceAsStream("/Simple.xml");
InputStream xsd1 = TesteValidacao.class.getResourceAsStream("/Pessoa.xsd");
InputStream xsd2 = TesteValidacao.class.getResourceAsStream("/PessoaFisica.xsd");
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
StreamSource src1 = new StreamSource(xsd1);
StreamSource src2 = new StreamSource(xsd2);
Source[] sources = new Source[] {src1, src2};
Schema schema = factory.newSchema(sources);
Validator v = schema.newValidator();
v.validate(new StreamSource(xml));
}