Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » Copy a new local element into another schema
Copy a new local element into another schema [message #70054] Thu, 19 October 2006 01:02 Go to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
I have two versions of an schema (newSchema and oldSchema) that are almost
the same, but some local elements in "newSchema" may need to imported into
"oldSchema". So I will compare these two schemas and then import those new
local elements from new schema into the old one.

for example:

oldSchema: A --- B
|- C
|- D

newSchema: A --- B
|- C
|- D
|- E


For new global elements, I guess it is easy to add them into oldSchema.

But for new local elements (like E in the above example), It is hard to
add them into the corresponding positions in oldSchema (as the child node
of A).

How Can I record the container particle of newSchema and then locate the
corresponding particle in the oldSchema?

Before I tried Xerces xsd, I can use XPath to point to any position of the
DOM tree. Maybe I can do the same thing here? I can get the XPath of each
elements easily..

Thanks a lot for any instructions!

-Mavis
Re: Copy a new local element into another schema [message #70094 is a reply to message #70054] Thu, 19 October 2006 10:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Mavis,

I would expect that while comparing you'd establish map for things match
and would locate correspondence via such a map. But if you already have
a way to use XPath, then you can apply that to XSDSchema.getElement()
and use XSDSchema.getCorrespondingComponent to locate the component
corresponding to the node you've located via XPath evaluation.


exquisitus wrote:
> I have two versions of an schema (newSchema and oldSchema) that are
> almost the same, but some local elements in "newSchema" may need to
> imported into "oldSchema". So I will compare these two schemas and
> then import those new local elements from new schema into the old one.
>
> for example:
>
> oldSchema: A --- B
> |- C
> |- D
>
> newSchema: A --- B
> |- C
> |- D
> |- E
>
> For new global elements, I guess it is easy to add them into oldSchema.
> But for new local elements (like E in the above example), It is hard
> to add them into the corresponding positions in oldSchema (as the
> child node of A).
>
> How Can I record the container particle of newSchema and then locate
> the corresponding particle in the oldSchema?
> Before I tried Xerces xsd, I can use XPath to point to any position of
> the DOM tree. Maybe I can do the same thing here? I can get the XPath
> of each elements easily..
>
> Thanks a lot for any instructions!
>
> -Mavis
>
Re: Copy a new local element into another schema [message #70153 is a reply to message #70094] Thu, 19 October 2006 17:30 Go to previous messageGo to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Thanks a bunch!

First the problem is in the currentSchema this new local element is not
existed, so I need to locate the corresponding "particle" to set the
element as content, or actually I need to locate the "compositor" or even
high level "particle"? I am confused here..

And what is the node of the "particle"? If the XPath of an element is sth
like:
xsd:schema/xsd:element[@name='configuration']/xsd:complexTyp e/xsd:sequence/xsd:element[@name='system']/xsd:complexType[@ name
='juniper-system']/xsd:sequence/xsd:element[@name='autoinsta llation']/xsd:complexType/xsd:sequence/xsd:element[@name='in terfaces']/xsd:complexType/xsd:sequence/xsd:element[@name='i nterface']/xsd:complexType/xsd:sequence/xsd:element[@name='i paddress-2']

What should be the XPath of "Particle"?....

Thanks!!

-Mavis
Re: Copy a new local element into another schema [message #70193 is a reply to message #70153] Thu, 19 October 2006 18:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Mavis,

Particle and element declaration are kind of odd in that they correspond
to the same physical DOM node. Given the element declaration, you can
use getXSDContainer to get the containing particle or given the
particle, you can use getContent to get the contained element, so either
way, you should be able to find what you need. If the thing is not
present at all yet, you need to create both the particle and the element
declaration...


exquisitus wrote:
> Thanks a bunch!
>
> First the problem is in the currentSchema this new local element is
> not existed, so I need to locate the corresponding "particle" to set
> the element as content, or actually I need to locate the "compositor"
> or even high level "particle"? I am confused here..
>
> And what is the node of the "particle"? If the XPath of an element is
> sth like:
> xsd:schema/xsd:element[@name='configuration']/xsd:complexTyp e/xsd:sequence/xsd:element[@name='system']/xsd:complexType[@ name
> ='juniper-system']/xsd:sequence/xsd:element[@name='autoinsta llation']/xsd:complexType/xsd:sequence/xsd:element[@name='in terfaces']/xsd:complexType/xsd:sequence/xsd:element[@name='i nterface']/xsd:complexType/xsd:sequence/xsd:element[@name='i paddress-2']
>
>
> What should be the XPath of "Particle"?....
>
> Thanks!!
>
> -Mavis
>
Re: Copy a new local element into another schema [message #70211 is a reply to message #70193] Thu, 19 October 2006 20:33 Go to previous messageGo to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Thanks for your prompt reply! :)

The oldSchema does not have the new local element from newSchema, and it
does not have the new container particle either. So actually what we need
to locate is the corresponding "Container" of the new Particle, and then
to create particle and also create element Decl to be the content of this
particle?

What is the container of the "particle"? compositor (like xsd:sequence)or
the particle of a model group?

-Mavis
Re: Copy a new local element into another schema [message #70290 is a reply to message #70211] Thu, 19 October 2006 21:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Mavis,

The container of the particle will the model group. You can always use
XSDConcreteComponent.getXSDContainer to walk up the tree all the way to
the root XSDSchema.


exquisitus wrote:
> Thanks for your prompt reply! :)
>
> The oldSchema does not have the new local element from newSchema, and
> it does not have the new container particle either. So actually what
> we need to locate is the corresponding "Container" of the new
> Particle, and then to create particle and also create element Decl to
> be the content of this particle?
> What is the container of the "particle"? compositor (like
> xsd:sequence)or the particle of a model group?
> -Mavis
Re: Copy a new local element into another schema [message #70346 is a reply to message #70290] Fri, 20 October 2006 00:32 Go to previous messageGo to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
In order to clone an element from one schema(newSchema) and import it into
the other schema(oldSchema), Can I do something like this:

......
Node newElemParentNode =
((XSDModelGroup)newElem.getXSDParticleContainer().getContain er()).getElement();

//get the corresponding node in currentSchema
XSDModelGroup currentModelGroup =
(XSDModelGroup)currentXSDSchema.getCorrespondingComponent(ne wElemParentNode);

XSDElementDeclaration clonedCurrentElem =
(XSDElementDeclaration)newElem.cloneConcreteComponent(true, false);

XSDParticle clonedCurrentParticle =
(XSDParticle)newElem.getXSDParticleContainer().cloneConcrete Component(true,
false);

clonedCurrentParticle.setContent(clonedCurrentElem);

currentModelGroup.getContents().add(clonedCurrentParticle);
......
..
..
It will get "java.lang.ClassCastException" for the second line code...

XSDModelGroup currentModelGroup =
(XSDModelGroup)currentXSDSchema.getCorrespondingComponent(ne wElemParentNode);

You further instructions will be highly appreciated!

-Mavis
Re: Copy a new local element into another schema [message #70365 is a reply to message #70346] Fri, 20 October 2006 05:50 Go to previous messageGo to next message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Sorry. I guess my previous reply should be wrong.
..

I guess I need to locate the container node in the same schema, and then
add the new cloned element to be the content of the container node.

For example:

......

Node currentRootNode = currentXSDSchema.getElement();

//get the corresponding "XSDModelGroup" node in the currentSchema based on
the XPath
containerXql =
" /xsd:schema/xsd:element[@name='configuration']/xsd:complexTy pe/xsd:sequence/xsd:element[@name='system']/xsd:complexType[ @name
='ok-system']/xsd:sequence";

Node currentElemContainerNode = XPathAPI.selectSingleNode(currentRootNode,
containerXql);

XSDModelGroup currentModelGroup =
(XSDModelGroup)currentXSDSchema.getCorrespondingComponent(cu rrentElemContainerNode);

XSDElementDeclaration clonedCurrentElem =
(XSDElementDeclaration)newElem.getXSDElementDeclaration().cl oneConcreteComponent(true,
false);

XSDParticle clonedCurrentParticle =
(XSDParticle)newElem.getXSDParticleContainer().cloneConcrete Component(true,
false);

clonedCurrentParticle.setContent(clonedCurrentElem);
currentModelGroup.getContents().add(clonedCurrentParticle);
......

But I cannot get the node through Xpath? :-( I feel so sorry to bother
you...

Thank you for any hints!

-Mavis
Re: Copy a new local element into another schema [message #70385 is a reply to message #70365] Fri, 20 October 2006 10:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Mavis,

Comments below.

exquisitus wrote:
> Sorry. I guess my previous reply should be wrong.
> .
>
> I guess I need to locate the container node in the same schema, and
> then add the new cloned element to be the content of the container node.
>
> For example:
>
> .....
>
> Node currentRootNode = currentXSDSchema.getElement();
>
> //get the corresponding "XSDModelGroup" node in the currentSchema
> based on the XPath
> containerXql =
> " /xsd:schema/xsd:element[@name='configuration']/xsd:complexTy pe/xsd:sequence/xsd:element[@name='system']/xsd:complexType[ @name
> ='ok-system']/xsd:sequence";
>
> Node currentElemContainerNode =
> XPathAPI.selectSingleNode(currentRootNode, containerXql);
>
> XSDModelGroup currentModelGroup =
> (XSDModelGroup)currentXSDSchema.getCorrespondingComponent(cu rrentElemContainerNode);
>
>
> XSDElementDeclaration clonedCurrentElem =
> (XSDElementDeclaration)newElem.getXSDElementDeclaration().cl oneConcreteComponent(true,
> false);
>
> XSDParticle clonedCurrentParticle =
> (XSDParticle)newElem.getXSDParticleContainer().cloneConcrete Component(true,
> false);
Why make a deep copy of both the child and the parent and then set the
cloned child to the already deeply cloned parent?
>
> clonedCurrentParticle.setContent(clonedCurrentElem);
> currentModelGroup.getContents().add(clonedCurrentParticle);
> .....
>
> But I cannot get the node through Xpath? :-( I feel so sorry to bother
> you...
The Xpath thing was your idea. I really don't know where these XPaths
are coming from or why they help implement your application. I'd
imagine that comparing the tree structure of the XSD model directly
would have been easier...
>
> Thank you for any hints!
>
> -Mavis
>
Re: Copy a new local element into another schema [message #70495 is a reply to message #70385] Fri, 20 October 2006 22:14 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
I am really appreciated for all your instructions!
Eventually it worked out.

-Mavis
Re: Copy a new local element into another schema [message #598880 is a reply to message #70054] Thu, 19 October 2006 10:31 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Mavis,

I would expect that while comparing you'd establish map for things match
and would locate correspondence via such a map. But if you already have
a way to use XPath, then you can apply that to XSDSchema.getElement()
and use XSDSchema.getCorrespondingComponent to locate the component
corresponding to the node you've located via XPath evaluation.


exquisitus wrote:
> I have two versions of an schema (newSchema and oldSchema) that are
> almost the same, but some local elements in "newSchema" may need to
> imported into "oldSchema". So I will compare these two schemas and
> then import those new local elements from new schema into the old one.
>
> for example:
>
> oldSchema: A --- B
> |- C
> |- D
>
> newSchema: A --- B
> |- C
> |- D
> |- E
>
> For new global elements, I guess it is easy to add them into oldSchema.
> But for new local elements (like E in the above example), It is hard
> to add them into the corresponding positions in oldSchema (as the
> child node of A).
>
> How Can I record the container particle of newSchema and then locate
> the corresponding particle in the oldSchema?
> Before I tried Xerces xsd, I can use XPath to point to any position of
> the DOM tree. Maybe I can do the same thing here? I can get the XPath
> of each elements easily..
>
> Thanks a lot for any instructions!
>
> -Mavis
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Copy a new local element into another schema [message #598900 is a reply to message #70094] Thu, 19 October 2006 17:30 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Thanks a bunch!

First the problem is in the currentSchema this new local element is not
existed, so I need to locate the corresponding "particle" to set the
element as content, or actually I need to locate the "compositor" or even
high level "particle"? I am confused here..

And what is the node of the "particle"? If the XPath of an element is sth
like:
xsd:schema/xsd:element[@name='configuration']/xsd:complexTyp e/xsd:sequence/xsd:element[@name='system']/xsd:complexType[@ name
='juniper-system']/xsd:sequence/xsd:element[@name='autoinsta llation']/xsd:complexType/xsd:sequence/xsd:element[@name='in terfaces']/xsd:complexType/xsd:sequence/xsd:element[@name='i nterface']/xsd:complexType/xsd:sequence/xsd:element[@name='i paddress-2']

What should be the XPath of "Particle"?....

Thanks!!

-Mavis
Re: Copy a new local element into another schema [message #598919 is a reply to message #70153] Thu, 19 October 2006 18:22 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Mavis,

Particle and element declaration are kind of odd in that they correspond
to the same physical DOM node. Given the element declaration, you can
use getXSDContainer to get the containing particle or given the
particle, you can use getContent to get the contained element, so either
way, you should be able to find what you need. If the thing is not
present at all yet, you need to create both the particle and the element
declaration...


exquisitus wrote:
> Thanks a bunch!
>
> First the problem is in the currentSchema this new local element is
> not existed, so I need to locate the corresponding "particle" to set
> the element as content, or actually I need to locate the "compositor"
> or even high level "particle"? I am confused here..
>
> And what is the node of the "particle"? If the XPath of an element is
> sth like:
> xsd:schema/xsd:element[@name='configuration']/xsd:complexTyp e/xsd:sequence/xsd:element[@name='system']/xsd:complexType[@ name
> ='juniper-system']/xsd:sequence/xsd:element[@name='autoinsta llation']/xsd:complexType/xsd:sequence/xsd:element[@name='in terfaces']/xsd:complexType/xsd:sequence/xsd:element[@name='i nterface']/xsd:complexType/xsd:sequence/xsd:element[@name='i paddress-2']
>
>
> What should be the XPath of "Particle"?....
>
> Thanks!!
>
> -Mavis
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Copy a new local element into another schema [message #598924 is a reply to message #70193] Thu, 19 October 2006 20:33 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Thanks for your prompt reply! :)

The oldSchema does not have the new local element from newSchema, and it
does not have the new container particle either. So actually what we need
to locate is the corresponding "Container" of the new Particle, and then
to create particle and also create element Decl to be the content of this
particle?

What is the container of the "particle"? compositor (like xsd:sequence)or
the particle of a model group?

-Mavis
Re: Copy a new local element into another schema [message #598950 is a reply to message #70211] Thu, 19 October 2006 21:02 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Mavis,

The container of the particle will the model group. You can always use
XSDConcreteComponent.getXSDContainer to walk up the tree all the way to
the root XSDSchema.


exquisitus wrote:
> Thanks for your prompt reply! :)
>
> The oldSchema does not have the new local element from newSchema, and
> it does not have the new container particle either. So actually what
> we need to locate is the corresponding "Container" of the new
> Particle, and then to create particle and also create element Decl to
> be the content of this particle?
> What is the container of the "particle"? compositor (like
> xsd:sequence)or the particle of a model group?
> -Mavis


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Copy a new local element into another schema [message #598977 is a reply to message #70290] Fri, 20 October 2006 00:32 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
In order to clone an element from one schema(newSchema) and import it into
the other schema(oldSchema), Can I do something like this:

......
Node newElemParentNode =
((XSDModelGroup)newElem.getXSDParticleContainer().getContain er()).getElement();

//get the corresponding node in currentSchema
XSDModelGroup currentModelGroup =
(XSDModelGroup)currentXSDSchema.getCorrespondingComponent(ne wElemParentNode);

XSDElementDeclaration clonedCurrentElem =
(XSDElementDeclaration)newElem.cloneConcreteComponent(true, false);

XSDParticle clonedCurrentParticle =
(XSDParticle)newElem.getXSDParticleContainer().cloneConcrete Component(true,
false);

clonedCurrentParticle.setContent(clonedCurrentElem);

currentModelGroup.getContents().add(clonedCurrentParticle);
......
..
..
It will get "java.lang.ClassCastException" for the second line code...

XSDModelGroup currentModelGroup =
(XSDModelGroup)currentXSDSchema.getCorrespondingComponent(ne wElemParentNode);

You further instructions will be highly appreciated!

-Mavis
Re: Copy a new local element into another schema [message #598979 is a reply to message #70346] Fri, 20 October 2006 05:50 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
Sorry. I guess my previous reply should be wrong.
..

I guess I need to locate the container node in the same schema, and then
add the new cloned element to be the content of the container node.

For example:

......

Node currentRootNode = currentXSDSchema.getElement();

//get the corresponding "XSDModelGroup" node in the currentSchema based on
the XPath
containerXql =
" /xsd:schema/xsd:element[@name='configuration']/xsd:complexTy pe/xsd:sequence/xsd:element[@name='system']/xsd:complexType[ @name
='ok-system']/xsd:sequence";

Node currentElemContainerNode = XPathAPI.selectSingleNode(currentRootNode,
containerXql);

XSDModelGroup currentModelGroup =
(XSDModelGroup)currentXSDSchema.getCorrespondingComponent(cu rrentElemContainerNode);

XSDElementDeclaration clonedCurrentElem =
(XSDElementDeclaration)newElem.getXSDElementDeclaration().cl oneConcreteComponent(true,
false);

XSDParticle clonedCurrentParticle =
(XSDParticle)newElem.getXSDParticleContainer().cloneConcrete Component(true,
false);

clonedCurrentParticle.setContent(clonedCurrentElem);
currentModelGroup.getContents().add(clonedCurrentParticle);
......

But I cannot get the node through Xpath? :-( I feel so sorry to bother
you...

Thank you for any hints!

-Mavis
Re: Copy a new local element into another schema [message #598990 is a reply to message #70365] Fri, 20 October 2006 10:16 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Mavis,

Comments below.

exquisitus wrote:
> Sorry. I guess my previous reply should be wrong.
> .
>
> I guess I need to locate the container node in the same schema, and
> then add the new cloned element to be the content of the container node.
>
> For example:
>
> .....
>
> Node currentRootNode = currentXSDSchema.getElement();
>
> //get the corresponding "XSDModelGroup" node in the currentSchema
> based on the XPath
> containerXql =
> " /xsd:schema/xsd:element[@name='configuration']/xsd:complexTy pe/xsd:sequence/xsd:element[@name='system']/xsd:complexType[ @name
> ='ok-system']/xsd:sequence";
>
> Node currentElemContainerNode =
> XPathAPI.selectSingleNode(currentRootNode, containerXql);
>
> XSDModelGroup currentModelGroup =
> (XSDModelGroup)currentXSDSchema.getCorrespondingComponent(cu rrentElemContainerNode);
>
>
> XSDElementDeclaration clonedCurrentElem =
> (XSDElementDeclaration)newElem.getXSDElementDeclaration().cl oneConcreteComponent(true,
> false);
>
> XSDParticle clonedCurrentParticle =
> (XSDParticle)newElem.getXSDParticleContainer().cloneConcrete Component(true,
> false);
Why make a deep copy of both the child and the parent and then set the
cloned child to the already deeply cloned parent?
>
> clonedCurrentParticle.setContent(clonedCurrentElem);
> currentModelGroup.getContents().add(clonedCurrentParticle);
> .....
>
> But I cannot get the node through Xpath? :-( I feel so sorry to bother
> you...
The Xpath thing was your idea. I really don't know where these XPaths
are coming from or why they help implement your application. I'd
imagine that comparing the tree structure of the XSD model directly
would have been easier...
>
> Thank you for any hints!
>
> -Mavis
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Copy a new local element into another schema [message #599043 is a reply to message #70385] Fri, 20 October 2006 22:14 Go to previous message
donghua deng is currently offline donghua dengFriend
Messages: 34
Registered: July 2009
Member
I am really appreciated for all your instructions!
Eventually it worked out.

-Mavis
Previous Topic:test
Next Topic:Facets - dynamically updating
Goto Forum:
  


Current Time: Thu Apr 18 17:22:06 GMT 2024

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

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

Back to the top