[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: xml-sax issue



   I am not clear as to why you would be using a VarChar field in any
   case.
   The data coming in is not a VarChar. It is a straight character and you
   would not be trimming it.
   The data length parameter says how long the data actually is. All it is
   passing is a pointer to the data so as in my example program
   dcl-s Data Char(32765) Based(InPointerToData);
   So lets say it a Order number and the length says 7.
   OrderNumber = %Subst(Data:1:Length);
   This pulls that value out of the incoming field.
   Now if you try to reference anything past 7 in this example, you are
   going to get garbage.
   On the next *XMLCHARS event it might be 50.
   You need to look for *XML_START_ELEMENT and see if this an element that
   you want.
   What I do is just build a tag.
   So first time in
   /REQUEST
   Then
   /REQUEST/ORDER
   then
   /REQUEST/ORDER/NUMBER
   Then in the *XML_CHARS event I just compare to see if I want to process
   that event
   If Tag = '/REQUEST/ORDER/NUMBER';
   � // Process order number.
   etc.

   On Tue, Sep 8, 2015 at 12:44 PM, Elbert Cook
   <[1]elbert@xxxxxxxxxxxxxxx> wrote:

     � �Could the problem be something like the following scenario. If
     not my
     � �apologizes for not understanding the question.
     � �xml = %trim(%subst(GetResponse: 3: 5000));
     � �When you have a varying field, the field contains 2 extra
     invisible
     � �positions, contain the length of the data.
     � �D Data1 s 20a
     � �D Data2 s 20a
     � �D Data3 s 20a
     � �D ds
     � �D GetResponse 20a varying inz('<MMMProcess>')
     � �D InvisLen 2a overlay(GetResponse: 1)
     � �D Value 20a overlay(GetResponse: 3)
     � �Data1 = Value;
     � �Data2 = %subst(GetResponse: 1)
     � �Data3 = %subst(GetResponse: 3)
     � �Data1 contains "<MMMProcess>"
     � �Data2 contains "<MMMProcess>"
     � �Data3 contains "MMProcess>"
     � �With %subst your start with position 1, if you are using a data
     � �structure
     � �you start with position 3.
     � �----> I'm getting a weird character �MMMProcess>
     � �Yes, GetResponse would have a weird first two position if you
     are
     � �retrieving
     � �the first two invisible fields.
     � �-----Original Message-----
     � �From: Paul Roy [mailto:[2]paul.roy@xxxxxxx]
     � �Sent: Tuesday, September 08, 2015 3:02 PM
     � �To: HTTPAPI and FTPAPI Projects
     � �Subject: Re: xml-sax issue
     � �that's looks like a problem of a variable length string not
     correctly
     � �defined...
     � �mismatch in a definition of a program/procedure ?
     � �Paul
     � �From: "RPG List" <[3]rpglist@xxxxxxxxxxx>
     � �To: "HTTPAPI and FTPAPI Projects"
     <[4]ftpapi@xxxxxxxxxxxxxxxxxxxxxx>
     � �Date: 08/09/2015 19:42
     � �Subject: Re: xml-sax issue
     � �Sent by: [1][5]ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
     � �John,
     � �I don't recall off the top of my head. He tried sending it as
     UTF-16
     � �but
     � �its defaulting to 8 so I'm not sure if that's the problem or
     not.
     � �I recompiled the srvpgm and stubs and created the sample
     program, in
     � �debug
     � �when I check the xml value immediately following the web
     service call
     � �I'm
     � �getting a weird character �MMMProcess>
     � �and it is starting in position 2. I don't recall seeing this
     before.
     � �Ideas?
     � �> XML-INTO is usually a lot less work than XML-SAX unless you
     only want
     � �> a small portion of the data. From what you posted earlier it
     didn?t
     � �> look that complex - what problems did you encounter with
     XML-INTO?
     � �>
     � �>
     � �> On Sep 8, 2015, at 2:21 PM, RPG List <[6]rpglist@xxxxxxxxxxx>
     wrote:
     � �>
     � �>> Scott the 3:5000 is a typo, that should be a 1.
     � �>>
     � �>> I am using XML-SAX because I wasn't able to get XML-INTO to
     work.
     � �>> However, I found out this morning that the XML is coming in
     as
     � �UTF-8.
     � �>> I asked him to change that to 16 for a test, since I recall
     reading
     � �>> that RPG does not like 8.
     � �>>
     � �>> I'm open to suggestions to make this learning curve easier
     � �>>
     � �>>
     � �>>> Dutch,
     � �>>>
     � �>>> You are doing this:
     � �>>>
     � �>>> xml = %trim(%subSt(GetResponse:3:5000));
     � �>>>
     � �>>> Can you explain why you are doing that %subst? Wouldn't
     that cause
     � �the
     � �>>> '<M' at the start of the XML document to be chopped off,
     making
     � �this
     � �an
     � �>>> invalid document?
     � �>>>
     � �>>> The %trim() is not necessary, but shouldn't hurt anything.
     � �>>>
     � �>>> Can you explain why you want to use XML-SAX here instead of
     � �XML-INTO
     � �or
     � �>>> the XML parser included with HTTPAPI? (Which is a wrapper
     around
     � �>>> Expat)
     � �>>>
     � �>>>
     � �>>> On 9/4/2015 4:34 PM, RPG List wrote:
     � �>>>> Scott,
     � �>>>> I'm not sure we don't have another problem. Here's why
     when I step
     � �>>>> through the xmlhandler, I get the start_document on the
     first
     � �read,
     � �>>>> and then I get end_document on the second read. That's it.
     Its
     � �>>>> almost
     � �as
     � �>>>> though its never seeing the data further. I ran a test
     using the
     � �>>>> following:
     � �>>>>
     � �>>>> XML = '<xmlTest>+
     � �>>>> <name type="author">AS400 Sample Code/name>+
     � �>>>> </xmlTest>';
     � �>>>>
     � �>>>> that worked.
     � �>>>>
     � �>>>> Here is what the xml document looks like coming in:
     � �>>>>
     � �>>>>
     '<MMMProcess><Results><Claim>8104550</Claim><Amount>1995.83</'
     � �>>>> 'Amount><Code>7320</Code><Xrg>53</Xrg><MEANLOS2>2</MEAN'
     � �>>>> 'LOS2><Error_Code>0</Error_Code></Results></MMMProcess>'
     � �>>>>
     � �>>>>
     � �>>>> I just can't find what's wrong with the xml..
     � �>>>>
     � �>>>>
     � �>>>>> Dutch,
     � �>>>>>
     � �>>>>> The XML processing instructions ("header" as you call it)
     are
     � �>>>>> optional.
     � �>>>>> They are not required.
     � �>>>>>
     � �>>>>> The problem is what I said in my first reply to you.
     Please read
     � �the
     � �>>>>> article I linked to so you can learn how XML-SAX works.
     � �>>>>>
     � �>>>>> -SK
     � �>>>>>
     � �>>>>>
     � �>>>>> On 9/4/2015 3:18 PM, RPG List wrote:
     � �>>>>>> one additional issue I saw this morning Scott and maybe
     this is
     � �>>>>>> the problem, the incoming XML does not have what I would
     call a
     � �standard
     � �>>>>>> header:
     � �>>>>>>
     � �>>>>>> IE: it does not have a version or description that I see
     in most
     � �xml
     � �>>>>>> documents, maybe that's needed or maybe not?
     � �>>>>>>
     � �>>>>>>
     � �>>>>>>> Dutch,
     � �>>>>>>>
     � �>>>>>>> This looks an awful lot like a program that I wrote a
     long time
     � �ago
     � �>>>>>>> to
     � �>>>>>>> print the XML events. I would not recommend using this
     to
     � �actually
     � �>>>>>>> parse a document -- to parse with XML-SAX you're going
     to need
     � �>>>>>>> to create a stack of XML elements (implemented in RPG
     as an
     � �>>>>>>> array, most
     � �>>>>>>> likely)
     � �>>>>>>> and keep track of the current XML element you're
     working on,
     � �etc.
     � �>>>>>>> There
     � �>>>>>>> was another program included in that same article
     called
     � �"CustXml"
     � �>>>>>>> that
     � �>>>>>>> demonstrates this -- that program would be a better
     starting
     � �point.
     � �>>>>>>>
     �     �[2][7]http://iprodeveloper.com/print/rpg-programming/rpgs-xml-sax-
     opco
     � �>>>>>>> de
     � �>>>>>>>
     � �>>>>>>> (use the "print" option to format the code better,
     Penton media
     � �has
     � �>>>>>>> screwed up the code figures in their article archive)
     � �>>>>>>>
     � �>>>>>>> Based on what you've shown us, the only thing you'd get
     in your
     � �>>>>>>> string is the name of the XML tag you're parsing.
     (Since that's
     � �>>>>>>> what's pointed to by "string" during the
     XML_START_ELEMENT
     � �>>>>>>> event.)
     � �>>>>>>>
     � �>>>>>>> You say you're getting nothing at all...? Since you're
     getting
     � �>>>>>>> it from the 'value' field, you'd need to show us the
     definition
     � �>>>>>>> and/or
     � �code
     � �>>>>>>> that
     � �>>>>>>> populates 'value' for us to see how that works. Funny
     that you
     � �>>>>>>> omitted that part of the code considering that your
     question is
     � �>>>>>>> about it?
     � �>>>>>>>
     � �>>>>>>> Also, is this part of a program that uses HTTPAPI or
     FTPAPI? If
     � �>>>>>>> so, I
     � �>>>>>>> guess we can discuss it here... if not, however, this
     really
     � �>>>>>>> doesn't
     � �>>>>>>> belong on this mailing list.
     � �>>>>>>>
     � �>>>>>>> -SK
     � �>>>>>>>
     � �>>>>>>>
     � �>>>>>>> On 9/3/2015 9:17 PM, RPG List wrote:
     � �>>>>>>>> I am attempting to parse out the data I'm getting from
     a web
     � �>>>>>>>> service and I'm having a little trouble.
     � �>>>>>>>>
     � �>>>>>>>> I'm using the following as my to the handler:
     � �>>>>>>>>
     � �>>>>>>>> xml = %trim(%subSt(GetResponse:3:5000));
     � �>>>>>>>> xml-sax %handler(xmlHandler: ignoreMe)
     � �>>>>>>>> %XML(xml: 'doc=string');
     � �>>>>>>>>
     � �>>>>>>>> GetResponse has the full xml string I'm expecting.
     � �>>>>>>>>
     � �>>>>>>>> my xmlhandler is defined as follows:
     � �>>>>>>>>
     � �>>>>>>>> P xmlHandler b
     � �>>>>>>>> D pi 10i 0
     � �>>>>>>>> D ignore 1a
     � �>>>>>>>> D event 10i 0 value
     � �>>>>>>>> D string * value
     � �>>>>>>>> D stringLen 20i 0 value
     � �>>>>>>>> D exceptionId 10i 0 value
     � �>>>>>>>>
     � �>>>>>>>> I then have the following code in the procedure:
     � �>>>>>>>>
     � �>>>>>>>> OutputXML.name = XML_Event_Name(event); OutputXML.data
     =
     � �>>>>>>>> *blanks;
     � �>>>>>>>>
     � �>>>>>>>> select;
     � �>>>>>>>> when string=*null or stringlen<1;
     � �>>>>>>>> // no string given...
     � �>>>>>>>> when stringlen>%size(value);
     � �>>>>>>>> OutputXML.data = '** string length invalid'; other;
     � �>>>>>>>> OutputXML.data = %subst(value:1:stringlen); endsl;
     � �>>>>>>>>
     � �>>>>>>>> // Change Current XML group if applicable Select;
     � �>>>>>>>> When OutputXML.name = 'XML_START_ELEMENT';
     � �>>>>>>>>
     � �>>>>>>>>
     � �>>>>>>>>
     � �>>>>>>>>
     � �>>>>>>>> The problem is outputXML.data never has a value that I
     can
     � �see.
     � �>>>>>>>> Am
     � �>>>>>>>> I
     � �>>>>>>>> doing something wrong or am I missing a step?
     � �>>>>>>>>
     � �>>>>>>>>
     � �>>>>>>>>
     � �>>>>>>>>
     � �>>>>>>>>
     � �>>>>>
     � �>>>
     � �>>>
     �     �------------------------------------------------------------------
     -----
     � �>>> This is the FTPAPI mailing list. To unsubscribe, please go
     to:
     � �>>> [3][8]http://www.scottklement.com/mailman/listinfo/ftpapi
     � �>>>
     �     �------------------------------------------------------------------
     -----
     � �>>>
     � �>>
     � �>>
     � �>>
     �     �------------------------------------------------------------------
     -----
     � �>> This is the FTPAPI mailing list. To unsubscribe, please go
     to:
     � �>> [4][9]http://www.scottklement.com/mailman/listinfo/ftpapi
     � �>>
     �     �------------------------------------------------------------------
     -----
     � �>
     � �> Jon Paris
     � �>
     � �> [5][10]www.partner400.com
     � �> [6][11]www.SystemiDeveloper.com
     � �>
     � �>
     �     �------------------------------------------------------------------
     -----
     � �> This is the FTPAPI mailing list. To unsubscribe, please go
     to:
     � �> [7][12]http://www.scottklement.com/mailman/listinfo/ftpapi
     � �>
     �     �------------------------------------------------------------------
     -----
     � �>
     � �>
     �     �------------------------------------------------------------------
     -----
     � �This is the FTPAPI mailing list. To unsubscribe, please go to:
     � �[8][13]http://www.scottklement.com/mailman/listinfo/ftpapi
     �     �------------------------------------------------------------------
     -----
     � �Disclaimer
     � �The information contained in this communication from the sender
     is
     � �confidential. It is intended solely for use by the recipient
     and others
     � �authorized to receive it. If you are not the recipient, you are
     hereby
     � �notified that any disclosure, copying, distribution or taking
     action in
     � �relation of the contents of this information is strictly
     prohibited and
     � �may be unlawful.
     � �This email has been scanned for viruses and malware, and may
     have been
     � �automatically archived by Mimecast Ltd, an innovator in
     Software as a
     � �Service (SaaS) for business. Providing a safer and more useful
     place
     � �for your human generated data. Specializing in; Security,
     archiving and
     � �compliance. To find out more [9]Click Here.
     References
     � �1. mailto:[14]ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
     � �2.
     [15]http://iprodeveloper.com/print/rpg-programming/rpgs-xml-sax-opco
     � �3. [16]http://www.scottklement.com/mailman/listinfo/ftpapi
     � �4. [17]http://www.scottklement.com/mailman/listinfo/ftpapi
     � �5. [18]http://www.partner400.com/
     � �6. [19]http://www.SystemiDeveloper.com/
     � �7. [20]http://www.scottklement.com/mailman/listinfo/ftpapi
     � �8. [21]http://www.scottklement.com/mailman/listinfo/ftpapi
     � �9. [22]http://www.mimecast.com/products/
     --------------------------------------------------------------------
     ---
     This is the FTPAPI mailing list.� To unsubscribe, please go to:
     [23]http://www.scottklement.com/mailman/listinfo/ftpapi
     --------------------------------------------------------------------
     ---

References

   1. mailto:elbert@xxxxxxxxxxxxxxx
   2. mailto:paul.roy@xxxxxxx
   3. mailto:rpglist@xxxxxxxxxxx
   4. mailto:ftpapi@xxxxxxxxxxxxxxxxxxxxxx
   5. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
   6. mailto:rpglist@xxxxxxxxxxx
   7. http://iprodeveloper.com/print/rpg-programming/rpgs-xml-sax-opco
   8. http://www.scottklement.com/mailman/listinfo/ftpapi
   9. http://www.scottklement.com/mailman/listinfo/ftpapi
  10. http://www.partner400.com/
  11. http://www.SystemiDeveloper.com/
  12. http://www.scottklement.com/mailman/listinfo/ftpapi
  13. http://www.scottklement.com/mailman/listinfo/ftpapi
  14. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
  15. http://iprodeveloper.com/print/rpg-programming/rpgs-xml-sax-opco
  16. http://www.scottklement.com/mailman/listinfo/ftpapi
  17. http://www.scottklement.com/mailman/listinfo/ftpapi
  18. http://www.partner400.com/
  19. http://www.SystemiDeveloper.com/
  20. http://www.scottklement.com/mailman/listinfo/ftpapi
  21. http://www.scottklement.com/mailman/listinfo/ftpapi
  22. http://www.mimecast.com/products/
  23. http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------