Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » Schema Merging
Schema Merging [message #72167] Thu, 26 April 2007 14:47 Go to next message
Klaus Schaefers is currently offline Klaus Schaefers
Messages: 24
Registered: July 2009
Junior Member
Hi,

I'm trying to generate a new Schema based on an old Schema that conatins
all included / imported schemas. E.g. a includes B & C then the new schema
D schould contain all types of A, B and C.

I have tried it like this:

XSDSchema newSchema = XSDSchemaBuildingTools.getBlankSchema(factory,...);

...

list complexTypes = getAllComplexTypesRecursivly.

for(ComplexType type: complexTypes)
{
newSchema.getContents().add(type).
}

When I try to sreialize the new Schema with Xerces i got the following
error:
org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a
different document than the one that created it.
at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknow n Source)
at org.apache.xerces.dom.ParentNode.insertBefore(Unknown Source)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.forceNiceInser tBefore(XSDConcreteComponentImpl.java:1590)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.niceInsertBefo re(XSDConcreteComponentImpl.java:1514)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.handleElementF orAdopt(XSDConcreteComponentImpl.java:1367)
at
org.eclipse.xsd.impl.XSDConcreteComponentImpl.updateElement( XSDConcreteComponentImpl.java:366)

Does anybody have a hint?

Kind regards,

klaus
Re: Schema Merging [message #72185 is a reply to message #72167] Thu, 26 April 2007 16:01 Go to previous messageGo to next message
Eclipse User
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------000406050004050800060305
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Klaus,

I don't understand how it got past *this *guard:

if (getElement() != null && (childElement == null ||
childElement.getParentNode() == null))
{
if (childElement != null && *childElement.getOwnerDocument() !=
getElement().getOwnerDocument()*)
{
xsdConcreteComponent.setElement(null);
childElement = null;
}

handleElementForAdopt(eReference, xsdConcreteComponent);
xsdConcreteComponent.updateElement();
}

I'd need to see the problem in action...

To preserve all your DOM content (e.g., documentation, appinfo and
non-schema namespace attributes), you'd likely be better off to clone
the DOM nodes themselves and add them directly to the new schema's DOM.
(And you'd probably be better off doing an addAll instead of adding one
at a time.) Using XSDConcreteComponent.cloneConcreteComponent(true,
false) and adding a clone might be a way to avoid whatever problem you
are seeing...


Klaus Schaefers wrote:
> Hi,
> I'm trying to generate a new Schema based on an old Schema that
> conatins all included / imported schemas. E.g. a includes B & C then
> the new schema D schould contain all types of A, B and C.
>
> I have tried it like this:
>
> XSDSchema newSchema = XSDSchemaBuildingTools.getBlankSchema(factory,...);
>
> ..
>
> list complexTypes = getAllComplexTypesRecursivly.
>
> for(ComplexType type: complexTypes)
> {
> newSchema.getContents().add(type).
> }
> When I try to sreialize the new Schema with Xerces i got the following
> error:
> org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a
> different document than the one that created it.
> at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknow n
> Source)
> at org.apache.xerces.dom.ParentNode.insertBefore(Unknown Source)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.forceNiceInser tBefore(XSDConcreteComponentImpl.java:1590)
>
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.niceInsertBefo re(XSDConcreteComponentImpl.java:1514)
>
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.handleElementF orAdopt(XSDConcreteComponentImpl.java:1367)
>
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.updateElement( XSDConcreteComponentImpl.java:366)
>
>
> Does anybody have a hint?
>
> Kind regards,
>
> klaus
>
>
>
>


--------------000406050004050800060305
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">
</head>
<body bgcolor="#ffffff" text="#000000">
Klaus,<br>
<br>
I don't understand how it got past <b>this </b>guard:<br>
<br>
Re: Schema Merging [message #72203 is a reply to message #72185] Fri, 27 April 2007 09:41 Go to previous messageGo to next message
Klaus Schaefers is currently offline Klaus Schaefers
Messages: 24
Registered: July 2009
Junior Member
Ed Merks wrote:

> Klaus,

> I don't understand how it got past *this *guard:

> if (getElement() != null && (childElement == null ||
> childElement.getParentNode() == null))
> {
> if (childElement != null && *childElement.getOwnerDocument() !=
> getElement().getOwnerDocument()*)
> {
> xsdConcreteComponent.setElement(null);
> childElement = null;
> }

> handleElementForAdopt(eReference, xsdConcreteComponent);
> xsdConcreteComponent.updateElement();
> }

> I'd need to see the problem in action...

> To preserve all your DOM content (e.g., documentation, appinfo and
> non-schema namespace attributes), you'd likely be better off to clone
> the DOM nodes themselves and add them directly to the new schema's DOM.
> (And you'd probably be better off doing an addAll instead of adding one
> at a time.) Using XSDConcreteComponent.cloneConcreteComponent(true,
> false) and adding a clone might be a way to avoid whatever problem you
> are seeing...


> Klaus Schaefers wrote:
>> Hi,
>> I'm trying to generate a new Schema based on an old Schema that
>> conatins all included / imported schemas. E.g. a includes B & C then
>> the new schema D schould contain all types of A, B and C.
>>
>> I have tried it like this:
>>
>> XSDSchema newSchema = XSDSchemaBuildingTools.getBlankSchema(factory,...);
>>
>> ..
>>
>> list complexTypes = getAllComplexTypesRecursivly.
>>
>> for(ComplexType type: complexTypes)
>> {
>> newSchema.getContents().add(type).
>> }
>> When I try to sreialize the new Schema with Xerces i got the following
>> error:
>> org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a
>> different document than the one that created it.
>> at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknow n
>> Source)
>> at org.apache.xerces.dom.ParentNode.insertBefore(Unknown Source)
>> at
>>
org.eclipse.xsd.impl.XSDConcreteComponentImpl.forceNiceInser tBefore(XSDConcreteComponentImpl.java:1590)
>>
>> at
>>
org.eclipse.xsd.impl.XSDConcreteComponentImpl.niceInsertBefo re(XSDConcreteComponentImpl.java:1514)
>>
>> at
>>
org.eclipse.xsd.impl.XSDConcreteComponentImpl.handleElementF orAdopt(XSDConcreteComponentImpl.java:1367)
>>
>> at
>>
org.eclipse.xsd.impl.XSDConcreteComponentImpl.updateElement( XSDConcreteComponentImpl.java:366)
>>
>>
>> Does anybody have a hint?
>>
>> Kind regards,
>>
>> klaus
>>
>>
>>
>>Thankx, it works. Do I have to take care of the namespaces of the elements
by my self, or does EMF that work for me?
Cheers,
Klaus
Re: Schema Merging [message #72221 is a reply to message #72203] Fri, 27 April 2007 10:29 Go to previous message
Eclipse User
Originally posted by: merks.ca.ibm.com

Klaus,

I was going to mention that it's tricky since references will be to
things in other namespaces and when copying them over, they will still
want to refer to those same namespace. So yes, if you want something to
refer to a different namespace, you have to do the visiting and the
transforming to make that happen. Probably an
XSDUtil.XSDNamedComponentCrossReferencer will help. You can apply it to
the final schema to find all the references to named components. I
think that for each named component that's a key in the map and that's
not resolved (for which getContainer() is null), you'd want to use
resolveXyz of the new namespace and the old local name to find where it
should resolve, and then use EcoreUtil.replace(setting,
oldNamedComponent, newNamedComponent) for the setting that's the value
in the map.


Klaus Schaefers wrote:
> Ed Merks wrote:
>
>> Klaus,
>
>> I don't understand how it got past *this *guard:
>
>> if (getElement() != null && (childElement == null ||
>> childElement.getParentNode() == null))
>> {
>> if (childElement != null && *childElement.getOwnerDocument()
>> != getElement().getOwnerDocument()*)
>> {
>> xsdConcreteComponent.setElement(null);
>> childElement = null;
>> }
>
>> handleElementForAdopt(eReference, xsdConcreteComponent);
>> xsdConcreteComponent.updateElement();
>> }
>
>> I'd need to see the problem in action...
>
>> To preserve all your DOM content (e.g., documentation, appinfo and
>> non-schema namespace attributes), you'd likely be better off to clone
>> the DOM nodes themselves and add them directly to the new schema's
>> DOM. (And you'd probably be better off doing an addAll instead of
>> adding one at a time.) Using
>> XSDConcreteComponent.cloneConcreteComponent(true, false) and adding a
>> clone might be a way to avoid whatever problem you are seeing...
>
>
>> Klaus Schaefers wrote:
>>> Hi,
>>> I'm trying to generate a new Schema based on an old Schema that
>>> conatins all included / imported schemas. E.g. a includes B & C then
>>> the new schema D schould contain all types of A, B and C.
>>>
>>> I have tried it like this:
>>>
>>> XSDSchema newSchema =
>>> XSDSchemaBuildingTools.getBlankSchema(factory,...);
>>>
>>> ..
>>>
>>> list complexTypes = getAllComplexTypesRecursivly.
>>>
>>> for(ComplexType type: complexTypes)
>>> {
>>> newSchema.getContents().add(type).
>>> }
>>> When I try to sreialize the new Schema with Xerces i got the
>>> following error:
>>> org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a
>>> different document than the one that created it.
>>> at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknow n
>>> Source)
>>> at org.apache.xerces.dom.ParentNode.insertBefore(Unknown Source)
>>> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.forceNiceInser tBefore(XSDConcreteComponentImpl.java:1590)
>
>>>
>>> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.niceInsertBefo re(XSDConcreteComponentImpl.java:1514)
>
>>>
>>> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.handleElementF orAdopt(XSDConcreteComponentImpl.java:1367)
>
>>>
>>> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.updateElement( XSDConcreteComponentImpl.java:366)
>
>>>
>>>
>>> Does anybody have a hint?
>>>
>>> Kind regards,
>>>
>>> klaus
>>>
>>>
>>>
>>> Thankx, it works. Do I have to take care of the namespaces of the
>>> elements
> by my self, or does EMF that work for me?
> Cheers,
> Klaus
>
Re: Schema Merging [message #602327 is a reply to message #72167] Thu, 26 April 2007 16:01 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26054
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000406050004050800060305
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Klaus,

I don't understand how it got past *this *guard:

if (getElement() != null && (childElement == null ||
childElement.getParentNode() == null))
{
if (childElement != null && *childElement.getOwnerDocument() !=
getElement().getOwnerDocument()*)
{
xsdConcreteComponent.setElement(null);
childElement = null;
}

handleElementForAdopt(eReference, xsdConcreteComponent);
xsdConcreteComponent.updateElement();
}

I'd need to see the problem in action...

To preserve all your DOM content (e.g., documentation, appinfo and
non-schema namespace attributes), you'd likely be better off to clone
the DOM nodes themselves and add them directly to the new schema's DOM.
(And you'd probably be better off doing an addAll instead of adding one
at a time.) Using XSDConcreteComponent.cloneConcreteComponent(true,
false) and adding a clone might be a way to avoid whatever problem you
are seeing...


Klaus Schaefers wrote:
> Hi,
> I'm trying to generate a new Schema based on an old Schema that
> conatins all included / imported schemas. E.g. a includes B & C then
> the new schema D schould contain all types of A, B and C.
>
> I have tried it like this:
>
> XSDSchema newSchema = XSDSchemaBuildingTools.getBlankSchema(factory,...);
>
> ..
>
> list complexTypes = getAllComplexTypesRecursivly.
>
> for(ComplexType type: complexTypes)
> {
> newSchema.getContents().add(type).
> }
> When I try to sreialize the new Schema with Xerces i got the following
> error:
> org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a
> different document than the one that created it.
> at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknow n
> Source)
> at org.apache.xerces.dom.ParentNode.insertBefore(Unknown Source)
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.forceNiceInser tBefore(XSDConcreteComponentImpl.java:1590)
>
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.niceInsertBefo re(XSDConcreteComponentImpl.java:1514)
>
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.handleElementF orAdopt(XSDConcreteComponentImpl.java:1367)
>
> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.updateElement( XSDConcreteComponentImpl.java:366)
>
>
> Does anybody have a hint?
>
> Kind regards,
>
> klaus
>
>
>
>


--------------000406050004050800060305
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">
</head>
<body bgcolor="#ffffff" text="#000000">
Klaus,<br>
<br>
I don't understand how it got past <b>this </b>guard:<br>
<br>
Re: Schema Merging [message #602332 is a reply to message #72185] Fri, 27 April 2007 09:41 Go to previous message
Klaus Schaefers is currently offline Klaus Schaefers
Messages: 24
Registered: July 2009
Junior Member
Ed Merks wrote:

> Klaus,

> I don't understand how it got past *this *guard:

> if (getElement() != null && (childElement == null ||
> childElement.getParentNode() == null))
> {
> if (childElement != null && *childElement.getOwnerDocument() !=
> getElement().getOwnerDocument()*)
> {
> xsdConcreteComponent.setElement(null);
> childElement = null;
> }

> handleElementForAdopt(eReference, xsdConcreteComponent);
> xsdConcreteComponent.updateElement();
> }

> I'd need to see the problem in action...

> To preserve all your DOM content (e.g., documentation, appinfo and
> non-schema namespace attributes), you'd likely be better off to clone
> the DOM nodes themselves and add them directly to the new schema's DOM.
> (And you'd probably be better off doing an addAll instead of adding one
> at a time.) Using XSDConcreteComponent.cloneConcreteComponent(true,
> false) and adding a clone might be a way to avoid whatever problem you
> are seeing...


> Klaus Schaefers wrote:
>> Hi,
>> I'm trying to generate a new Schema based on an old Schema that
>> conatins all included / imported schemas. E.g. a includes B & C then
>> the new schema D schould contain all types of A, B and C.
>>
>> I have tried it like this:
>>
>> XSDSchema newSchema = XSDSchemaBuildingTools.getBlankSchema(factory,...);
>>
>> ..
>>
>> list complexTypes = getAllComplexTypesRecursivly.
>>
>> for(ComplexType type: complexTypes)
>> {
>> newSchema.getContents().add(type).
>> }
>> When I try to sreialize the new Schema with Xerces i got the following
>> error:
>> org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a
>> different document than the one that created it.
>> at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknow n
>> Source)
>> at org.apache.xerces.dom.ParentNode.insertBefore(Unknown Source)
>> at
>>
org.eclipse.xsd.impl.XSDConcreteComponentImpl.forceNiceInser tBefore(XSDConcreteComponentImpl.java:1590)
>>
>> at
>>
org.eclipse.xsd.impl.XSDConcreteComponentImpl.niceInsertBefo re(XSDConcreteComponentImpl.java:1514)
>>
>> at
>>
org.eclipse.xsd.impl.XSDConcreteComponentImpl.handleElementF orAdopt(XSDConcreteComponentImpl.java:1367)
>>
>> at
>>
org.eclipse.xsd.impl.XSDConcreteComponentImpl.updateElement( XSDConcreteComponentImpl.java:366)
>>
>>
>> Does anybody have a hint?
>>
>> Kind regards,
>>
>> klaus
>>
>>
>>
>>Thankx, it works. Do I have to take care of the namespaces of the elements
by my self, or does EMF that work for me?
Cheers,
Klaus
Re: Schema Merging [message #602336 is a reply to message #72203] Fri, 27 April 2007 10:29 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26054
Registered: July 2009
Senior Member
Klaus,

I was going to mention that it's tricky since references will be to
things in other namespaces and when copying them over, they will still
want to refer to those same namespace. So yes, if you want something to
refer to a different namespace, you have to do the visiting and the
transforming to make that happen. Probably an
XSDUtil.XSDNamedComponentCrossReferencer will help. You can apply it to
the final schema to find all the references to named components. I
think that for each named component that's a key in the map and that's
not resolved (for which getContainer() is null), you'd want to use
resolveXyz of the new namespace and the old local name to find where it
should resolve, and then use EcoreUtil.replace(setting,
oldNamedComponent, newNamedComponent) for the setting that's the value
in the map.


Klaus Schaefers wrote:
> Ed Merks wrote:
>
>> Klaus,
>
>> I don't understand how it got past *this *guard:
>
>> if (getElement() != null && (childElement == null ||
>> childElement.getParentNode() == null))
>> {
>> if (childElement != null && *childElement.getOwnerDocument()
>> != getElement().getOwnerDocument()*)
>> {
>> xsdConcreteComponent.setElement(null);
>> childElement = null;
>> }
>
>> handleElementForAdopt(eReference, xsdConcreteComponent);
>> xsdConcreteComponent.updateElement();
>> }
>
>> I'd need to see the problem in action...
>
>> To preserve all your DOM content (e.g., documentation, appinfo and
>> non-schema namespace attributes), you'd likely be better off to clone
>> the DOM nodes themselves and add them directly to the new schema's
>> DOM. (And you'd probably be better off doing an addAll instead of
>> adding one at a time.) Using
>> XSDConcreteComponent.cloneConcreteComponent(true, false) and adding a
>> clone might be a way to avoid whatever problem you are seeing...
>
>
>> Klaus Schaefers wrote:
>>> Hi,
>>> I'm trying to generate a new Schema based on an old Schema that
>>> conatins all included / imported schemas. E.g. a includes B & C then
>>> the new schema D schould contain all types of A, B and C.
>>>
>>> I have tried it like this:
>>>
>>> XSDSchema newSchema =
>>> XSDSchemaBuildingTools.getBlankSchema(factory,...);
>>>
>>> ..
>>>
>>> list complexTypes = getAllComplexTypesRecursivly.
>>>
>>> for(ComplexType type: complexTypes)
>>> {
>>> newSchema.getContents().add(type).
>>> }
>>> When I try to sreialize the new Schema with Xerces i got the
>>> following error:
>>> org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a
>>> different document than the one that created it.
>>> at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknow n
>>> Source)
>>> at org.apache.xerces.dom.ParentNode.insertBefore(Unknown Source)
>>> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.forceNiceInser tBefore(XSDConcreteComponentImpl.java:1590)
>
>>>
>>> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.niceInsertBefo re(XSDConcreteComponentImpl.java:1514)
>
>>>
>>> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.handleElementF orAdopt(XSDConcreteComponentImpl.java:1367)
>
>>>
>>> at
> org.eclipse.xsd.impl.XSDConcreteComponentImpl.updateElement( XSDConcreteComponentImpl.java:366)
>
>>>
>>>
>>> Does anybody have a hint?
>>>
>>> Kind regards,
>>>
>>> klaus
>>>
>>>
>>>
>>> Thankx, it works. Do I have to take care of the namespaces of the
>>> elements
> by my self, or does EMF that work for me?
> Cheers,
> Klaus
>
Previous Topic:Schema Merging
Next Topic:complexType mapped to EDataType
Goto Forum:
  


Current Time: Sat Sep 20 14:03:34 GMT 2014

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

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