Copy a new local element into another schema [message #70054] |
Thu, 19 October 2006 01:02  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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 #598880 is a reply to message #70054] |
Thu, 19 October 2006 10:31  |
Eclipse User |
|
|
|
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 #598900 is a reply to message #70094] |
Thu, 19 October 2006 17:30  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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 #598924 is a reply to message #70193] |
Thu, 19 October 2006 20:33  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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 #598977 is a reply to message #70290] |
Fri, 20 October 2006 00:32  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.05148 seconds