parse xml

My shop will soon be converting to Natural 4.2. I am currently using a test library, and trying to parse an .xml file. I am using a sample code that is used throughout the forum and natural help; very simple :roll:

I get this error: NAT8312 ‘Error during XML parser processing, reason 5: Unsupported encoding is used.’

Is there something perhaps in the installation/administration of 4.2 that needs to be added, or an object added to the STEPLIB (pre-processing) objects within the library where my program object resides?

Object code:


DEFINE DATA LOCAL                               
01 XML-DOC     (A) DYNAMIC                       
01 XML-DATA    (A) DYNAMIC                       
01 #XML-PATH  (A) DYNAMIC                       
01 #XML-NAME  (A) DYNAMIC                       
01 #XML-VALUE (A) DYNAMIC                       
END-DEFINE                                      
FORMAT LS=120 PS=40                             
XML-DOC := "C:\TEMP\TESTXML.XML"      
PERFORM W3READ-RESOURCE ' ' XML-DOC XML-DATA    
PARSE XML XML-DATA INTO PATH   #XML-PATH         
                                          NAME  #XML-NAME         
                                          VALUE #XML-VALUE        
DISPLAY #XML-PATH (AL=60)                       
              #XML-NAME (AL=15) 
              #XML-VALUE (AL=30) 
              *PARSE-TYPE
END-PARSE                                       
END                                             

Any help would be greatly appreciated.
thankyou, gtb

Not sure, but my guess is you have an HTML document, not an XML document. I ran into the same problem the first time I tried PARSE. XML rules are stricter than HTML rules.

I am not sure if it is distributed with 4.2, but you might see if there is a subprogram called WRITEXML , which is a misnomer since it accepts HTML, whereas PARSE does not.

steve

I don’t think that your example runs on MF at all:

PERFORM W3READ-RESOURCE 

is only available on not MF Naturals, e.g. Windows/Unix.

By the way

XML-DOC := "C:\TEMP\TESTXML.XML"     
PERFORM W3READ-RESOURCE ' ' XML-DOC XML-DATA

is not the correct way th use W3READ-RESOURCE. You should only read a resource document from a natural library. It is not a replacement for

DEFINE WORK FILE 12 #PATH TYPE "UNFORMATTED"
READ WORK FILE 12 XML-DATA 
END-WORK
CLOSE WORK 12

… even if it works (at the moment).
If you use the call outside the Web Interface context, it is useful, to add the optional error response parameter (I4) to trap possible error conditions. Otherwise a error page is automatically written, but it can only be seen within the Web Interface context.

Now some questions are open:

  • How does your real program and your real environment look like and where is it executed?
  • How does your xml look like - especially the xml header.

thankyou for the help… I will try all suggestions… this is something that was given to me to try… I did ask for assistance at a user’s group, but nobody had any experience with parse xml in natural…