× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



If I could make a recommendation on the direction of your
architecture...

I have found that going direct to a set of Java API's can often create
more Java prototypes than necessary in your RPG program.  I would
instead create a custom Java class that would encapsulate the XML
parsing/serializing and all you have to do from RPG is call methods that
are relating to the business logic side of things.

Say you want to create the following XML:

<Order>
  <Item>123</Item>
  <Item>456</Item>
</Order>

Create a Java class that operates as an order object with methods like
addItem().  Then in your RPG code all you would do is something like
this:

... Instantiate java object in D specs ...

ordObj = NewOrder();

Chain ItemFile;
Dow Not %EOF(ItemFile);
  addItem(ordObj: itmNbrFld);
EndDo;

serializeXML(ordObj: '/ifsfolder/ifsfile.xml');

*InLR = *On;

In my mind this creates a nicer separation of java and RPG, but that I
suppose is pure opinion.  

Aaron Bartell



-----Original Message-----
From: rpg400-l-bounces+albartell=taylorcorp.com@xxxxxxxxxxxx
[mailto:rpg400-l-bounces+albartell=taylorcorp.com@xxxxxxxxxxxx] 
Sent: Wednesday, September 29, 2004 2:34 AM
To: RPG programming on the AS400 / iSeries
Subject: Using Java within RPG... 





I am trying to create an XML file within my RPG program and am trying to
implement something similar to the following java code:

 // Creation of an XML document
 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 DocumentBuilder db = dbf.newDocumentBuilder();

My prototype declaration looks like this:

d documentBuilderFactory...
d                 S               O   CLASS(*JAVA:'javax.xml.-
d                                     parsers.DocumentBuilderFactory')

 * create newInstance of DocumentBuilderFactory d
makeDocumentBuilderFactory...
d                 PR              O   STATIC EXTPROC(*JAVA:'javax.xml.-
d                                     parsers.DocumentBuilderFactory':
d                                     'newInstance')
d                                     CLASS(*JAVA:'javax.xml.-
d                                     parsers.DocumentBuilderFactory')

d documentBuilder...
d                 S               O   CLASS(*JAVA:'javax.xml.-
d                                     parsers.DocumentBuilder')

 * create newInstance of DocumentBuilder d makeDocumentBuilder...
d                 PR              O   STATIC EXTPROC(*JAVA:'javax.xml.-
d                                     parsers.DocumentBuilderFactory':
d                                     'newDocumentBuilder')
d                                     CLASS(*JAVA:'javax.xml.-
d                                     parsers.DocumentBuilder')

in my free format code, i've got the following..

   documentBuilderFactory = makeDocumentBuilderFactory();
   documentBuilder = makeDocumentBuilder();


The first statement works ok, but I get the following error on the
second statement.

 Message . . . . :   Java exception received when calling Java method.
 Cause . . . . . :   RPG procedure JAVAXML2 in program RJOSEPH/JAVAXML2
   received Java exception "java.lang.NoSuchMethodError:
newDocumentBuilder"
   when calling method "newDocumentBuilder" with signature
   "()Ljavax.xml.parsers.DocumentBuilder;" in class
   "javax.xml.parsers.DocumentBuilderFactory".


Can anyone point out anything obvious that I am missing here? I am
convinced that this error occurs because I am creating a DocumentBuilder
out of an object that is not initialised, but is there anyway I can use
my documentBuilderFactory created in the first statement to generate the
DocumentBuilder (like in the java code)?

Thanks in advance.

Roshan

--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing
list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.