Thread: [tcljava-user] jacl 1.3.1 regexp
Brought to you by:
mdejong
From: Johannes K. <joh...@kl...> - 2007-04-09 12:32:48
|
Hi all, I look for a way to parse an XML-File in IBMs wsadmin, which uses jacl 1.3.1 as a scripting language. I found a project called sa4was [1] on IBMs developerworks which does parsing XML with regexp. sa4was works with WebSpher 5.x (which used jacl 1.2.x) however in WebSphere 6.0 (which uses jacl 1.3.1) it doesn't work anymore. Some code in sa4was does the following: ============================================ while {[regexp {([^=]+)="([^"]*?)"(.*)} $restOfTag dontCare attributeName attributeValue restOfTag]} { if {$attributeName == "id"} { set idValue $attributeValue break } } ============================================ and there I get the error "couldn't compile regular expression pattern: nested *?+" I found out that regexp changed in jacl 1.3.1 and non-greedy regexp (with this "*?" expression) doesn't work anymore. Is that right? Questions: a) So are there workarounds for something like that? b) Or are there some better ways to parse XML in jacl? Any help would be appreciated!! best regards, Johannes Links: 1: http://www.alphaworks.ibm.com/tech/sa4was |
From: Patrick F. <pfi...@oz...> - 2007-04-09 13:16:50
|
On Monday 09 April 2007 13:32, Johannes Kleinlercher wrote: > Hi all, > > I look for a way to parse an XML-File in IBMs wsadmin, which uses jacl > 1.3.1 as a scripting language. > > I found a project called sa4was [1] on IBMs developerworks which does > parsing XML with regexp. sa4was works with WebSpher 5.x (which used jacl > 1.2.x) however in WebSphere 6.0 (which uses jacl 1.3.1) it doesn't work > anymore. > > Some code in sa4was does the following: > > ============================================ > while {[regexp {([^=]+)="([^"]*?)"(.*)} $restOfTag dontCare > attributeName attributeValue restOfTag]} { > if {$attributeName == "id"} { > set idValue $attributeValue > break > } > } > ============================================ > > and there I get the error > "couldn't compile regular expression pattern: nested *?+" > > > I found out that regexp changed in jacl 1.3.1 and non-greedy regexp > (with this "*?" expression) doesn't work anymore. Is that right? > > Questions: > a) So are there workarounds for something like that? > b) Or are there some better ways to parse XML in jacl? > The quick work around for existing sa4was scripts in a WAS 6 environment is to downgrade JACL from 1.3.1 to 1.2.X by replacing the 1.3.1 jacl.jar and tcljava.jar jar files in the was/installdirectory/lib directory. However I would not recommend using sa4was with 6.0 because it's is not supported by IBM in 6.x. I have a JACL script library for WAS which I am posting on the internet this week that covers most of the WAS admin functions. You should have a look at that. The Tcl xml parser TclXml has not been ported to JACL so you need to use 'regexp' or 'string match' to parse XML. If you want to use Tcl packages that have not been ported to JACL in a scripted WebSphere admin environment then you will need to use TclBlend as a java client with the WebSphere JMX java library. There are plenty of articles on Developerworks that describe WAS admin using java clients rather than Wasadmin clients written in Jython or Jacl. I am re-writing most of my stuff to use TclBlend because while IBM might drop support for Jacl and Jython in future releases the JVM layer will always be there. |
From: Johannes K. <joh...@kl...> - 2007-04-09 14:37:33
|
sa4was isn't supported anyway by IBM so I don't think that is the point. I am developing my own deployment-scripts so I just wanted to take some code of sa4was and use it in my scripts. Parsing XML files was some of it. I didn't find any code to do that and I don't think it is easy without a good regexp-engine. Non-greedy regexp is one important thing for parsing XML, I think. Do you have some piece of code which can parse XML-Files with the regexp-engine in jacl 1.3.1? I will look at your homepage the next time and look forward to your jacl libraries. Am Montag, den 09.04.2007, 14:22 +0100 schrieb Patrick Finnegan: > On Monday 09 April 2007 13:32, Johannes Kleinlercher wrote: > > Hi all, > > > > I look for a way to parse an XML-File in IBMs wsadmin, which uses jacl > > 1.3.1 as a scripting language. > > > > I found a project called sa4was [1] on IBMs developerworks which does > > parsing XML with regexp. sa4was works with WebSpher 5.x (which used jacl > > 1.2.x) however in WebSphere 6.0 (which uses jacl 1.3.1) it doesn't work > > anymore. > > > > Some code in sa4was does the following: > > > > ============================================ > > while {[regexp {([^=]+)="([^"]*?)"(.*)} $restOfTag dontCare > > attributeName attributeValue restOfTag]} { > > if {$attributeName == "id"} { > > set idValue $attributeValue > > break > > } > > } > > ============================================ > > > > and there I get the error > > "couldn't compile regular expression pattern: nested *?+" > > > > > > I found out that regexp changed in jacl 1.3.1 and non-greedy regexp > > (with this "*?" expression) doesn't work anymore. Is that right? > > > > Questions: > > a) So are there workarounds for something like that? > > b) Or are there some better ways to parse XML in jacl? > > > > The quick work around for existing sa4was scripts in a WAS 6 environment is to > downgrade JACL from 1.3.1 to 1.2.X by replacing the 1.3.1 jacl.jar and > tcljava.jar jar files in the was/installdirectory/lib directory. > > However I would not recommend using sa4was with 6.0 because it's is not > supported by IBM in 6.x. I have a JACL script library for WAS which I am > posting on the internet this week that covers most of the WAS admin > functions. You should have a look at that. > > The Tcl xml parser TclXml has not been ported to JACL so you need to use > 'regexp' or 'string match' to parse XML. > > If you want to use Tcl packages that have not been ported to JACL in a > scripted WebSphere admin environment then you will need to use TclBlend as a > java client with the WebSphere JMX java library. There are plenty of > articles on Developerworks that describe WAS admin using java clients rather > than Wasadmin clients written in Jython or Jacl. I am re-writing most of my > stuff to use TclBlend because while IBM might drop support for Jacl and > Jython in future releases the JVM layer will always be there. |
From: Patrick F. <pfi...@oz...> - 2007-04-09 16:11:43
|
On Monday 09 April 2007 15:37, Johannes Kleinlercher wrote: > sa4was isn't supported anyway by IBM so I don't think that is the > point. Parts of the underlying JMX implementation have changed in WS6.0. I had to modify some of my WAS 5.1 jacl scripts to cope with this. Since sa4was is a simplification of the WAS 5.1 JMX layer it may not cope with these changes so if you are starting from scratch I would avoid using sa4was with 6. The sarwas author is aware of these issues. See thread on the se4was forum. http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?message=13714004&cat=28&thread=78335&treeDisplayType=threadmode1&forum=443#13714004 > > I am developing my own deployment-scripts so I just wanted to take some > code of sa4was and use it in my scripts. Parsing XML files was some of > it. I didn't find any code to do that and I don't think it is easy > without a good regexp-engine. Non-greedy regexp is one important thing > for parsing XML, I think. Do you have some piece of code which can parse > XML-Files with the regexp-engine in jacl 1.3.1? > I have never had the need to parse XML files in JACL mainly because IBM do not recommend manual modification of the underlying WAS xml config files. I don't know whether jacl 1.4.0 supports non greedy regexp but if it does then you can upgrade the WAS 6.0 jacl environment by simply downloading the jacl 1.4 binary and replacing the jacl.jar and tcljava.jar files in the wasinstall/appserver/lib directory with the 1.4 jars. I have tested 1.4 with WAS 6.0 and have not had a single problem. It's rock solid. You can test the regexp in jacl 1.4 independently. See this link. link:http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=60&t=000208 You can also run wsadmin with Jacl 1.4 as an external tool in eclipse. See this link. http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?message=13714004&cat=28&thread=78335&treeDisplayType=threadmode1&forum=443#13714004 |
From: Mo D. <mo...@mo...> - 2007-04-09 21:31:38
|
Johannes Kleinlercher wrote: > Hi all, > > I look for a way to parse an XML-File in IBMs wsadmin, which uses jacl > 1.3.1 as a scripting language. > > I found a project called sa4was [1] on IBMs developerworks which does > parsing XML with regexp. sa4was works with WebSpher 5.x (which used jacl > 1.2.x) however in WebSphere 6.0 (which uses jacl 1.3.1) it doesn't work > anymore. > > Some code in sa4was does the following: > > ============================================ > while {[regexp {([^=]+)="([^"]*?)"(.*)} $restOfTag dontCare > attributeName attributeValue restOfTag]} { > if {$attributeName == "id"} { > set idValue $attributeValue > break > } > } > ============================================ > > and there I get the error > "couldn't compile regular expression pattern: nested *?+" > > > I found out that regexp changed in jacl 1.3.1 and non-greedy regexp > (with this "*?" expression) doesn't work anymore. Is that right? > > Questions: > a) So are there workarounds for something like that? > b) Or are there some better ways to parse XML in jacl? > Currently, there is no workaround except porting regexp code back to use the older Tcl 8.1 style regexp syntax. Very old versions of Jacl made use or the Oro regexp package, but it was non free and had to be removed from Jacl. But, lets back up a minute. I would not even suggest that you use regexp commands to parse your XML code. Using a series of regexp call like that is going to be SLOW! There is just no way around it, you would be much better off using a XML parsing engine written in Java. There are lots and lot of them available. You could create your XML parser in Java and build up a DOM in memory and then pass a handle to the DOM back to your Tcl scripts. It is actually quite easy to examine and decode a DOM tree with Tcl code once you have your own utility procs that examine subtrees and extract data from nodes. I hope that helps Mo DeJong |