Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to add namespace info into XMLResource
How to add namespace info into XMLResource [message #416139] Fri, 18 January 2008 15:58 Go to next message
Eclipse UserFriend
Originally posted by: a.rahman.distilinteractive.com

Hi,

I am trying to add namespce info before saving an XMLResource. It is
someting like <anyElement
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="someLocation">.
I have checked the ExtendedMetaData and BasicExtendedMetaData classes, but
not very clear on how to use this classess for this issue.

I have tried :
((BasicExtendedMetaData)((XMLResource)resource).getDefaultSa veOptions().get(XMLResource.OPTION_EXTENDED_META_DATA)).setN amespace(somePackage.eINSTANCE.getDocumentRoot_SomeElemnt(),
"test");

which produeces : <test:anyElement xmlns:test="test" >.

Thanks,
-Anisur.
Re: How to add namespace info into XMLResource [message #416147 is a reply to message #416139] Fri, 18 January 2008 18:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Anisur,

Do you generate this model from a schema with no target namespace?
Generated models typically don't save a schemaLocation but if you are
using the resource factory generated for the package to create the
resource you could use the trick of doing
XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ")
and then, since the location doesn't match the namespace and since the
generated resource impl as the OPTION_SCHEMA_LOCATION set to true, it
should save an xsi:schemaLocation...


Anisur wrote:
> Hi,
>
> I am trying to add namespce info before saving an XMLResource. It is
> someting like <anyElement
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="someLocation">.
> I have checked the ExtendedMetaData and BasicExtendedMetaData classes, but
> not very clear on how to use this classess for this issue.
>
> I have tried :
> ((BasicExtendedMetaData)((XMLResource)resource).getDefaultSa veOptions().get(XMLResource.OPTION_EXTENDED_META_DATA)).setN amespace(somePackage.eINSTANCE.getDocumentRoot_SomeElemnt(),
> "test");
>
> which produeces : <test:anyElement xmlns:test="test" >.
>
> Thanks,
> -Anisur.
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to add namespace info into XMLResource [message #416160 is a reply to message #416147] Fri, 18 January 2008 21:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: a.rahman.distilinteractive.com

Hi Ed,

Thank you for your reply. I am using the resource factory generated for the
package., and included
XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ") , but
still does not generates the output.
Following is the code sample:

My..Package.eINSTANCE.eResource().setURI(someURI);

My..ResourceFactoryImpl factory = new My..ResourceFactoryImpl();

Resource resource = factory.createResource(uri);

((XMLResource)resource).getDefaultSaveOptions().put(XMLResou rce.OPTION_SCHEMA_LOCATION,Boolean.TRUE);


DocumentRoot root = My..Factory.eINSTANCE.createDocumentRoot();

root.set......(someObject);

resource.getContents().add(root);



try {

resource.save(null);


} catch (IOException e) { }



Thanks,

-Anisur.






"Ed Merks" <merks@ca.ibm.com> wrote in message
news:fmqqms$emg$1@build.eclipse.org...
> Anisur,
>
> Do you generate this model from a schema with no target namespace?
> Generated models typically don't save a schemaLocation but if you are
> using the resource factory generated for the package to create the
> resource you could use the trick of doing
> XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ") and
> then, since the location doesn't match the namespace and since the
> generated resource impl as the OPTION_SCHEMA_LOCATION set to true, it
> should save an xsi:schemaLocation...
>
>
> Anisur wrote:
>> Hi,
>>
>> I am trying to add namespce info before saving an XMLResource. It is
>> someting like <anyElement
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:noNamespaceSchemaLocation="someLocation">.
>> I have checked the ExtendedMetaData and BasicExtendedMetaData classes,
>> but not very clear on how to use this classess for this issue.
>>
>> I have tried :
>> ((BasicExtendedMetaData)((XMLResource)resource).getDefaultSa veOptions().get(XMLResource.OPTION_EXTENDED_META_DATA)).setN amespace(somePackage.eINSTANCE.getDocumentRoot_SomeElemnt(),
>> "test");
>>
>> which produeces : <test:anyElement xmlns:test="test" >.
>>
>> Thanks,
>> -Anisur.
>>
>>
>>
>>
Re: How to add namespace info into XMLResource [message #416161 is a reply to message #416160] Fri, 18 January 2008 21:32 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070101020503030100060809
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Anisur,

I'm looking into why this doesn't work for a null namespace package like
it does for any other package... In the meantime, you can use:

root.getXSISchemaLocation().put(null, "someLocation");


Anisur wrote:
> Hi Ed,
>
> Thank you for your reply. I am using the resource factory generated for the
> package., and included
> XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ") , but
> still does not generates the output.
> Following is the code sample:
>
> My..Package.eINSTANCE.eResource().setURI(someURI);
>
> My..ResourceFactoryImpl factory = new My..ResourceFactoryImpl();
>
> Resource resource = factory.createResource(uri);
>
> ((XMLResource)resource).getDefaultSaveOptions().put(XMLResou rce.OPTION_SCHEMA_LOCATION,Boolean.TRUE);
>
>
> DocumentRoot root = My..Factory.eINSTANCE.createDocumentRoot();
>
> root.set......(someObject);
>
> resource.getContents().add(root);
>
>
>
> try {
>
> resource.save(null);
>
>
> } catch (IOException e) { }
>
>
>
> Thanks,
>
> -Anisur.
>
>
>
>
>
>
> "Ed Merks" <merks@ca.ibm.com> wrote in message
> news:fmqqms$emg$1@build.eclipse.org...
>
>> Anisur,
>>
>> Do you generate this model from a schema with no target namespace?
>> Generated models typically don't save a schemaLocation but if you are
>> using the resource factory generated for the package to create the
>> resource you could use the trick of doing
>> XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ") and
>> then, since the location doesn't match the namespace and since the
>> generated resource impl as the OPTION_SCHEMA_LOCATION set to true, it
>> should save an xsi:schemaLocation...
>>
>>
>> Anisur wrote:
>>
>>> Hi,
>>>
>>> I am trying to add namespce info before saving an XMLResource. It is
>>> someting like <anyElement
>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xsi:noNamespaceSchemaLocation="someLocation">.
>>> I have checked the ExtendedMetaData and BasicExtendedMetaData classes,
>>> but not very clear on how to use this classess for this issue.
>>>
>>> I have tried :
>>> ((BasicExtendedMetaData)((XMLResource)resource).getDefaultSa veOptions().get(XMLResource.OPTION_EXTENDED_META_DATA)).setN amespace(somePackage.eINSTANCE.getDocumentRoot_SomeElemnt(),
>>> "test");
>>>
>>> which produeces : <test:anyElement xmlns:test="test" >.
>>>
>>> Thanks,
>>> -Anisur.
>>>
>>>
>>>
>>>
>>>
>
>
>


--------------070101020503030100060809
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Anisur,<br>
<br>
I'm looking into why this doesn't work for a null namespace package
like it does for any other package...&nbsp; In the meantime, you can use:<br>
<blockquote>root.getXSISchemaLocation().put(null, "someLocation");<br>
</blockquote>
<br>
Anisur wrote:
<blockquote cite="mid:fmr4nm$hif$1@build.eclipse.org" type="cite">
<pre wrap="">Hi Ed,

Thank you for your reply. I am using the resource factory generated for the
package., and included
XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ") , but
still does not generates the output.
Following is the code sample:

My..Package.eINSTANCE.eResource().setURI(someURI);

My..ResourceFactoryImpl factory = new My..ResourceFactoryImpl();

Resource resource = factory.createResource(uri);

((XMLResource)resource).getDefaultSaveOptions().put(XMLResou rce.OPTION_SCHEMA_LOCATION,Boolean.TRUE);


DocumentRoot root = My..Factory.eINSTANCE.createDocumentRoot();

root.set......(someObject);

resource.getContents().add(root);



try {

resource.save(null);


} catch (IOException e) { }



Thanks,

-Anisur.






"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:fmqqms$emg$1@build.eclipse.org">news:fmqqms$emg$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Anisur,

Do you generate this model from a schema with no target namespace?
Generated models typically don't save a schemaLocation but if you are
using the resource factory generated for the package to create the
resource you could use the trick of doing
XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ") and
then, since the location doesn't match the namespace and since the
generated resource impl as the OPTION_SCHEMA_LOCATION set to true, it
should save an xsi:schemaLocation...


Anisur wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi,

I am trying to add namespce info before saving an XMLResource. It is
someting like &lt;anyElement
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xsi:noNamespaceSchemaLocation="someLocation"&gt;.
I have checked the ExtendedMetaData and BasicExtendedMetaData classes,
but not very clear on how to use this classess for this issue.

I have tried :
((BasicExtendedMetaData)((XMLResource)resource).getDefaultSa veOptions().get(XMLResource.OPTION_EXTENDED_META_DATA)).setN amespace(somePackage.eINSTANCE.getDocumentRoot_SomeElemnt(),
"test");

which produeces : &lt;test:anyElement xmlns:test="test" &gt;.

Thanks,
-Anisur.




</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------070101020503030100060809--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to add namespace info into XMLResource [message #416191 is a reply to message #416161] Mon, 21 January 2008 16:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: a.rahman.distilinteractive.com

Hi Ed,
Thank you for your reply. Using root.getXSISchemaLocation().put(null,
"someLocation") saves the schema location. However, the scheman location is
changed changed intor relative to the current resource location. I am using
the locations as "file:/.........someXsdFile.xsd", however it is changed
into "../.../someXsdFile.xsd", doing so, if the file copied into different
filelocation of the same computer, xsd info becomes invalid.
Thank you,
-Anisur.


"Ed Merks" <merks@ca.ibm.com> wrote in message
news:fmr5tf$to0$1@build.eclipse.org...
> Anisur,
>
> I'm looking into why this doesn't work for a null namespace package like
> it does for any other package... In the meantime, you can use:
>
> root.getXSISchemaLocation().put(null, "someLocation");
>
>
> Anisur wrote:
>> Hi Ed,
>>
>> Thank you for your reply. I am using the resource factory generated for
>> the
>> package., and included
>> XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ") ,
>> but
>> still does not generates the output.
>> Following is the code sample:
>>
>> My..Package.eINSTANCE.eResource().setURI(someURI);
>>
>> My..ResourceFactoryImpl factory = new My..ResourceFactoryImpl();
>>
>> Resource resource = factory.createResource(uri);
>>
>>
>> ((XMLResource)resource).getDefaultSaveOptions().put(XMLResou rce.OPTION_SCHEMA_LOCATION,Boolean.TRUE);
>>
>>
>> DocumentRoot root = My..Factory.eINSTANCE.createDocumentRoot();
>>
>> root.set......(someObject);
>>
>> resource.getContents().add(root);
>>
>>
>>
>> try {
>>
>> resource.save(null);
>>
>>
>> } catch (IOException e) { }
>>
>>
>>
>> Thanks,
>>
>> -Anisur.
>>
>>
>>
>>
>>
>>
>> "Ed Merks" <merks@ca.ibm.com> wrote in message
>> news:fmqqms$emg$1@build.eclipse.org...
>>
>>> Anisur,
>>>
>>> Do you generate this model from a schema with no target namespace?
>>> Generated models typically don't save a schemaLocation but if you are
>>> using the resource factory generated for the package to create the
>>> resource you could use the trick of doing
>>> XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ")
>>> and
>>> then, since the location doesn't match the namespace and since the
>>> generated resource impl as the OPTION_SCHEMA_LOCATION set to true, it
>>> should save an xsi:schemaLocation...
>>>
>>>
>>> Anisur wrote:
>>>
>>>> Hi,
>>>>
>>>> I am trying to add namespce info before saving an XMLResource. It is
>>>> someting like <anyElement
>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>> xsi:noNamespaceSchemaLocation="someLocation">.
>>>> I have checked the ExtendedMetaData and BasicExtendedMetaData classes,
>>>> but not very clear on how to use this classess for this issue.
>>>>
>>>> I have tried :
>>>> ((BasicExtendedMetaData)((XMLResource)resource).getDefaultSa veOptions().get(XMLResource.OPTION_EXTENDED_META_DATA)).setN amespace(somePackage.eINSTANCE.getDocumentRoot_SomeElemnt(),
>>>> "test");
>>>>
>>>> which produeces : <test:anyElement xmlns:test="test" >.
>>>>
>>>> Thanks,
>>>> -Anisur.
>>>>
>>>>
>>>>
>>>>
>>>>
>>
>>
>>
>
>
Re: How to add namespace info into XMLResource [message #416192 is a reply to message #416191] Mon, 21 January 2008 16:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090609030500030102070105
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Anisur,

That's true, but if the project containing both the instance and the
schema is both moved, then it will remain valid whereas the absolute
location would be correct. The absolute location is also not likely to
be correct across machines. You'd of course be best to use a schema
location that's truly portable across machines, like an http URI. Or
you could use a "symbolic" URI and define a URI mapping from the
symbolic location to a physical location...

You can use this option to influence/control how URIs are deresolved and
resolved:

/**
* A {@link URIHandler} value that will be used to control how
URIs are {@link URI#resolve(URI) resolved} during load
* and {@link URI#deresolve(URI) deresolved} during save.
* @see URI
* @see URIHandler
* @see XMLHelper#resolve(URI, URI)
* @see XMLHelper#deresolve(URI)
* @see URIHandlerImpl
*/
String OPTION_URI_HANDLER = "URI_HANDLER";



Anisur wrote:
> Hi Ed,
> Thank you for your reply. Using root.getXSISchemaLocation().put(null,
> "someLocation") saves the schema location. However, the scheman location is
> changed changed intor relative to the current resource location. I am using
> the locations as "file:/.........someXsdFile.xsd", however it is changed
> into "../.../someXsdFile.xsd", doing so, if the file copied into different
> filelocation of the same computer, xsd info becomes invalid.
> Thank you,
> -Anisur.
>
>
> "Ed Merks" <merks@ca.ibm.com> wrote in message
> news:fmr5tf$to0$1@build.eclipse.org...
>
>> Anisur,
>>
>> I'm looking into why this doesn't work for a null namespace package like
>> it does for any other package... In the meantime, you can use:
>>
>> root.getXSISchemaLocation().put(null, "someLocation");
>>
>>
>> Anisur wrote:
>>
>>> Hi Ed,
>>>
>>> Thank you for your reply. I am using the resource factory generated for
>>> the
>>> package., and included
>>> XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ") ,
>>> but
>>> still does not generates the output.
>>> Following is the code sample:
>>>
>>> My..Package.eINSTANCE.eResource().setURI(someURI);
>>>
>>> My..ResourceFactoryImpl factory = new My..ResourceFactoryImpl();
>>>
>>> Resource resource = factory.createResource(uri);
>>>
>>>
>>> ((XMLResource)resource).getDefaultSaveOptions().put(XMLResou rce.OPTION_SCHEMA_LOCATION,Boolean.TRUE);
>>>
>>>
>>> DocumentRoot root = My..Factory.eINSTANCE.createDocumentRoot();
>>>
>>> root.set......(someObject);
>>>
>>> resource.getContents().add(root);
>>>
>>>
>>>
>>> try {
>>>
>>> resource.save(null);
>>>
>>>
>>> } catch (IOException e) { }
>>>
>>>
>>>
>>> Thanks,
>>>
>>> -Anisur.
>>>
>>>
>>>
>>>
>>>
>>>
>>> "Ed Merks" <merks@ca.ibm.com> wrote in message
>>> news:fmqqms$emg$1@build.eclipse.org...
>>>
>>>
>>>> Anisur,
>>>>
>>>> Do you generate this model from a schema with no target namespace?
>>>> Generated models typically don't save a schemaLocation but if you are
>>>> using the resource factory generated for the package to create the
>>>> resource you could use the trick of doing
>>>> XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ")
>>>> and
>>>> then, since the location doesn't match the namespace and since the
>>>> generated resource impl as the OPTION_SCHEMA_LOCATION set to true, it
>>>> should save an xsi:schemaLocation...
>>>>
>>>>
>>>> Anisur wrote:
>>>>
>>>>
>>>>> Hi,
>>>>>
>>>>> I am trying to add namespce info before saving an XMLResource. It is
>>>>> someting like <anyElement
>>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>>> xsi:noNamespaceSchemaLocation="someLocation">.
>>>>> I have checked the ExtendedMetaData and BasicExtendedMetaData classes,
>>>>> but not very clear on how to use this classess for this issue.
>>>>>
>>>>> I have tried :
>>>>> ((BasicExtendedMetaData)((XMLResource)resource).getDefaultSa veOptions().get(XMLResource.OPTION_EXTENDED_META_DATA)).setN amespace(somePackage.eINSTANCE.getDocumentRoot_SomeElemnt(),
>>>>> "test");
>>>>>
>>>>> which produeces : <test:anyElement xmlns:test="test" >.
>>>>>
>>>>> Thanks,
>>>>> -Anisur.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>
>
>
>


--------------090609030500030102070105
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Anisur,<br>
<br>
That's true, but if the project containing both the instance and the
schema is both moved, then it will remain valid whereas the absolute
location would be correct.&nbsp; The absolute location is also not likely to
be correct across machines.&nbsp; You'd of course be best to use a schema
location that's truly portable across machines, like an http URI.&nbsp; Or
you could use a "symbolic" URI and define a URI mapping from the
symbolic location to a physical location...<br>
<br>
You can use this option to influence/control how URIs are deresolved
and resolved:<br>
<blockquote>&nbsp; /**<br>
&nbsp;&nbsp; * A {@link URIHandler} value that will be used to control how URIs
are {@link URI#resolve(URI) resolved} during load <br>
&nbsp;&nbsp; * and {@link URI#deresolve(URI) deresolved} during save.<br>
&nbsp;&nbsp; * @see URI<br>
&nbsp;&nbsp; * @see URIHandler<br>
&nbsp;&nbsp; * @see XMLHelper#resolve(URI, URI)<br>
&nbsp;&nbsp; * @see XMLHelper#deresolve(URI)<br>
&nbsp;&nbsp; * @see URIHandlerImpl<br>
&nbsp;&nbsp; */<br>
&nbsp; String OPTION_URI_HANDLER = "URI_HANDLER";<br>
</blockquote>
<br>
<br>
Anisur wrote:
<blockquote cite="mid:fn2i2i$iah$1@build.eclipse.org" type="cite">
<pre wrap="">Hi Ed,
Thank you for your reply. Using root.getXSISchemaLocation().put(null,
"someLocation") saves the schema location. However, the scheman location is
changed changed intor relative to the current resource location. I am using
the locations as <a class="moz-txt-link-rfc2396E" href="file:/.........someXsdFile.xsd">"file:/.........someXsdFile.xsd "</a>, however it is changed
into "../.../someXsdFile.xsd", doing so, if the file copied into different
filelocation of the same computer, xsd info becomes invalid.
Thank you,
-Anisur.


"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:fmr5tf$to0$1@build.eclipse.org">news:fmr5tf$to0$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Anisur,

I'm looking into why this doesn't work for a null namespace package like
it does for any other package... In the meantime, you can use:

root.getXSISchemaLocation().put(null, "someLocation");


Anisur wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi Ed,

Thank you for your reply. I am using the resource factory generated for
the
package., and included
XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ") ,
but
still does not generates the output.
Following is the code sample:

My..Package.eINSTANCE.eResource().setURI(someURI);

My..ResourceFactoryImpl factory = new My..ResourceFactoryImpl();

Resource resource = factory.createResource(uri);


((XMLResource)resource).getDefaultSaveOptions().put(XMLResou rce.OPTION_SCHEMA_LOCATION,Boolean.TRUE);


DocumentRoot root = My..Factory.eINSTANCE.createDocumentRoot();

root.set......(someObject);

resource.getContents().add(root);



try {

resource.save(null);


} catch (IOException e) { }



Thanks,

-Anisur.






"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:fmqqms$emg$1@build.eclipse.org">news:fmqqms$emg$1@build.eclipse.org</a>...

</pre>
<blockquote type="cite">
<pre wrap="">Anisur,

Do you generate this model from a schema with no target namespace?
Generated models typically don't save a schemaLocation but if you are
using the resource factory generated for the package to create the
resource you could use the trick of doing
XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ")
and
then, since the location doesn't match the namespace and since the
generated resource impl as the OPTION_SCHEMA_LOCATION set to true, it
should save an xsi:schemaLocation...


Anisur wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Hi,

I am trying to add namespce info before saving an XMLResource. It is
someting like &lt;anyElement
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xsi:noNamespaceSchemaLocation="someLocation"&gt;.
I have checked the ExtendedMetaData and BasicExtendedMetaData classes,
but not very clear on how to use this classess for this issue.

I have tried :
((BasicExtendedMetaData)((XMLResource)resource).getDefaultSa veOptions().get(XMLResource.OPTION_EXTENDED_META_DATA)).setN amespace(somePackage.eINSTANCE.getDocumentRoot_SomeElemnt(),
"test");

which produeces : &lt;test:anyElement xmlns:test="test" &gt;.

Thanks,
-Anisur.





</pre>
</blockquote>
</blockquote>
<pre wrap="">

</pre>
</blockquote>
<pre wrap="">
</pre>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------090609030500030102070105--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to add namespace info into XMLResource [message #416193 is a reply to message #416192] Mon, 21 January 2008 17:11 Go to previous message
Eclipse UserFriend
Originally posted by: a.rahman.distilinteractive.com

Thank you very much Ed for the information. I got the point of this
behaviour. This behaviour allows to copy the whole project. Actually, I am
working on a RCP , where the schema is located in the installatin directory,
and never changes the location. However, the user is free to chose the
resource loaction any where in the local PC. Thank you again for helping me
and providing all the info.
-Anisur.

"Ed Merks" <merks@ca.ibm.com> wrote in message
news:fn2icd$kcn$1@build.eclipse.org...
> Anisur,
>
> That's true, but if the project containing both the instance and the
> schema is both moved, then it will remain valid whereas the absolute
> location would be correct. The absolute location is also not likely to
> be correct across machines. You'd of course be best to use a schema
> location that's truly portable across machines, like an http URI. Or
> you could use a "symbolic" URI and define a URI mapping from the
> symbolic location to a physical location...
>
> You can use this option to influence/control how URIs are deresolved and
> resolved:
>
> /**
> * A {@link URIHandler} value that will be used to control how
> URIs are {@link URI#resolve(URI) resolved} during load
> * and {@link URI#deresolve(URI) deresolved} during save.
> * @see URI
> * @see URIHandler
> * @see XMLHelper#resolve(URI, URI)
> * @see XMLHelper#deresolve(URI)
> * @see URIHandlerImpl
> */
> String OPTION_URI_HANDLER = "URI_HANDLER";
>
>
>
> Anisur wrote:
>> Hi Ed,
>> Thank you for your reply. Using root.getXSISchemaLocation().put(null,
>> "someLocation") saves the schema location. However, the scheman location
>> is
>> changed changed intor relative to the current resource location. I am
>> using
>> the locations as "file:/.........someXsdFile.xsd", however it is changed
>> into "../.../someXsdFile.xsd", doing so, if the file copied into
>> different
>> filelocation of the same computer, xsd info becomes invalid.
>> Thank you,
>> -Anisur.
>>
>>
>> "Ed Merks" <merks@ca.ibm.com> wrote in message
>> news:fmr5tf$to0$1@build.eclipse.org...
>>
>>> Anisur,
>>>
>>> I'm looking into why this doesn't work for a null namespace package like
>>> it does for any other package... In the meantime, you can use:
>>>
>>> root.getXSISchemaLocation().put(null, "someLocation");
>>>
>>>
>>> Anisur wrote:
>>>
>>>> Hi Ed,
>>>>
>>>> Thank you for your reply. I am using the resource factory generated for
>>>> the
>>>> package., and included
>>>> XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ") ,
>>>> but
>>>> still does not generates the output.
>>>> Following is the code sample:
>>>>
>>>> My..Package.eINSTANCE.eResource().setURI(someURI);
>>>>
>>>> My..ResourceFactoryImpl factory = new My..ResourceFactoryImpl();
>>>>
>>>> Resource resource = factory.createResource(uri);
>>>>
>>>>
>>>> ((XMLResource)resource).getDefaultSaveOptions().put(XMLResou rce.OPTION_SCHEMA_LOCATION,Boolean.TRUE);
>>>>
>>>>
>>>> DocumentRoot root = My..Factory.eINSTANCE.createDocumentRoot();
>>>>
>>>> root.set......(someObject);
>>>>
>>>> resource.getContents().add(root);
>>>>
>>>>
>>>>
>>>> try {
>>>>
>>>> resource.save(null);
>>>>
>>>>
>>>> } catch (IOException e) { }
>>>>
>>>>
>>>>
>>>> Thanks,
>>>>
>>>> -Anisur.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> "Ed Merks" <merks@ca.ibm.com> wrote in message
>>>> news:fmqqms$emg$1@build.eclipse.org...
>>>>
>>>>
>>>>> Anisur,
>>>>>
>>>>> Do you generate this model from a schema with no target namespace?
>>>>> Generated models typically don't save a schemaLocation but if you are
>>>>> using the resource factory generated for the package to create the
>>>>> resource you could use the trick of doing
>>>>> XyzPackage.eINSTANCE.eResource().setURI(URI.createURI("someLocation ")
>>>>> and
>>>>> then, since the location doesn't match the namespace and since the
>>>>> generated resource impl as the OPTION_SCHEMA_LOCATION set to true, it
>>>>> should save an xsi:schemaLocation...
>>>>>
>>>>>
>>>>> Anisur wrote:
>>>>>
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I am trying to add namespce info before saving an XMLResource. It is
>>>>>> someting like <anyElement
>>>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>>>> xsi:noNamespaceSchemaLocation="someLocation">.
>>>>>> I have checked the ExtendedMetaData and BasicExtendedMetaData
>>>>>> classes,
>>>>>> but not very clear on how to use this classess for this issue.
>>>>>>
>>>>>> I have tried :
>>>>>> ((BasicExtendedMetaData)((XMLResource)resource).getDefaultSa veOptions().get(XMLResource.OPTION_EXTENDED_META_DATA)).setN amespace(somePackage.eINSTANCE.getDocumentRoot_SomeElemnt(),
>>>>>> "test");
>>>>>>
>>>>>> which produeces : <test:anyElement xmlns:test="test" >.
>>>>>>
>>>>>> Thanks,
>>>>>> -Anisur.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>>
>>
>>
>>
>
>
Previous Topic:EMF model gobal registry lazy load?
Next Topic:ItemProvider and changeNotification
Goto Forum:
  


Current Time: Thu Apr 25 01:34:10 GMT 2024

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

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

Back to the top