Add Parent Element Functionality

Are you missing a feature? Request its implementation here.
idak
Posts: 16
Joined: Mon Mar 18, 2013 6:29 pm

Add Parent Element Functionality

Post by idak »

Hi,

I'm trying to implement ‘add parents’ functionality:
What java class I can used to search a list of parent elements (equivalent to xpath expression: //xs:element[descendant::xs:element/@ref='T0X']

example :
<T0X><p></T0X> after Add Parent action <T0Y> => <T0Y> <T0X><p></T0X> <T0Y>

Regards
Idak
Radu
Posts: 9472
Joined: Fri Jul 09, 2004 5:18 pm

Re: Add Parent Element Functionality

Post by Radu »

Hi Idak,

I do not quite understand what you want to do. Maybe you could elaborate.

For editing in the Author mode you have some API methods evailable like:

Code: Select all

ro.sync.ecss.extensions.api.AuthorDocumentController.evaluateXPath
and:

Code: Select all

ro.sync.ecss.extensions.api.AuthorDocumentController.findNodesByXPath
When editing in the Text page there is an API method like:

Code: Select all

ro.sync.exml.workspace.api.editor.page.text.xml.WSXMLTextEditorPage.findElementsByXPath(String)
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
idak
Posts: 16
Joined: Mon Mar 18, 2013 6:29 pm

Re: Add Parent Element Functionality

Post by idak »

Hi,
To search the list ChildrenElements I use this java code :
WhatElementsCanGoHereContext elementsCanGoHereContext;
elementsCanGoHereContext = authorSchemaManager.createWhatElementsCanGoHereContext(selectedNode.getStartOffset());
List<CIElement> elements = authorSchemaManager.getChildrenElements(elementsCanGoHereContext);

I want to get the list of parent elements (in xsd schemas) something like getParentElements ...

Regards,
Idak
Radu
Posts: 9472
Joined: Fri Jul 09, 2004 5:18 pm

Re: Add Parent Element Functionality

Post by Radu »

Hi Idak,

One remark, the code you are currently using:

Code: Select all

authorSchemaManager.createWhatElementsCanGoHereContext(selectedNode.getStartOffset());
will not return the possible children in the current selected node but the possible children from it's parent (because selectedNode.getStartOffset() represents a position which is in front of the selected node and not inside it).

I think that you actually want to know the answer to this question:

In what other parents could this current element be inserted?

We do not have an API for this.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
idak
Posts: 16
Joined: Mon Mar 18, 2013 6:29 pm

Re: Add Parent Element Functionality

Post by idak »

OK Thanks,
Is it possible to load the xsd schema file and search the parent elements with xpath ? (//xs:element[descendant::xs:element/@ref='T0X'])

Regards,
Idak
Radu
Posts: 9472
Joined: Fri Jul 09, 2004 5:18 pm

Re: Add Parent Element Functionality

Post by Radu »

Hi Idak,

You have API to create an XSLT transformer which could match the XPath in an XSLT stylesheet template:

Code: Select all

ro.sync.exml.workspace.api.util.XMLUtilAccess.createXSLTTransformer(Source, URL[], int)
But the XPath expression you want to use: //xs:element[descendant::xs:element/@ref='T0X'] might work in some cases but fail most in others. What if an element references a complex type which is defined in another place and that complex type references a child element? So it is not a general solution.

You could also probably uses the Xerces libraries already available in Oxygen's classpath to create an org.apache.xerces.xs.XSModel implementation which is a compiled version of a schema, with all references resolved.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply