Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » refactoring imports in a XSD
refactoring imports in a XSD [message #426688] Sun, 18 January 2009 22:35 Go to next message
Marcin Cylke is currently offline Marcin CylkeFriend
Messages: 61
Registered: July 2009
Member
Hi
I'm working on a large collection of XSD files and I want to copy some
complex types to different files. I'm not changing workspaces just moving
the type.

I'm doing this with code like this below:
XSDSchema xsdSchema = XSDFactory.eINSTANCE.createXSDSchema();
xsdSchema.setTargetNamespace(parentSchema.getTargetNamespace ());
xsdSchema.setSchemaForSchemaQNamePrefix("xsd");

Map<String, String> qNamePrefixToNamespaceMap =
xsdSchema.getQNamePrefixToNamespaceMap();
qNamePrefixToNamespaceMap.put(xsdSchema.getSchemaForSchemaQN amePrefix(),
XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
xsdSchema.getContents().add((XSDComplexTypeDefinition)
cplxType.cloneConcreteComponent(true, false));

Than I save it via resource set with uri of 'file:/path/in/my/fs' format.

My resulting XSD file looks like this:
<xsd:schema xmlns:Q1="http://ns1/query"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://ns1/query">
<xsd:complexType name="TQuery">
<xsd:sequence>
<xsd:element minOccurs="0" name="parameterSetOne"
type="Q1:Tparameters"/>
<xsd:element minOccurs="0" name="parameterSetTwo"
type="Q1:Tparameters"/>
...

What I don't like are those Q1 namespace prefixes. In my original schema I
have them named approprietly, and I would like to be able to preserve
this. I tried putting appropriate stuff - correct mappings of
prefix-namespace into qNamePrefixToNamespaceMap before serialization, but
that doesn't do the trick.

Any help would be appreciated.
Thanks in advance.
Marcin
Re: refactoring imports in a XSD [message #426689 is a reply to message #426688] Mon, 19 January 2009 01:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Marcin,

Comments below.

Marcin Cylke wrote:
> Hi
> I'm working on a large collection of XSD files and I want to copy some
> complex types to different files. I'm not changing workspaces just
> moving the type.
That's easier said than done...
>
> I'm doing this with code like this below:
> XSDSchema xsdSchema = XSDFactory.eINSTANCE.createXSDSchema();
> xsdSchema.setTargetNamespace(parentSchema.getTargetNamespace ());
> xsdSchema.setSchemaForSchemaQNamePrefix("xsd");
>
> Map<String, String> qNamePrefixToNamespaceMap =
> xsdSchema.getQNamePrefixToNamespaceMap();
>
> qNamePrefixToNamespaceMap.put(xsdSchema.getSchemaForSchemaQN amePrefix(),
> XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
> xsdSchema.getContents().add((XSDComplexTypeDefinition)
> cplxType.cloneConcreteComponent(true, false));
Keep in mind that this code will not preserve all details of the
original DOM...
>
> Than I save it via resource set with uri of 'file:/path/in/my/fs' format.
>
> My resulting XSD file looks like this:
> <xsd:schema xmlns:Q1="http://ns1/query"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://ns1/query">
> <xsd:complexType name="TQuery">
> <xsd:sequence>
> <xsd:element minOccurs="0" name="parameterSetOne"
> type="Q1:Tparameters"/>
> <xsd:element minOccurs="0" name="parameterSetTwo"
> type="Q1:Tparameters"/>
> ..
>
> What I don't like are those Q1 namespace prefixes. In my original
> schema I have them named approprietly, and I would like to be able to
> preserve this.
If you want to clone the DOM level details, you'd be better to import
the DOM node into the Document of the target schema, wrap that with a
complex type, and add that to the schema...
> I tried putting appropriate stuff - correct mappings of
> prefix-namespace into qNamePrefixToNamespaceMap before serialization,
> but that doesn't do the trick.
You could do it before you copy the clone into the schema, or fix the
generated prefixes after the fact.

Of course you'll soon discover that you need to add appropriate imports
or includes as well so that any referenced things are still visible.
>
> Any help would be appreciated.
> Thanks in advance.
> Marcin
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: refactoring imports in a XSD [message #426694 is a reply to message #426689] Mon, 19 January 2009 07:25 Go to previous messageGo to next message
Marcin Cylke is currently offline Marcin CylkeFriend
Messages: 61
Registered: July 2009
Member
Ed Merks wrote:

Hi

> If you want to clone the DOM level details, you'd be better to import
> the DOM node into the Document of the target schema, wrap that with a
> complex type, and add that to the schema...

Ok, I know how to copy a DOM node but how to correctly wrap it up as
XSDComplexType after the copy operation? Any code snippets?

and what data is lost in that transition? (cloning complex type not DOM
node). Maybe it is ok for me to ignore it.

> You could do it before you copy the clone into the schema, or fix the
> generated prefixes after the fact.

Well, it was my first guess, but I can't do that. After importing cloned
complex type into new XSDSchema, when I iterate over
xsdSchema.getQNamePrefixToNamespaceMap() I only get "xsd" element, which
I've added myself. There are no prefixes like Q1, Q2, etc.

> Of course you'll soon discover that you need to add appropriate imports
> or includes as well so that any referenced things are still visible.

Yes, that's natural :) I will handle this after the namespaces are ok.

Thanks and bye
Marcin
Re: refactoring imports in a XSD [message #426699 is a reply to message #426694] Mon, 19 January 2009 11:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Marcin,

Comments below.

Marcin Cylke wrote:
> Ed Merks wrote:
>
> Hi
>
>> If you want to clone the DOM level details, you'd be better to
>> import the DOM node into the Document of the target schema, wrap that
>> with a complex type, and add that to the schema...
>
> Ok, I know how to copy a DOM node but how to correctly wrap it up as
> XSDComplexType after the copy operation? Any code snippets?
XSDPrototypicalSchema.cloneComponent has an example for cloning
something in to the same DOM document.
>
> and what data is lost in that transition? (cloning complex type not
> DOM node). Maybe it is ok for me to ignore it.
The prefixes. :-P Also any non-schema namespace attributes and the
arbitrary DOM contents of annotations.
>
>> You could do it before you copy the clone into the schema, or fix the
>> generated prefixes after the fact.
>
> Well, it was my first guess, but I can't do that. After importing
> cloned complex type into new XSDSchema, when I iterate over
> xsdSchema.getQNamePrefixToNamespaceMap() I only get "xsd" element,
> which I've added myself. There are no prefixes like Q1, Q2, etc.
Bummer. I suppose XSDSchemaImpl.reconcileAttributes isn't being
called... Of course you can always get at the underlying DOM, but we
should probably improve this behavior in
XSDConcreteComponentImpl.niceCreateNamespaceAttribute to ensure such
demand-created prefixes are added to the map. Feel free to open a bugzilla.
> .
>
>> Of course you'll soon discover that you need to add appropriate
>> imports or includes as well so that any referenced things are still
>> visible.
>
> Yes, that's natural :) I will handle this after the namespaces are ok.
>
> Thanks and bye
> Marcin
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: refactoring imports in a XSD [message #426722 is a reply to message #426699] Mon, 19 January 2009 16:03 Go to previous messageGo to next message
Marcin Cylke is currently offline Marcin CylkeFriend
Messages: 61
Registered: July 2009
Member
Ed Merks wrote:

> XSDPrototypicalSchema.cloneComponent has an example for cloning
> something in to the same DOM document.

Ok, but what if I need to put the complex type into another DOM document?
Specifically I don't understand why - using the mentioned cloneComponent()
function - I'm getting a WRONG_DOCUMENT_ERR exception even though there is
element.cloneNode(true) called in that function.

What else needs to be taken care of?

> Bummer. I suppose XSDSchemaImpl.reconcileAttributes isn't being
> called... Of course you can always get at the underlying DOM, but we
> should probably improve this behavior in
> XSDConcreteComponentImpl.niceCreateNamespaceAttribute to ensure such
> demand-created prefixes are added to the map. Feel free to open a bugzilla.

Done.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=261518

Bye
Marcin
Re: refactoring imports in a XSD [message #426746 is a reply to message #426722] Tue, 20 January 2009 04:09 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050804080708040600050701
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Marcin,

Comments below.

Marcin Cylke wrote:
> Ed Merks wrote:
>
>> XSDPrototypicalSchema.cloneComponent has an example for cloning
>> something in to the same DOM document.
>
> Ok, but what if I need to put the complex type into another DOM
> document? Specifically I don't understand why - using the mentioned
> cloneComponent() function - I'm getting a WRONG_DOCUMENT_ERR exception
> even though there is element.cloneNode(true) called in that function.
>
> What else needs to be taken care of?
I was obtusely referring to this method with is the cross document
equivalent of cloning a node:

http://java.sun.com/javase/6/docs/api/org/w3c/dom/Document.h tml#importNode(org.w3c.dom.Node,%20boolean)
< http://java.sun.com/javase/6/docs/api/org/w3c/dom/Document.h tml#importNode%28org.w3c.dom.Node,%20boolean%29>

>
>> Bummer. I suppose XSDSchemaImpl.reconcileAttributes isn't being
>> called... Of course you can always get at the underlying DOM, but we
>> should probably improve this behavior in
>> XSDConcreteComponentImpl.niceCreateNamespaceAttribute to ensure such
>> demand-created prefixes are added to the map. Feel free to open a
>> bugzilla.
>
> Done.
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=261518
>
> Bye
> Marcin
>
>

--------------050804080708040600050701
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Marcin,<br>
<br>
Comments below.<br>
<br>
Marcin Cylke wrote:
<blockquote
cite="mid:25612f205715fcda3b62a1d009b4329f$1@www.eclipse.org"
type="cite">Ed Merks wrote:
<br>
<br>
<blockquote type="cite">XSDPrototypicalSchema.cloneComponent has an
example for cloning something in to the same DOM document.
<br>
</blockquote>
<br>
Ok, but what if I need to put the complex type into another DOM
document? Specifically I don't understand why - using the mentioned
cloneComponent() function - I'm getting a WRONG_DOCUMENT_ERR exception
even though there is element.cloneNode(true) called in that function.
<br>
<br>
What else needs to be taken care of?
<br>
</blockquote>
I was obtusely referring to this method with is the cross document
equivalent of cloning a node:<br>
<blockquote><a
href=" http://java.sun.com/javase/6/docs/api/org/w3c/dom/Document.h tml#importNode%28org.w3c.dom.Node,%20boolean%29"> http://java.sun.com/javase/6/docs/api/org/w3c/dom/Document.h tml#importNode(org.w3c.dom.Node,%20boolean)</a><br>
</blockquote>
<blockquote
cite="mid:25612f205715fcda3b62a1d009b4329f$1@www.eclipse.org"
type="cite"><br>
<blockquote type="cite">Bummer.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] Multiple Roots
Next Topic:Setting EEnum using reflective API
Goto Forum:
  


Current Time: Fri Apr 26 07:32:22 GMT 2024

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

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

Back to the top