-2

See original XML

i need to parse the XML after compare the previous row.Please take a look attached picture

Below are my progress 4GL query for parsing XML

DEFINE INPUT PARAMETER ipc_fileName AS CHARACTER.

DEFINE VARIABLE cSegmentName AS CHARACTER   NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE i661 AS INTEGER NO-UNDO.
DEFINE VARIABLE cInputData AS CHARACTER NO-UNDO.
DEFINE VARIABLE lv_c_Customer_Number AS INTEGER NO-UNDO.

INPUT FROM VALUE(ipc_FileName).
 IF cInputData = "" THEN NEXT.
    cSegmenTNAME = SUBSTRING(cInputData,1,3).     

CASE cSegmenTNAME :
        WHEN "661" THEN DO:
                 i = i + 1.
            IF LENGTH(cInputData) = 128 THEN DO:
                ASSIGN
                i661                 = i
                lv_c_Customer_Number = SUBSTRING(cInputData,6,9).
END.

Like wise I can parse every row but my doubt is how to parse row 663 if previous row starts with 664.

Any answers appreciated here.

Thiru
  • 231
  • 6
  • 20
  • Sounds to me like the simplest solution would be to read the data into a temp-table with some sort of sequence attribute on it and then parse the temp-table data. But that could of course be completely wrong because your problem definition is pretty poor. – jdpjamesp Dec 31 '18 at 17:10
  • You understand the point right?then why you getting me down sir? – Thiru Dec 31 '18 at 17:15
  • 1
    I cannot speak for James but I do not see anything about this question that seems to be related to parsing, XML, or writing a query. So, no, in my case anyway, I do not understand the point. You have provided a fragment of a code snippet that consists of syntactically incomplete and incorrect statements and which does nothing to illuminate the questions and doubts that you are raising. To improve the question you might start by showing an example of the actual source XML and the code that you are actually using to read it. – Tom Bascom Dec 31 '18 at 17:22
  • I have edited sir.Please take a look – Thiru Dec 31 '18 at 17:25
  • Any body can help this case please? – Thiru Jan 01 '19 at 11:53
  • Maybe you should rephrase your question. Your post doesn't make sense. It suggests it about XML but nowhere in your post there's any XML. – Bronco Oostermeyer Jan 01 '19 at 13:04
  • Reading between the lines I think this is an issue with the linear nature of xml parsing. The OP seems to only want to parse information on line x if line x-1 has certain criteria in it. That is my understanding at least. Hence my recommendation to make it a 2 pass parse - parse into temp tables or similar first and then parse the temp table which is able to be less linear. – jdpjamesp Jan 04 '19 at 09:29

1 Answers1

0

For parsing XML in Progress you have several options. Neither of those are used in your example.

Options:

DATASET and TEMP-TABLES can read (correctly formatted) XML.

Almost any XML can be read by a DATASET that represent the XML. This can be quite easy for simple XMLs. Temp-tables can directly read xml if that xml matches the representation of a temp-table. This isn't usually the case unless the xml indeed is a serialized temp-table.

Reading xml into datasets and temp-tables requires decent knowledge of datasets and temp-tables and how you can format those and adapt them using attributes like "serialize-name", "serialize-hidden" and so on.

Example from https://knowledgebase.progress.com/articles/Article/How-to-read-an-XML-in-a-temp-table-using-READ-XML:

DEFINE VARIABLE lcc AS LONGCHAR INIT "<A><B>Red</B><B>Green</B></A>". 

DEFINE TEMP-TABLE ttb SERIALIZE-NAME "B" 
    FIELD cc AS CHAR XML-NODE-TYPE "text". 

DEFINE DATASET dsa SERIALIZE-NAME "A" FOR ttb. 

DATASET dsa:READ-XML( "longchar", lcc, ?, ?, ? ). 

FOR EACH ttb: 
    MESSAGE ttb.cc VIEW-AS ALERT-BOX. 
END.

Document Object Model (X-DOCUMENT)

Using DOM you create an X-DOCUMENT object and it can read the xml. Then you will have a tree structure containing the XML-data. You will have to parse that yourself so be ready to walk the tree of nodes...

Example (copied from https://knowledgebase.progress.com/articles/Article/P21055):

The below code reads a file called personal.xml, processes all of its child nodes and displays information if the node name is "person":

/* e-attnam.p */
DEFINE VARIABLE hDoc AS HANDLE NO-UNDO.
DEFINE VARIABLE hRoot AS HANDLE NO-UNDO.
DEFINE VARIABLE good AS LOGICAL NO-UNDO.

CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.

hDoc:LOAD("file","personal.xml",TRUE).

hDoc:GET-DOCUMENT-ELEMENT(hRoot).

RUN GetChildren(hRoot, 1).

DELETE OBJECT hDoc.
DELETE OBJECT hRoot.

PROCEDURE GetChildren:
DEFINE INPUT PARAMETER hParent AS HANDLE NO-UNDO.
DEFINE INPUT PARAMETER level AS INTEGER NO-UNDO.

DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE hNoderef AS HANDLE NO-UNDO.

CREATE X-NODEREF hNoderef.

REPEAT i = 1 TO hParent:NUM-CHILDREN:
   good = hParent:GET-CHILD(hNoderef,i).
   IF NOT good THEN
LEAVE.
   IF hNoderef:SUBTYPE <> "element" THEN
NEXT.
   IF hNoderef:NAME = "person" THEN
       MESSAGE "getattr id gives" hNoderef:GET-ATTRIBUTE("id") hNoderef:ATTRIBUTE-NAMES.
   RUN GetChildren(hNoderef, (level + 1)).
END.

DELETE OBJECT hNoderef.
END PROCEDURE.

Simple API for XML (SAX)

This is perhaps a more lightweight approach to XML. You will have to write code that "reacts" the the presence of certain nodes in the XML.

Example can be found at https://knowledgebase.progress.com/articles/Article/000035469

For all things XML and Progress: https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvxml%2Fpreface.html%23

Jensd
  • 7,886
  • 2
  • 28
  • 37