Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » Incorrect validation
Incorrect validation [message #604616] Wed, 28 April 2010 12:07 Go to next message
Tsvetan Stoyanov is currently offline Tsvetan Stoyanov
Messages: 9
Registered: July 2009
Junior Member
Hi all,

I have a schema file(A1.xsd, ns="http://www.example.org/A") that imports another schema (B.xsd, ns="http://www.example.org/B"). This second schema imports another schema file that has the same target namespace as A1 - A.xsd, ns="http://www.example.org/A".
After loading an XSDSchema instance for A1.xsd, the validation returns an error saying that "Type reference 'http://www.example.org/A#A_ST_01' is unresolved".
Do I have to do something with the imports before invoking the schema validation?

10x
Tsvetan

Source code:

A1.xsd
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/A" xmlns:tns="http://www.example.org/A" elementFormDefault="qualified" xmlns:b="http://www.example.org/B">

<import namespace="http://www.example.org/B" schemaLocation="B.xsd"></import>


<complexType name="C_CT_02">
<sequence>
<element name="e1" type="tns:A_ST_01"></element>
<element name="e2" type="tns:A_ST_01NOTEXISTING" nillable="false"></element>
</sequence>
</complexType>
</schema>

B.xsd
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/B" xmlns:tns="http://www.example.org/B" elementFormDefault="qualified" xmlns:a="http://www.example.org/A">

<import schemaLocation="A.xsd" namespace="http://www.example.org/A"></import>

<complexType name="B_CT_01"></complexType>

<simpleType name="B_ST_01">
<restriction base="string"/>
</simpleType>

<element name="B_E_01" type="string"/>

<element name="B_E_02" type="tns:B_CT_01"/>

<element name="B_E_03" type="a:A_ST_01"/>

<element name="B_E_04" type="a:A_CT_01"/>
</schema>
A.xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/A" xmlns:tns="http://www.example.org/A" elementFormDefault="qualified">

<complexType name="A_CT_01"></complexType>

<simpleType name="A_ST_01">
<restriction base="string"/>
</simpleType>

<element name="A_E_01" type="string"></element>

<element name="A_E_02" type="tns:A_CT_01"></element>
</schema>
Java

ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_L OCATION, Boolean.TRUE);
URL entry = Activator.getDefault().getBundle().getResource("resources/original/A1.xsd ");
URI uri = URI.createURI(entry.toString());

XSDResourceImpl xsdResource = (XSDResourceImpl) resourceSet.getResource(uri, true);
XSDSchema schema = xsdResource.getSchema();
schema.validate();
EList<XSDDiagnostic> allDiagnostics = schema.getAllDiagnostics();
for (XSDDiagnostic diagnostic : allDiagnostics) {
System.out.println(diagnostic.getLine() + ":" + diagnostic.getMessage());
}
Re: Incorrect validation [message #604621 is a reply to message #604616] Wed, 28 April 2010 12:55 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26048
Registered: July 2009
Senior Member
Tsvetan,

A1.xsd will not generally see the indirect imports of any schemas it
directly imports so I don't expect A1.xsd to see what's in A.xsd. As
such, the error message is expected unless you add an include.


Tsvetan Stoyanov wrote:
> Hi all,
>
> I have a schema file(A1.xsd, ns="http://www.example.org/A") that
> imports another schema (B.xsd, ns="http://www.example.org/B"). This
> second schema imports another schema file that has the same target
> namespace as A1 - A.xsd, ns="http://www.example.org/A".
> After loading an XSDSchema instance for A1.xsd, the validation returns
> an error saying that "Type reference
> 'http://www.example.org/A#A_ST_01' is unresolved".
> Do I have to do something with the imports before invoking the schema
> validation?
>
> 10x
> Tsvetan
>
> Source code:
>
> A1.xsd
> <schema xmlns="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.example.org/A"
> xmlns:tns="http://www.example.org/A" elementFormDefault="qualified"
> xmlns:b="http://www.example.org/B">
>
> <import namespace="http://www.example.org/B"
> schemaLocation="B.xsd"></import>
>
>
> <complexType name="C_CT_02">
> <sequence> <element name="e1"
> type="tns:A_ST_01"></element>
> <element name="e2" type="tns:A_ST_01NOTEXISTING"
> nillable="false"></element>
> </sequence>
> </complexType>
> </schema>
>
> B.xsd
> <schema xmlns="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.example.org/B"
> xmlns:tns="http://www.example.org/B" elementFormDefault="qualified"
> xmlns:a="http://www.example.org/A">
>
> <import schemaLocation="A.xsd"
> namespace="http://www.example.org/A"></import>
>
> <complexType name="B_CT_01"></complexType>
>
> <simpleType name="B_ST_01">
> <restriction base="string"/>
> </simpleType>
>
> <element name="B_E_01" type="string"/>
>
> <element name="B_E_02" type="tns:B_CT_01"/>
>
> <element name="B_E_03" type="a:A_ST_01"/>
>
> <element name="B_E_04" type="a:A_CT_01"/>
> </schema>
> A.xsd
> <?xml version="1.0" encoding="UTF-8"?>
> <schema xmlns="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.example.org/A"
> xmlns:tns="http://www.example.org/A" elementFormDefault="qualified">
>
> <complexType name="A_CT_01"></complexType>
>
> <simpleType name="A_ST_01">
> <restriction base="string"/>
> </simpleType>
>
> <element name="A_E_01" type="string"></element>
>
> <element name="A_E_02" type="tns:A_CT_01"></element>
> </schema>
> Java
>
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_L OCATION,
> Boolean.TRUE);
> URL entry =
> Activator.getDefault().getBundle().getResource("resources/original/A1.xsd ");
>
> URI uri = URI.createURI(entry.toString());
>
> XSDResourceImpl xsdResource = (XSDResourceImpl)
> resourceSet.getResource(uri, true);
> XSDSchema schema = xsdResource.getSchema();
> schema.validate();
> EList<XSDDiagnostic> allDiagnostics = schema.getAllDiagnostics();
> for (XSDDiagnostic diagnostic : allDiagnostics) {
> System.out.println(diagnostic.getLine() + ":" +
> diagnostic.getMessage());
> }
>
Previous Topic:Can I use .xsd2ecore to specify class names to generate
Next Topic:Incorrect validation
Goto Forum:
  


Current Time: Wed Sep 17 21:46:18 GMT 2014

Powered by FUDForum. Page generated in 0.01653 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software