Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » Incorrect validation((Possibly) incorrect validation of imported schema)
Incorrect validation [message #530077] Wed, 28 April 2010 12:07 Go to next message
Tsvetan Stoyanov is currently offline Tsvetan StoyanovFriend
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_LOCATION, 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 #530090 is a reply to message #530077] Wed, 28 April 2010 12:55 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26226
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());
> }
>
Re: Incorrect validation [message #530107 is a reply to message #530090] Wed, 28 April 2010 13:44 Go to previous messageGo to next message
Tsvetan Stoyanov is currently offline Tsvetan StoyanovFriend
Messages: 9
Registered: July 2009
Junior Member
Hi Ed,

That's strange.
If I iterate over the schemes tree starting from A1, invoke importSchema() on each XSDImport and then update() the schema,
the error message is not shown anymore and the type definition is resolved.

Here is the code I'm using in order to make A1 see the indirect imports:

    
    private static void updateSchema(XSDSchema schema) {
    	if (schema == null)
    		return;
    	
        for (XSDSchemaContent ref : schema.getContents() ) {
        	if (ref instanceof XSDImport) {
        		((XSDImportImpl) ref).importSchema();
        		updateSchema(((XSDImport) ref).getResolvedSchema());
        	}
        }
        schema.update(true);
        
    }


Best Regards,
Tsvetan
Re: Incorrect validation [message #530112 is a reply to message #530107] Wed, 28 April 2010 13:52 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26226
Registered: July 2009
Senior Member
Tsvetan,

It's not supposed to see indirect imports.


Tsvetan Stoyanov wrote:
> Hi Ed,
>
> That's strange. If I iterate over the schemes tree starting from A1,
> invoke importSchema() on each XSDImport and then update() the schema,
> the error message is not shown anymore and the type definition is
> resolved.
>
> Here is the code I'm using in order to make A1 see the indirect imports:
>
> private static void updateSchema(XSDSchema schema) {
> if (schema == null)
> return;
>
> for (XSDSchemaContent ref : schema.getContents() ) {
> if (ref instanceof XSDImport) {
> ((XSDImportImpl) ref).importSchema();
> updateSchema(((XSDImport) ref).getResolvedSchema());
> }
> }
> schema.update(true);
> }
>
> Best Regards,
> Tsvetan
Re: Incorrect validation [message #604632 is a reply to message #530090] Wed, 28 April 2010 13:44 Go to previous message
Tsvetan Stoyanov is currently offline Tsvetan StoyanovFriend
Messages: 9
Registered: July 2009
Junior Member
Hi Ed,

That's strange.
If I iterate over the schemes tree starting from A1, invoke importSchema() on each XSDImport and then update() the schema,
the error message is not shown anymore and the type definition is resolved.

Here is the code I'm using in order to make A1 see the indirect imports:


private static void updateSchema(XSDSchema schema) {
if (schema == null)
return;

for (XSDSchemaContent ref : schema.getContents() ) {
if (ref instanceof XSDImport) {
((XSDImportImpl) ref).importSchema();
updateSchema(((XSDImport) ref).getResolvedSchema());
}
}
schema.update(true);

}

Best Regards,
Tsvetan
Re: Incorrect validation [message #604637 is a reply to message #604632] Wed, 28 April 2010 13:52 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26226
Registered: July 2009
Senior Member
Tsvetan,

It's not supposed to see indirect imports.


Tsvetan Stoyanov wrote:
> Hi Ed,
>
> That's strange. If I iterate over the schemes tree starting from A1,
> invoke importSchema() on each XSDImport and then update() the schema,
> the error message is not shown anymore and the type definition is
> resolved.
>
> Here is the code I'm using in order to make A1 see the indirect imports:
>
> private static void updateSchema(XSDSchema schema) {
> if (schema == null)
> return;
>
> for (XSDSchemaContent ref : schema.getContents() ) {
> if (ref instanceof XSDImport) {
> ((XSDImportImpl) ref).importSchema();
> updateSchema(((XSDImport) ref).getResolvedSchema());
> }
> }
> schema.update(true);
> }
>
> Best Regards,
> Tsvetan
Previous Topic:Incorrect validation
Next Topic:Missing element in XML editor autocompletion
Goto Forum:
  


Current Time: Thu Nov 27 03:22:23 GMT 2014

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

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