Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » import resolution and namespaces
import resolution and namespaces [message #602390] Tue, 19 June 2007 18:39
Tommaso is currently offline Tommaso
Messages: 6
Registered: July 2009
Junior Member
hi,
we are having problems in the resolution of imported schemas.

I enclose here an ultrasimplified version of the schema we are dealing
with.

nirstrict.xsd:
_________________________________________________

<xsd:schema
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:h="http://www.w3.org/HTML/1998/html4"
targetNamespace="http://www.normeinrete.it/nir/2.2/"
xmlns="http://www.normeinrete.it/nir/2.2/"
xmlns:dsp="http://www.normeinrete.it/nir/disposizioni/2.2/"
elementFormDefault="qualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>

<xsd:import namespace="http://www.w3.org/HTML/1998/html4"
schemaLocation="./h.xsd"/>

<!--<xsd:group name="elblocchi">
<xsd:choice>
<xsd:element ref="h:div"/>
<xsd:element ref="h:p"/>
<xsd:element ref="h:img"/>
<xsd:element ref="h:table"/>
</xsd:choice>
</xsd:group>-->

<xsd:element name="Legge" type="xsd:string" />


</xsd:schema>

_____________________________________________________

h.xsd :

<xsd:schema targetNamespace="http://www.w3.org/HTML/1998/html4"
xmlns="http://www.normeinrete.it/nir/2.2/"
xmlns:h="http://www.w3.org/HTML/1998/html4" elementFormDefault="qualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:import namespace="http://www.normeinrete.it/nir/2.2/"
schemaLocation="./nirstrict.xsd"/>

<xsd:element name="p" type="xsd:string" />

</xsd:schema>

_____________________________________________________



The problem is in the resolution of the imported schema h.xsd from the
main schema nirstrict.xsd


The code we are using is the following



/**
*
* @param schemaURL
* @return
* @throws Exception
*/
public static XSDSchema loadSchemaUsingResourceSet(String schemaURL)
throws Exception{

System.out.println("--> Loading Schema Using Resource Set @ url
"+schemaURL);

XSDResourceFactoryImpl resourceFactory = new XSDResourceFactoryImpl();

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",resourceFactory);


//////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// ////////////////////
//
// prende il path assoluto di schemaURL
//
File file = new File(schemaURL);
if (file.isFile())
schemaURL =
URI.createFileURI(file.getCanonicalFile().toString()).toStri ng();

// Create a resource set and load the main schema file into it.
ResourceSet resourceSet = new ResourceSetImpl();



//
resourceSet.getURIConverter().getURIMap().put(URI.createURI( "./xlink.xsd"),URI.createURI(" file:/home/tommaso/schemaWorkspace/xmLegesEditor/xsdData/NIR _XSD_completo/xlink.xsd "));//,URI.createURI("./xlink.xsd"));
//
resourceSet.getURIConverter().getURIMap().put(URI.createURI( "./h.xsd"),URI.createURI(" file:/home/tommaso/schemaWorkspace/xmLegesEditor/xsdData/NIR _XSD_completo/h.xsd "));//,URI.createURI("./h.xsd"));
//
resourceSet.getURIConverter().getURIMap().put(URI.createURI( "./dsp.xsd"),URI.createURI(" file:/home/tommaso/schemaWorkspace/xmLegesEditor/xsdData/NIR _XSD_completo/dsp.xsd "));//,URI.createURI("./dsp.xsd"));
//

System.err.println("URIMAP:
" +resourceSet.getURIConverter().getURIMap().entrySet().toStri ng());


resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_L OCATION,
Boolean.TRUE);


XSDResourceImpl xsdSchemaResource = null;
try
{
xsdSchemaResource =
(XSDResourceImpl)resourceSet.getResource(URI.createURI(schem aURL),true);
}
catch(Exception e)
{
System.err.println("Exception caught in method 'load schema using
ResourceSet' message = " + e.getMessage() + " xsdSchemaResource: " +
xsdSchemaResource);
}

Resource resource = (Resource)xsdSchemaResource;
if (resource instanceof XSDResourceImpl)
{
XSDResourceImpl xsdResource = (XSDResourceImpl)resource;
// Iterate over the schema's content's looking for directives.
XSDSchema xsdSchema = xsdResource.getSchema();
for (Iterator contents = xsdSchema.getContents().iterator();
contents.hasNext(); )
{
XSDSchemaContent xsdSchemaContent =
(XSDSchemaContent)contents.next();
if (xsdSchemaContent instanceof XSDSchemaDirective)
{
XSDSchemaDirective xsdSchemaDirective =
(XSDSchemaDirective)xsdSchemaContent;
if (xsdSchemaDirective.getResolvedSchema() == null){

System.err.println("Unresolved schema "+
xsdSchemaDirective.getSchemaLocation() +" in " + xsdResource.getURI());

if(xsdSchemaDirective instanceof XSDImport){
XSDImport xsdSchemaImport = (XSDImport)xsdSchemaDirective;
System.err.println(" IMPORT: namespace -->
"+xsdSchemaImport.getNamespace());
System.err.println(" IMPORT: location -->
"+xsdSchemaImport.getSchemaLocation());
}
}
else {
System.err.println("Resolved schema "+
xsdSchemaDirective.getSchemaLocation() +" in " + xsdResource.getURI());
if(xsdSchemaDirective instanceof XSDImport){
XSDImport xsdSchemaImport = (XSDImport)xsdSchemaDirective;
System.err.println(" IMPORT: namespace -->
"+xsdSchemaImport.getNamespace());
System.err.println(" IMPORT: location -->
"+xsdSchemaImport.getSchemaLocation());
}
}
}
}
return xsdResource.getSchema();
}
System.err.println("loadSchemaUsingResourceSet(" + schemaURL + ") did
not contain any schemas!");
return null;
}




What we noticed is that if elements of the imported xsd are referred in
the main schema like here:

<xsd:group name="elblocchi">
<xsd:choice>
<xsd:element ref="h:div"/>
<xsd:element ref="h:p"/>
<xsd:element ref="h:img"/>
<xsd:element ref="h:table"/>
</xsd:choice>
</xsd:group>



i.e. commenting out such block in nirstrict.xsd,

the import is resolved otherwise it is not.

see here the results in the two cases:

with references to h: elements

*****************
Resolved schema ./h.xsd in
file:/home/tommaso/schemaWorkspace/xmLegesEditor/xsdData/XSD _Test_2/nirstrict.xsd
IMPORT: namespace --> http://www.w3.org/HTML/1998/html4
IMPORT: location --> ./h.xsd
loaded schema
*****************

or without

*****************
Unresolved schema ./h.xsd in
file:/home/tommaso/schemaWorkspace/xmLegesEditor/xsdData/XSD _Test_2/nirstrict.xsd
IMPORT: namespace --> http://www.w3.org/HTML/1998/html4
IMPORT: location --> ./h.xsd
*****************



In the actual schemas we are using we have two different version, a light
and a strict version. The light version which refers imported elements in
the main schema is correctly resolved, in the strict, where the imported
elements are referred from other included xsd files and not in the main
one, the import resolution does not succeed.

Do you have any hint on what could be the reason? Do we need to perform a
recursive import resolution ove all the resources in the resourceSet ?
Notice that all works in cases of include instead of import.


We also tried various URI Mapping like

resourceSet.getURIConverter().getURIMap().put(URI.createURI( "./h.xsd"),URI.createURI(" file:/home/tommaso/schemaWorkspace/xmLegesEditor/xsdData/NIR _XSD_completo/h.xsd "));

or

resourceSet.getURIConverter().getURIMap().put(URI.createURI( "http://www.w3.org/HTML/1998/html4/"),URI.createURI("./h.xsd"));

but none solves the problem. Which is the correct URI mapping for a case
like our:

<xsd:import namespace="http://www.w3.org/HTML/1998/html4"
schemaLocation="./h.xsd"/>


Notice that, in the for cycle over the resources of the resourceSet, the
imported resources correctly inherit the absolute path from the main
resource.
In case you need the complete schema we are using I can send it. Running
xsdMainExample load and validate on it gives the same Unresolved import
problems.



Any help is greatly appreciated,

thanks in advance

Tommaso
Previous Topic:XSDSchema Loading
Next Topic:import resolution and namespaces
Goto Forum:
  


Current Time: Mon Oct 20 18:00:24 GMT 2014

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

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