Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » URI converting - set resource base
URI converting - set resource base [message #40810] Fri, 09 April 2004 10:49 Go to next message
Christian Stein is currently offline Christian SteinFriend
Messages: 29
Registered: July 2009
Junior Member
Hello NewsGroup (aka Ed...)!

is it possible to set a resource base which is prepended
to all *relative* schemaLocation tag values that *do not*
start with "./"?

The simple solution

map.put(URI.createURI("./"), URI.createURI("./my/folder/"));

does not always work here, as some schemaLocations just
contain the simple file name. A possible solution could be a
directory change to where the root schema is located. But,
AFAIK, you can't change users' current directory "user.dir"...

Regards,
Christian

--

Current directory: /


Green example "/my/folder/main1.xsd":

<xs:schema targetNamespace="MAINSPACE" ...>

<xs:import namespace="IMPORTSPACE" schemaLocation="./import.xsd"/>

</xs:schema>



Not working example "/my/folder/main2.xsd":

<xs:schema targetNamespace="MAINSPACE" ...>

<xs:import namespace="IMPORTSPACE" schemaLocation="import.xsd"/>

</xs:schema>
Re: URI converting - set resource base [message #40844 is a reply to message #40810] Fri, 09 April 2004 12:34 Go to previous messageGo to next message
Christian Stein is currently offline Christian SteinFriend
Messages: 29
Registered: July 2009
Junior Member
On Fri, 09 Apr 2004 12:49:38 +0200, Christian Stein <sormuras@web.de>
wrote:

> Hello NewsGroup (aka Ed...)!
>
> is it possible to set a resource base which is prepended
> to all *relative* schemaLocation tag values that *do not*
> start with "./"?
>
> The simple solution
>
> map.put(URI.createURI("./"), URI.createURI("./my/folder/"));
>
> does not always work here, as some schemaLocations just
> contain the simple file name. A possible solution could be a
> directory change to where the root schema is located. But,
> AFAIK, you can't change users' current directory "user.dir"...
>

I use this work-around(?) for now:

// String name = "main2.xsd";
// String name = "folder/textmain2.xsd";
// String name = "/my/folder/textmain2.xsd";

String name = "my/folder/textmain2.xsd";

java.io.File file = new java.io.File(name).getAbsoluteFile();

System.setProperty("user.dir", file.getParent());

set.getResource(URI.createURI(file.getName()), true);

This only works, because XSD uses System.getProperty("user.dir") or
a similiar "magic". As long it does, that's ok for me...

Sorry for bothering,
Christian

--

Still learning Java basics after 6 years... ;)
Re: URI converting - set resource base [message #40969 is a reply to message #40844] Mon, 12 April 2004 10:52 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Christian,

I'm not sure exactly what you are doing, but you can always override the
resource set's URI converter's normalize method to do additional funky
stuff. Just be aware that relative schema locations within documents,
i.e., in an include's or import's schemaLocation, typically need to be
resolved against the absolute location of the containing schema and if
that location isn't an absolute URI, resolve isn't well defined. It's
really best to ensure that each resource URI is absolute.

If you want things to be "relocatable" I would suggest something like:

map.put(URI.createURI("pathmap://base-location/",
"c:/actual-location/");

and using absolute URI's of the form "pathmap://base-location/..." for
the resources...



Christian Stein wrote:

> On Fri, 09 Apr 2004 12:49:38 +0200, Christian Stein <sormuras@web.de>
> wrote:
>
> > Hello NewsGroup (aka Ed...)!
> >
> > is it possible to set a resource base which is prepended
> > to all *relative* schemaLocation tag values that *do not*
> > start with "./"?
> >
> > The simple solution
> >
> > map.put(URI.createURI("./"), URI.createURI("./my/folder/"));
> >
> > does not always work here, as some schemaLocations just
> > contain the simple file name. A possible solution could be a
> > directory change to where the root schema is located. But,
> > AFAIK, you can't change users' current directory "user.dir"...
> >
>
> I use this work-around(?) for now:
>
> // String name = "main2.xsd";
> // String name = "folder/textmain2.xsd";
> // String name = "/my/folder/textmain2.xsd";
>
> String name = "my/folder/textmain2.xsd";
>
> java.io.File file = new java.io.File(name).getAbsoluteFile();
>
> System.setProperty("user.dir", file.getParent());
>
> set.getResource(URI.createURI(file.getName()), true);
>
> This only works, because XSD uses System.getProperty("user.dir") or
> a similiar "magic". As long it does, that's ok for me...
>
> Sorry for bothering,
> Christian
>
> --
>
> Still learning Java basics after 6 years... ;)
Re: URI converting - set resource base [message #585272 is a reply to message #40810] Fri, 09 April 2004 12:34 Go to previous message
Christian Stein is currently offline Christian SteinFriend
Messages: 29
Registered: July 2009
Junior Member
On Fri, 09 Apr 2004 12:49:38 +0200, Christian Stein <sormuras@web.de>
wrote:

> Hello NewsGroup (aka Ed...)!
>
> is it possible to set a resource base which is prepended
> to all *relative* schemaLocation tag values that *do not*
> start with "./"?
>
> The simple solution
>
> map.put(URI.createURI("./"), URI.createURI("./my/folder/"));
>
> does not always work here, as some schemaLocations just
> contain the simple file name. A possible solution could be a
> directory change to where the root schema is located. But,
> AFAIK, you can't change users' current directory "user.dir"...
>

I use this work-around(?) for now:

// String name = "main2.xsd";
// String name = "folder/textmain2.xsd";
// String name = "/my/folder/textmain2.xsd";

String name = "my/folder/textmain2.xsd";

java.io.File file = new java.io.File(name).getAbsoluteFile();

System.setProperty("user.dir", file.getParent());

set.getResource(URI.createURI(file.getName()), true);

This only works, because XSD uses System.getProperty("user.dir") or
a similiar "magic". As long it does, that's ok for me...

Sorry for bothering,
Christian

--

Still learning Java basics after 6 years... ;)
Re: URI converting - set resource base [message #585352 is a reply to message #40844] Mon, 12 April 2004 10:52 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31633
Registered: July 2009
Senior Member
Christian,

I'm not sure exactly what you are doing, but you can always override the
resource set's URI converter's normalize method to do additional funky
stuff. Just be aware that relative schema locations within documents,
i.e., in an include's or import's schemaLocation, typically need to be
resolved against the absolute location of the containing schema and if
that location isn't an absolute URI, resolve isn't well defined. It's
really best to ensure that each resource URI is absolute.

If you want things to be "relocatable" I would suggest something like:

map.put(URI.createURI("pathmap://base-location/",
"c:/actual-location/");

and using absolute URI's of the form "pathmap://base-location/.." for
the resources...



Christian Stein wrote:

> On Fri, 09 Apr 2004 12:49:38 +0200, Christian Stein <sormuras@web.de>
> wrote:
>
> > Hello NewsGroup (aka Ed...)!
> >
> > is it possible to set a resource base which is prepended
> > to all *relative* schemaLocation tag values that *do not*
> > start with "./"?
> >
> > The simple solution
> >
> > map.put(URI.createURI("./"), URI.createURI("./my/folder/"));
> >
> > does not always work here, as some schemaLocations just
> > contain the simple file name. A possible solution could be a
> > directory change to where the root schema is located. But,
> > AFAIK, you can't change users' current directory "user.dir"...
> >
>
> I use this work-around(?) for now:
>
> // String name = "main2.xsd";
> // String name = "folder/textmain2.xsd";
> // String name = "/my/folder/textmain2.xsd";
>
> String name = "my/folder/textmain2.xsd";
>
> java.io.File file = new java.io.File(name).getAbsoluteFile();
>
> System.setProperty("user.dir", file.getParent());
>
> set.getResource(URI.createURI(file.getName()), true);
>
> This only works, because XSD uses System.getProperty("user.dir") or
> a similiar "magic". As long it does, that's ok for me...
>
> Sorry for bothering,
> Christian
>
> --
>
> Still learning Java basics after 6 years... ;)


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:redefine
Next Topic:Settable properties for XSDSimpleTypeDefinition
Goto Forum:
  


Current Time: Wed Dec 02 22:58:26 GMT 2020

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

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

Back to the top