Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » Copy Schema item
Copy Schema item [message #64888] Fri, 04 November 2005 20:58 Go to next message
David Carver is currently offline David CarverFriend
Messages: 174
Registered: July 2009
Senior Member
I'm running into an issue with the XSD API from eclipse. I'm trying to
copy an XSD artifact from one XSDSchema to another.

Basically, I want to take elements, complexTypes, and simpleTypes and copy
them exactly into another schema. If I go through programmicly and
create each type, they appear when I serialize them. However if I do
something like the following:

XSDElementDeclaration element =
XSDFactory.eINSTANCE.createXSDElementDeclaration();
element.setElement(xsdItem.getElement());
newMergedSchema.getContents().add(element);

They appear in the newMergedSchemas.getContents() when I examine it with
the debugger, but when I serialize the newMergeSchema, the items do not
show up in the serialization. I've tried doing an
element.updateElement(), but that didn't have any affect. I've also
tried a clone, but it doesn't do anything different.

Any ideas?

Dave
Re: Copy Schema item [message #64910 is a reply to message #64888] Fri, 04 November 2005 21:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Dave,

I'm not sure of the context of the lines below, but you need to remember
that each XSDSchema will wrap a different DOM Document and you can't add
an element from one document to another document. Calling setElement
on a detached XSDElementDeclaration isn't going to be able to create a
nice tree either; the element needs to be attached for that. You've
tried xsdItem.cloneConcreteComponent(true, false) to produce a copy you
can insert elsewhere? This won't copy the DOM fragment over verbatim
and will lose the contents of annotations, which are representable only
in the DOM. You could use
mergedSchema.getDocument().cloneNode(xsdItem.getElement()) to copy the
fragment itself and then insert it into the mergedSchema.getElement.


Dave Carver wrote:

> I'm running into an issue with the XSD API from eclipse. I'm trying
> to copy an XSD artifact from one XSDSchema to another.
>
> Basically, I want to take elements, complexTypes, and simpleTypes and
> copy them exactly into another schema. If I go through programmicly
> and create each type, they appear when I serialize them. However if I
> do something like the following:
>
> XSDElementDeclaration element =
> XSDFactory.eINSTANCE.createXSDElementDeclaration();
> element.setElement(xsdItem.getElement());
> newMergedSchema.getContents().add(element);
>
> They appear in the newMergedSchemas.getContents() when I examine it
> with the debugger, but when I serialize the newMergeSchema, the items
> do not show up in the serialization. I've tried doing an
> element.updateElement(), but that didn't have any affect. I've also
> tried a clone, but it doesn't do anything different.
>
> Any ideas?
>
> Dave
Re: Copy Schema item [message #64929 is a reply to message #64910] Fri, 04 November 2005 22:23 Go to previous messageGo to next message
David Carver is currently offline David CarverFriend
Messages: 174
Registered: July 2009
Senior Member
Thanks Ed, it's gotten me a bit closer, but I'm still not quite there.
Basically what the method does is takes in two XSDSchema objects, and
tries to copy the Elements, ComplexTypes, and SimpleTypes from the first
schema to the second schemas.

Here is the method that I've created where I have the code for copying
from one schema to another:

public void copyAllContents(XSDSchema xsdSchema, XSDSchema
newMergedSchema) {
Iterator xsdSchemaIterator = xsdSchema.getContents().iterator();

while (xsdSchemaIterator.hasNext()) {
XSDConcreteComponent xsdItem = (XSDConcreteComponent)xsdSchemaIterator
.next();
if (isNotImportInclude(xsdItem)) {
if (xsdItem instanceof XSDElementDeclarationImpl) {
XSDElementDeclaration element = XSDFactory
.eINSTANCE.createXSDElementDeclaration();
Element dup = xsdItem.getElement();
element.setElement((Element)dup.cloneNode(true));
newMergedSchema.getContents().add(element);
}
if (xsdItem instanceof XSDComplexTypeDefinitionImpl) {
XSDComplexTypeDefinition element = XSDFactory
.eINSTANCE.createXSDComplexTypeDefinition();
Element dup = xsdItem.getElement();
dup.cloneNode(true);
element.setElement((Element)dup.cloneNode(true));
newMergedSchema.getContents().add(element);
}
if (xsdItem instanceof XSDSimpleTypeDefinitionImpl) {
XSDSimpleTypeDefinition element = XSDFactory
.eINSTANCE.createXSDSimpleTypeDefinition();
Element dup = xsdItem.getElement();
dup.cloneNode(true);
element.setElement((Element)dup.cloneNode(true));
newMergedSchema.getContents().add(element);
}
}
}
}

This code now is producing the following (I wasn't getting anything
before):

<xsd:element/>
<xsd:complexType/>
<xsd:complexType/>
<xsd:complexType/>
<xsd:element/>
<xsd:element/>
<xsd:element/>
<xsd:complexType/>
<xsd:complexType/>
<xsd:complexType/>
<xsd:complexType/>
<xsd:complexType/>

None of the attributes information or sub nodes are showing up. I'm sure
I'm probably missing something simple.

Dave
Re: Copy Schema item [message #64945 is a reply to message #64929] Fri, 04 November 2005 22:52 Go to previous message
David Carver is currently offline David CarverFriend
Messages: 174
Registered: July 2009
Senior Member
Actually, tried the cloneConcreteComponent method again and this time it
cloned the item exactly (except for the annotations which you noted it
wouldn't).

I'm sure I can find some sample code on getting the annotations over as
well.

Thanks for the help.
Re: Copy Schema item [message #597114 is a reply to message #64888] Fri, 04 November 2005 21:37 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Dave,

I'm not sure of the context of the lines below, but you need to remember
that each XSDSchema will wrap a different DOM Document and you can't add
an element from one document to another document. Calling setElement
on a detached XSDElementDeclaration isn't going to be able to create a
nice tree either; the element needs to be attached for that. You've
tried xsdItem.cloneConcreteComponent(true, false) to produce a copy you
can insert elsewhere? This won't copy the DOM fragment over verbatim
and will lose the contents of annotations, which are representable only
in the DOM. You could use
mergedSchema.getDocument().cloneNode(xsdItem.getElement()) to copy the
fragment itself and then insert it into the mergedSchema.getElement.


Dave Carver wrote:

> I'm running into an issue with the XSD API from eclipse. I'm trying
> to copy an XSD artifact from one XSDSchema to another.
>
> Basically, I want to take elements, complexTypes, and simpleTypes and
> copy them exactly into another schema. If I go through programmicly
> and create each type, they appear when I serialize them. However if I
> do something like the following:
>
> XSDElementDeclaration element =
> XSDFactory.eINSTANCE.createXSDElementDeclaration();
> element.setElement(xsdItem.getElement());
> newMergedSchema.getContents().add(element);
>
> They appear in the newMergedSchemas.getContents() when I examine it
> with the debugger, but when I serialize the newMergeSchema, the items
> do not show up in the serialization. I've tried doing an
> element.updateElement(), but that didn't have any affect. I've also
> tried a clone, but it doesn't do anything different.
>
> Any ideas?
>
> Dave


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Copy Schema item [message #597120 is a reply to message #64910] Fri, 04 November 2005 22:23 Go to previous message
David Carver is currently offline David CarverFriend
Messages: 174
Registered: July 2009
Senior Member
Thanks Ed, it's gotten me a bit closer, but I'm still not quite there.
Basically what the method does is takes in two XSDSchema objects, and
tries to copy the Elements, ComplexTypes, and SimpleTypes from the first
schema to the second schemas.

Here is the method that I've created where I have the code for copying
from one schema to another:

public void copyAllContents(XSDSchema xsdSchema, XSDSchema
newMergedSchema) {
Iterator xsdSchemaIterator = xsdSchema.getContents().iterator();

while (xsdSchemaIterator.hasNext()) {
XSDConcreteComponent xsdItem = (XSDConcreteComponent)xsdSchemaIterator
.next();
if (isNotImportInclude(xsdItem)) {
if (xsdItem instanceof XSDElementDeclarationImpl) {
XSDElementDeclaration element = XSDFactory
.eINSTANCE.createXSDElementDeclaration();
Element dup = xsdItem.getElement();
element.setElement((Element)dup.cloneNode(true));
newMergedSchema.getContents().add(element);
}
if (xsdItem instanceof XSDComplexTypeDefinitionImpl) {
XSDComplexTypeDefinition element = XSDFactory
.eINSTANCE.createXSDComplexTypeDefinition();
Element dup = xsdItem.getElement();
dup.cloneNode(true);
element.setElement((Element)dup.cloneNode(true));
newMergedSchema.getContents().add(element);
}
if (xsdItem instanceof XSDSimpleTypeDefinitionImpl) {
XSDSimpleTypeDefinition element = XSDFactory
.eINSTANCE.createXSDSimpleTypeDefinition();
Element dup = xsdItem.getElement();
dup.cloneNode(true);
element.setElement((Element)dup.cloneNode(true));
newMergedSchema.getContents().add(element);
}
}
}
}

This code now is producing the following (I wasn't getting anything
before):

<xsd:element/>
<xsd:complexType/>
<xsd:complexType/>
<xsd:complexType/>
<xsd:element/>
<xsd:element/>
<xsd:element/>
<xsd:complexType/>
<xsd:complexType/>
<xsd:complexType/>
<xsd:complexType/>
<xsd:complexType/>

None of the attributes information or sub nodes are showing up. I'm sure
I'm probably missing something simple.

Dave
Re: Copy Schema item [message #597125 is a reply to message #64929] Fri, 04 November 2005 22:52 Go to previous message
David Carver is currently offline David CarverFriend
Messages: 174
Registered: July 2009
Senior Member
Actually, tried the cloneConcreteComponent method again and this time it
cloned the item exactly (except for the annotations which you noted it
wouldn't).

I'm sure I can find some sample code on getting the annotations over as
well.

Thanks for the help.
Previous Topic:Copy Schema item
Next Topic:Copying/Cloning Annotations
Goto Forum:
  


Current Time: Tue Apr 23 14:51:14 GMT 2024

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

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

Back to the top