Four Js Development Tools Forum

Discussions by product => Genero BDL => Topic started by: ORGA-SOFT B. on August 02, 2017, 09:41:13 am



Title: DomNode selectbypath selectbyxpath using contains or starts-with
Post by: ORGA-SOFT B. on August 02, 2017, 09:41:13 am
Hello @ all,

i'm trying to get all elements in the domnode that matches a string in the name tag.
So in xml i can do this with like this:

XPath  = //*[contains(@name, 'page_tab_')]
It selects all nodes that have the string page_tab_ inside the name

But when i try this at the function selectbypath of a domnode this doesn't work.

Here is my Code

   DEFINE   vlname      STRING,
            domtree     om.domnode,
            dmfieldlist om.nodelist,
            uiwin       ui.Window

   LET uiWin  = ui.WINDOW.getCurrent()
   LET domtree = uiWin.getNode()
   
   LET dmfieldlist = domtree.selectByPath("//*[contains(\"@name\", \"page_tab\")]")
   
   RETURN dmfieldlist

Hope someone can help me thanks a lot

Martin Stigmond


Title: Re: DomNode selectbypath selectbyxpath using contains or starts-with
Post by: Reuben B. on August 04, 2017, 01:56:50 am
Hi Martin,

The om.DomNode.selectByPath has a limited syntax so as to support its intended use for finding nodes in the DOM tree.  So as per the documentation ...   http://4js.com/online_documentation/fjs-fgl-manual-html/#c_fgl_ClassDomNode_selectByPath.html ...and the example ... http://4js.com/online_documentation/fjs-fgl-manual-html/#c_fgl_ClassNodeList_example_2.html you just need to modify your clause to match what is given there.   

Something like (hopefully the slashes and quotes make it through to what you read)
Code
  1. domtree.selectByPath("//*[@name=\"page_tab\"]")

Historically I've wrapped it in a library function so I don't have to deal with the slashes and quotes each time when I call it!

Reuben