Parsing xml?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Parsing xml?

Peter Sharp-2
Looking for pointers (examples preferably) on parsing xml in NetRexx.

The task is formatting MQFTE transfer log msgs. This was done
historically by a set of java pgms whose origin I'm unfamiliar with.
Following one upgrade several years ago of the command-and-coordinator
qmgr from MQ v7.5 to v8.0, the xml parser ('log reporter') was throwing
errors on logger msgs produced by FTE agents that were also upgraded. My
java cluelessness (& other resource constrictions) resulted in me
cobbling together an alternate parser using shell script examples freely
available. I struggled to comprehend how the java solution functioned,
and my attempts at inserting debug stmts just broke it - throwing me at
the quick-n-dirty shell script option. You know how deadlines loom.
However, while it works & at least I can understand it, it's SLOW.

So, the goal is to return to a better performing java based MQFTE log
reporter by means of NetRexx. I've often thought there must be a NetRexx
xml parser solution out there somewhere.

Does such a tool exist?

Peter

BTW, MQ upgrades to v9.1 are well under way.

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Parsing xml?

Rony G. Flatscher
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
ZjQcmQRYFpfptBannerEnd
On 07.06.2021 15:14, Peter Sharp wrote:
Looking for pointers (examples preferably) on parsing xml in NetRexx.

The task is formatting MQFTE transfer log msgs. This was done historically by a set of java pgms whose origin I'm unfamiliar with. Following one upgrade several years ago of the command-and-coordinator qmgr from MQ v7.5 to v8.0, the xml parser ('log reporter') was throwing errors on logger msgs produced by FTE agents that were also upgraded. My java cluelessness (& other resource constrictions) resulted in me cobbling together an alternate parser using shell script examples freely available. I struggled to comprehend how the java solution functioned, and my attempts at inserting debug stmts just broke it - throwing me at the quick-n-dirty shell script option. You know how deadlines loom. However, while it works & at least I can understand it, it's SLOW.

So, the goal is to return to a better performing java based MQFTE log reporter by means of NetRexx. I've often thought there must be a NetRexx xml parser solution out there somewhere.

Does such a tool exist?

Peter

BTW, MQ upgrades to v9.1 are well under way.

Not sure this will help you, but may enable you to take advantage of Java-SAX and/or Java-DOM solutions from NetRexx, by rewriting/recoding the BSF4ooRexx examples in NetRexx. If you do, I would be very interested in them of course! :)

  • SAX (simple API for XML, [1]): maybe the easiest/quickest route to parsing xml: here [2] the presentation from the 2013 RexxLA symposium [3].
  • DOM (document object model, [4]): the presentation from the 2013 RexxLA symposium [5].

If you have ooRexx and install BSF4ooRexx you would find the ooRexx samples to transcribe to NetRexx in the "samples/SAX" and "samples/DOM" subdirectories.

---

Again, IMHO, the fastest/easiest route is probably via SAX.

HTH,

---rony

[1] "Simple API for XML": <https://en.wikipedia.org/wiki/Simple_API_for_XML>
[2] "Processing XML Documents with SAX Using BSF4ooRexx": <https://www.rexxla.org/events/2013/presentations/rgf_SAX_201305.pdf>
[3] The 2013 International Rexx Symposium: <https://www.rexxla.org/events/2013/schedule.html>
[4] "Document Object Model": <https://en.wikipedia.org/wiki/Document_Object_Model>
[5] "Processing XML Documents with DOM Using BSF4ooRexx": <https://www.rexxla.org/events/2013/presentations/rgf_DOM_201305.pdf>


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Parsing xml?

Peter Sharp-2
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
ZjQcmQRYFpfptBannerEnd


On 7/6/21 11:45 pm, Rony G. Flatscher wrote:
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
ZjQcmQRYFpfptBannerEnd
On 07.06.2021 15:14, Peter Sharp wrote:
Looking for pointers (examples preferably) on parsing xml in NetRexx.

The task is formatting MQFTE transfer log msgs. This was done historically by a set of java pgms whose origin I'm unfamiliar with. Following one upgrade several years ago of the command-and-coordinator qmgr from MQ v7.5 to v8.0, the xml parser ('log reporter') was throwing errors on logger msgs produced by FTE agents that were also upgraded. My java cluelessness (& other resource constrictions) resulted in me cobbling together an alternate parser using shell script examples freely available. I struggled to comprehend how the java solution functioned, and my attempts at inserting debug stmts just broke it - throwing me at the quick-n-dirty shell script option. You know how deadlines loom. However, while it works & at least I can understand it, it's SLOW.

So, the goal is to return to a better performing java based MQFTE log reporter by means of NetRexx. I've often thought there must be a NetRexx xml parser solution out there somewhere.

Does such a tool exist?

Peter

BTW, MQ upgrades to v9.1 are well under way.

Not sure this will help you, but may enable you to take advantage of Java-SAX and/or Java-DOM solutions from NetRexx, by rewriting/recoding the BSF4ooRexx examples in NetRexx. If you do, I would be very interested in them of course! :)

  • SAX (simple API for XML, [1]): maybe the easiest/quickest route to parsing xml: here [2] the presentation from the 2013 RexxLA symposium [3].
  • DOM (document object model, [4]): the presentation from the 2013 RexxLA symposium [5].

If you have ooRexx and install BSF4ooRexx you would find the ooRexx samples to transcribe to NetRexx in the "samples/SAX" and "samples/DOM" subdirectories.

---

Again, IMHO, the fastest/easiest route is probably via SAX.

HTH,

---rony

[1] "Simple API for XML": <https://en.wikipedia.org/wiki/Simple_API_for_XML>
[2] "Processing XML Documents with SAX Using BSF4ooRexx": <https://www.rexxla.org/events/2013/presentations/rgf_SAX_201305.pdf>
[3] The 2013 International Rexx Symposium: <https://www.rexxla.org/events/2013/schedule.html>
[4] "Document Object Model": <https://en.wikipedia.org/wiki/Document_Object_Model>
[5] "Processing XML Documents with DOM Using BSF4ooRexx": <https://www.rexxla.org/events/2013/presentations/rgf_DOM_201305.pdf>

Rony,

Thanks for the pointers. Unfortunately, a bsf4ooRexx install didn't yield the promised samples (this time). Have I missed something?

Below is the result of searches for the samples, SAX & DOM dirs, plus a search for any *.rxj files under the bsf4ooRexx install dir.

--------------------------------

[psharp@fedora NetRexx]$ find bsf4ooRexx -name samples
bsf4ooRexx/BSF4ooRexx_testUnits/bsf4oorexx.dev/testUnits/ooTest-5.0.0-20171022/ooRexx/samples
[psharp@fedora NetRexx]$ find bsf4ooRexx -name SAX
[psharp@fedora NetRexx]$ find bsf4ooRexx -name DOM
[psharp@fedora NetRexx]$ ls -al bsf4ooRexx//BSF4ooRexx_testUnits/bsf4oorexx.dev//testUnits//ooTest-5.0.0-20171022/ooRexx//samples
total 20
drwxrwxr-x. 1 psharp psharp   78 Oct 25  2017 .
drwxrwxr-x. 1 psharp psharp  136 Oct 25  2017 ..
-rw-rw-r--. 1 psharp psharp 9392 Mar  8  2018 drives.testGroup
-rw-rw-r--. 1 psharp psharp 5990 Mar  8  2018 month.testGroup
drwxrwxr-x. 1 psharp psharp   16 Oct 25  2017 ooDialog
[psharp@fedora NetRexx]$ find bsf4ooRexx -name '*.rxj'
bsf4ooRexx/BSF4ooRexx_testUnits/bsf4oorexx.dev/testUnits/bsf4rexx/java8/defaultMethods/test.rxj
[psharp@fedora NetRexx]$


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Parsing xml?

Rony G. Flatscher
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
ZjQcmQRYFpfptBannerEnd


On 07.06.2021 16:56, Peter Sharp wrote:
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
ZjQcmQRYFpfptBannerEnd


On 7/6/21 11:45 pm, Rony G. Flatscher wrote:
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
ZjQcmQRYFpfptBannerEnd
On 07.06.2021 15:14, Peter Sharp wrote:
Looking for pointers (examples preferably) on parsing xml in NetRexx.

The task is formatting MQFTE transfer log msgs. This was done historically by a set of java pgms whose origin I'm unfamiliar with. Following one upgrade several years ago of the command-and-coordinator qmgr from MQ v7.5 to v8.0, the xml parser ('log reporter') was throwing errors on logger msgs produced by FTE agents that were also upgraded. My java cluelessness (& other resource constrictions) resulted in me cobbling together an alternate parser using shell script examples freely available. I struggled to comprehend how the java solution functioned, and my attempts at inserting debug stmts just broke it - throwing me at the quick-n-dirty shell script option. You know how deadlines loom. However, while it works & at least I can understand it, it's SLOW.

So, the goal is to return to a better performing java based MQFTE log reporter by means of NetRexx. I've often thought there must be a NetRexx xml parser solution out there somewhere.

Does such a tool exist?

Peter

BTW, MQ upgrades to v9.1 are well under way.

Not sure this will help you, but may enable you to take advantage of Java-SAX and/or Java-DOM solutions from NetRexx, by rewriting/recoding the BSF4ooRexx examples in NetRexx. If you do, I would be very interested in them of course! :)

  • SAX (simple API for XML, [1]): maybe the easiest/quickest route to parsing xml: here [2] the presentation from the 2013 RexxLA symposium [3].
  • DOM (document object model, [4]): the presentation from the 2013 RexxLA symposium [5].

If you have ooRexx and install BSF4ooRexx you would find the ooRexx samples to transcribe to NetRexx in the "samples/SAX" and "samples/DOM" subdirectories.

---

Again, IMHO, the fastest/easiest route is probably via SAX.

HTH,

---rony

[1] "Simple API for XML": <https://en.wikipedia.org/wiki/Simple_API_for_XML>
[2] "Processing XML Documents with SAX Using BSF4ooRexx": <https://www.rexxla.org/events/2013/presentations/rgf_SAX_201305.pdf>
[3] The 2013 International Rexx Symposium: <https://www.rexxla.org/events/2013/schedule.html>
[4] "Document Object Model": <https://en.wikipedia.org/wiki/Document_Object_Model>
[5] "Processing XML Documents with DOM Using BSF4ooRexx": <https://www.rexxla.org/events/2013/presentations/rgf_DOM_201305.pdf>

Rony,

Thanks for the pointers. Unfortunately, a bsf4ooRexx install didn't yield the promised samples (this time). Have I missed something?

Below is the result of searches for the samples, SAX & DOM dirs, plus a search for any *.rxj files under the bsf4ooRexx install dir.

--------------------------------

[psharp@fedora NetRexx]$ find bsf4ooRexx -name samples
bsf4ooRexx/BSF4ooRexx_testUnits/bsf4oorexx.dev/testUnits/ooTest-5.0.0-20171022/ooRexx/samples
[psharp@fedora NetRexx]$ find bsf4ooRexx -name SAX
[psharp@fedora NetRexx]$ find bsf4ooRexx -name DOM
[psharp@fedora NetRexx]$ ls -al bsf4ooRexx//BSF4ooRexx_testUnits/bsf4oorexx.dev//testUnits//ooTest-5.0.0-20171022/ooRexx//samples
total 20
drwxrwxr-x. 1 psharp psharp   78 Oct 25  2017 .
drwxrwxr-x. 1 psharp psharp  136 Oct 25  2017 ..
-rw-rw-r--. 1 psharp psharp 9392 Mar  8  2018 drives.testGroup
-rw-rw-r--. 1 psharp psharp 5990 Mar  8  2018 month.testGroup
drwxrwxr-x. 1 psharp psharp   16 Oct 25  2017 ooDialog
[psharp@fedora NetRexx]$ find bsf4ooRexx -name '*.rxj'
bsf4ooRexx/BSF4ooRexx_testUnits/bsf4oorexx.dev/testUnits/bsf4rexx/java8/defaultMethods/test.rxj
[psharp@fedora NetRexx]$

Peter, you seem to have fetched the BSF4ooRexx testunits. Given your last output (path to test.rxj), the samples directory should be in "bsf4ooRexx/BSF4ooRexx_testUnits/samples" on your machine.

If you had installed BSF4ooRexx on a Linux machine, it should be in "/opt/BSF4ooRexx/samples".

Alternatively, you could look them up starting out pointing your browser at: <https://sourceforge.net/p/bsf4oorexx/code/HEAD/tree/trunk/samples/>.

HTH,

---rony




_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Parsing xml?

Jason Martin
In reply to this post by Peter Sharp-2
Follow along with NetRexx

A Java to NetRexx conversion that could be done better

Their stuff; Their rules

https://howtodoinjava.com/java/xml/sax-parser-read-xml-example/ 

Download the conversion

https://github.com/agrellum/NetRexx-Samples/raw/master/SAXNRX.tar.gz 

unpack

cd to it

nrc *nrx

java TestSaxParser

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Parsing xml?

Peter Sharp-2
Thanks Jason! As expected, the nrx solution is so much more elegant than
java :-)

Seeing the flavours of xml parsing listed there, what I actually need is
an nrx version of the convert-xml-to-properties function. Should keep me
busy for a while.

Peter

On 8/6/21 3:06 am, Jason Martin wrote:

> Follow along with NetRexx
>
> A Java to NetRexx conversion that could be done better
>
> Their stuff; Their rules
>
> https://howtodoinjava.com/java/xml/sax-parser-read-xml-example/ 
> Download the conversion
>
> https://github.com/agrellum/NetRexx-Samples/raw/master/SAXNRX.tar.gz 
> unpack
>
> cd to it
>
> nrc *nrx
>
> java TestSaxParser
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Parsing xml?

Jason Martin
--package com.howtodoinjava.demo

import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.util.InvalidPropertiesFormatException
import java.util.Properties

class XMLToProperties public


   method main(args=String[]) static signals
InvalidPropertiesFormatException,IOException
     --outPropertiesFile=String
     outPropertiesFile="./application.properties"
     --inXmlFile=String
     inXmlFile="applicationProperties.xml"
     --inStream=InputStream
     inStream=FileInputStream(inXmlFile)
     --outStream=OutputStream
     outStream=FileOutputStream(outPropertiesFile)
     --props=Properties
     props=Properties()
     props.loadFromXML(inStream)
     props.store(outStream,"Converted from applicationProperties.xml")
     --System.out.println(props.get("input.dir"))
     say props.get("input.dir")

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Parsing xml?

Jason Martin

Second verse same as the first.

tweak args=String[], types and directories.


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Parsing xml?

Peter Sharp-2
In reply to this post by Jason Martin
Well, I have the beginnings of an xml parser, thanks to Rony & Jason!

Copied this input from somewhere in the samples:

[psharp@fedora SAXNRX]$ cat ./MyProps.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd ">
<properties>
     <comment>application.properties</comment>
     <entry key="input.dir">c:/temp/input</entry>
     <entry key="spring.batch.job.enabled">false</entry>
     <entry key="spring.main.banner-mode">off</entry>
</properties>
[psharp@fedora SAXNRX]$

Clean compile (finally!):

[psharp@fedora SAXNRX]$ nrc xmlToProps.nrx
NetRexx portable processor 4.01-GA build 573-20210320-2000
Copyright (c) RexxLA, 2011,2021.   All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program xmlToProps.nrx
   === class xmlToProps ===
     function main(String[])
       signals IOException,InvalidPropertiesFormatException
Compilation of 'xmlToProps.nrx' successful
[psharp@fedora SAXNRX]$

Useful execution:

[psharp@fedora SAXNRX]$ java xmlToProps ./MyProps.xml
#XML Properties file: ./MyProps.xml
spring.batch.job.enabled=false
input.dir=c:/temp/input
spring.main.banner-mode=off
[psharp@fedora SAXNRX]$

And finally, a rudimentary xml properties parser:

[psharp@fedora SAXNRX]$ cat xmlToProps.nrx

--package com.howtodoinnrx.xml.sax

import java.io.File
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.util.Properties

class xmlToProps public


   method main(args=String[]) static signals FileNotFoundException
     say '#XML Properties file:' (string args[0])
     xmlFile=File(args[0])
     props=Properties()
     props.loadFromXML(FileInputStream(xmlFile))
     keyList = props.propertyNames()
     loop while keyList.hasMoreElements()
        key = keyList.nextElement()
        value = props.getProperty(String key)
        say key"="value
     end

[psharp@fedora SAXNRX]$

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/