[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jibx-users
Subject:    Re: [jibx-users] how to add XML Schema namespace and	schemaLocation
From:       Linus Kamb <linus () iris ! washington ! edu>
Date:       2004-09-21 15:18:22
Message-ID: 4150463E.1090008 () iris ! washington ! edu
[Download RAW message or body]

I do it this way as well, but as an aside, you don't need the getters and setters.  JiBX can access 
the fields directly.

You can add whatever you want in here, but the downside is that it has to be set by applicaiton logic.

public class IsisExchangeDoc
	implements edu.iris.dmc.app.JibxVersionedObject
{
	// XXX For JibX. YUK.
	private String _schemaNS = "http://www.w3.org/2001/XMLSchema-instance";
	private String _schemaFile = "file:/users/linus/workspace/isis/xml/isis.xsd";

	private String bindingVersion = null;
[...]
}

	<mapping class="edu.iris.dmc.isis.IsisExchangeDoc" name="IXDoc">
		<value field="_schemaNS"
			name="xmlns:xsi"
			style="attribute"
			usage="optional" />
		<!--default="http://www.w3.org/2001/XMLSchema-instance" /-->
		<!-- defaults are not really necessary since I don't care about setting them
			when unmarshalling. -->
		<value field="_schemaFile"
			name="xsi:noNamespaceSchemaLocation"
			style="attribute"
			usage="optional" />
		<!--default="file:/users/linus/workspace/isis/xml/isis.xsd"/-->
		<value field="bindingVersion" name="bindingVersion" style="attribute"
  			default="IXD"/>
[...]
	</mapping>

Tilman Linden wrote:
> this issue has been discussed on the list before., and i entered it in
> jira. i have the same problem. so far there does not seem to exist a
> real solution for it. 
> the only possibility to add the desired attribute 'xsi:schemaLocation' 
> is by adding get/set methods for it to your mapped classes.
> 
> i build a workaround to handle the cases 'xsi:schemaLocation' and
> 'xsi:noNamespaceSchemaLocation' by writing a class 'NSPInfo' which has
> to get/set method pairs:
> 
> class NSPInfo {
>   String schemaLocation = null;
>   String noNamespaceSchemaLocation = null;
>   public void setSchemaLocation(String sloc) {
>     schemaLocation = sloc; 
>   }
>   public void setNoNamespaceSchemaLocation(String nnsloc) {
>     noNamespaceSchemaLocation = nnsloc;
>   }	
>   public String getSchemaLocation() { 
>     return schemaLocation; 
>   }
>   public String getNoNamespaceSchemaLocation() { 
>     return noNamespaceSchemaLocation; 
>   }
> }
> 
> An instance of this class is referenced by the Class which is mapped to
> the Root-Element. 
> 
> class RootClass {
>   NSPInfo nspinfo; 
>   public NSPInfo getNamespaceInformation() {
>     return nspinfo;
>   }
>   public void setNamespaceInformation(NSPInfo nsp) {
>     nspinfo = nsp;
>   }
>   ....
> }
> 
> The binding is then something like:
> 
> <binding>
>   <namespace uri="http://www.w3.org/2001/XMLSchema-instance"
> prefix="xsi"/>
> 
>   <mapping name = "RootElement" class = "RootClass">
> 
>     <structure get-method="getNamespaceInformation"
> set-method="setNamespaceInformation">
>       <value style="attribute"
> ns="http://www.w3.org/2001/XMLSchema-instance"
> name="noNamespaceSchemaLocation"
> get-method="getNoNamespaceSchemaLocation"
> set-method="setNoNamespaceSchemaLocation"
> usage="optional"/>
>       <value style="attribute"
> ns="http://www.w3.org/2001/XMLSchema-instance" name="schemaLocation"
> get-method="getSchemaLocation" set-method="setSchemaLocation"
> usage="optional"/>
>     </structure>
>     
>     .....
>   </mapping>
>   ....
> </binding>
> 
> 
> This is not very nice (because these things should not have anything to
> do with the classes you map), but it should work... hopefully this cases
> will soon be handled by JiBX itself.
> 
> regards,
> 
> tilman
> 
> 
> 
> 
> On Mon, 2004-09-20 at 17:34, Bao Trang wrote:
> 
>>I want my root element to be defined as follows:
>>
>><Root xmlns="urn:us:gov:epa"
>>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>xsi:schemaLocation="urn:us:gov:epa
>>C:\jibx\test\testSchema.xsd"></Root>
>>
>>---------
>>
>>So far, the best I can do is to get the first ns defined: <Root
>>xmlns="urn:us:gov:epa">.
>>
>>How do I add the lines for the xml schema namespace and the xml schema location?
>>
>>
>>-------------------------------------------------------
>>This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
>>Project Admins to receive an Apple iPod Mini FREE for your judgement on
>>who ports your project to Linux PPC the best. Sponsored by IBM.
>>Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
>>_______________________________________________
>>jibx-users mailing list
>>jibx-users@lists.sourceforge.net
>>https://lists.sourceforge.net/lists/listinfo/jibx-users
>>
> 
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
> Project Admins to receive an Apple iPod Mini FREE for your judgement on
> who ports your project to Linux PPC the best. Sponsored by IBM.
> Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users


-- 
Linus Kamb
linus@iris.washington.edu
(206) 547-0393 x106



-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic