parser xml - NAT8312

I

Your xml document is not valid, because a xml header is missing…

(don’t forget to replace the curly braces with less/greater sign)

I am using similar code to parse xml that Macros V. is using. I am receiving the same error, Nat8312, reason 5. My xml file is valid. I’ve used both (?xml version=“1.0” encoding=“ISO-8859-1” ?) & (?xml version=“1.0” ?) with less/greater sign.

What is missing? Has anyone successfully used parse xml on the mainframe?

:?: ISO-8859-1 on the MF?
Sure it works, if your characters inside your string are all real ASCII … after a REQUEST DOCUMENT for example.

:shock: I always thought MF uses code page names that sound like EBCDIC-US or EBCDIC-UK?

:idea: May you have a look at the *CODEPAGE system variable to see what your code page is supposed to be. Then check that your used character codes belong to this code page.

Here’s a piece of code that should work in any environment (I tested on mainframe and Windows):

DEFINE DATA LOCAL                                 
01 #XML (A) DYNAMIC                               
01 MYPATH (A) DYNAMIC                             
01 MYVALUE (A) DYNAMIC                            
END-DEFINE                                        
COMPRESS                                          
  '{?xml version="1.0" encoding="'                
  *CODEPAGE                                       
  '"?}'                                           
  '<Name>Marcos</Name>'                           
  INTO #XML LEAVING NO                            
*                                                
PARSE XML #XML INTO PATH MYPATH VALUE MYVALUE     
  DISPLAY (AL=39) MYPATH MYVALUE                  
END-PARSE                                         
END                                               

(replace the {} in the header with the appropriate <>)
Do be aware that if you are receiving documents (such as by the REQUEST DOCUMENT statement) from the internet, they will typically be in some ASCII variant (ISO-8859-1, etc). To view the received document on the mainframe, you need to add the ENCODED IN CODEPAGE ‘’ clause to your REQUEST DOCUMENT RETURN clause. However, if you then want to parse the received document (which will contain a header with encoding=“ISO-8859-1” (or whatever)), PARSE XML won’t accept it since the header shows ISO-8859-1 and the document is now in the mainframe codepage (ieg IBM01140). I leave out the “ENCODED” clause (so the XML document is in its native encoding such as ISO-8859-1) and process it with the PARSE XML statement, which will convert the INTO values into the target (mainframe) codepage. In case of an error, use the MOVE ENCODED statement to translate the returned document for display/debugging.

Obviously, there is something wrong or missing from my mainframe environment if I’m still getting an Error 8312, ‘reason 5’. I’m not a database manager, so I’m not familiar with any of the necessary utilities, files, or configurations for the environment.

I used the code that Douglas Kelly offered, and got the same error. I did a display on *CODEPAGE, and got ‘IBM01140’. I’ve never seen an encoding with
‘IBM01140’. By using ‘{?xml version=“1.0” encoding="’ *CODEPAGE ‘"?}’, it really is giving me an invalid xml document.

I would appreciate any other suggestions. I’ve almost given up on PARSE XML.

you did replace the curly braces “{” and “}” with less than “<”, greater than “>” signs from the example? I can’t put the proper header in the post as it get’s deleted…

IBM01140 is essentially EBCDIC, the code page for the IBM US mainframe.

What are your CFICU/NTCFICU parameters set to?

Did you try the version I suggested, without encoding inside the xml header?

If it doesn’t work, my try this…

DEFINE DATA LOCAL
1 #XML    (U) DYNAMIC
1 MYVALUE (A) DYNAMIC
END-DEFINE
#XML := UH'003C003F0078006D006C002000760065007200730069006F006E003D'-
  UH'00220031002E003000220020003F003E'-
  UH'003C004E0061006D0065003E004D006100720063006F0073003C002F004E0061'-
  UH'006D0065003E'
*
PARSE XML #XML INTO VALUE MYVALUE
  PRINT MYVALUE
END-PARSE
END

… to be sure that it works at all, response should be:

MARCOS

I am waiting for an answer from the database manager for the CFICU/NTCFICU parameters. I don’t know what routine to use to get those parameters, and the Help section isn’t much help.

I tried the code from Weihnachtsb

Yes. It has been a Unicode Hex constant.
The above the UH constants contain:

#XML := '{?xml version='-
  '"1.0" ?}'-
  '{Name}Marcos{/Na'-
  'me}'

Don’t forget to replace { } with < >

No. I haven’t typed the stuff…
The program editor of Natural for Windows knows three interesting shortcut keys:
CTRL+ALT+C Convert from hexadecimal to character format.
CTRL+ALT+U Convert characters of a text constant to hexadecimal Unicode representation.
CTRL+ALT+X Convert characters of a text constant to hexadecimal code page representation.
for more → see Natural Windows Online Help → Index → editor → shortcut keys

Ok. Your xml parser works - you run with a Unicode enabled Natural and the PARSE statement is available - and working.

Now try:

DEFINE DATA LOCAL
1 #XML    (A) DYNAMIC
1 MYVALUE (A) DYNAMIC
END-DEFINE
*
#XML := '<?xml version="1.0" ?>'-
  '<Name>Marcos</Name>'
*
EXAMINE #XML FOR '<' REPLACE WITH '<'
EXAMINE #XML FOR '>' REPLACE WITH '>'
*
PARSE XML #XML INTO VALUE MYVALUE
  PRINT MYVALUE
END-PARSE
END

and see what happens if we use just a (A) constant …

thankyou Weihnachtsb

The long version…
You are running a http server at your pc (IIS is most time available at a windows systems, I suppose you have, or can be installed from the Windows installation, but this is not my subject here - see Windows documentation for this - or use e.g. a Apache http server …)

Now you can find with IIS a directory C:\Inetpub\wwwroot at your pc.
Create there a empty myfirst.xml document at this directory.

Now open your NOTEPAD and write following xml document:

{?xml version="1.0" encoding="utf-8"?}
{mytag}No trick at all.{/mytag}

Don’t forget to replace { } with < >

Now open the “File → Save As” dialog
and specify for
“File name:” C:\Inetpub\wwwroot\myfirst.xml
“Encoding:” UTF-8
and then Save.

If you run your internet explorer and specify:
http://localhost/myfirst.xml
… and you should see the document.
No go to a different PC, again open the internet explorer and specify
http:///myfirst.xml
where is the name of your pc’s host name - may with the complete Primary Dns Suffix, as you can see if you call ipconfig /all from your Windows cmd.exe.
If you don’t see your page - your Windows firewall may block your page, or your host name / Primary Dns Suffix is wrong, or your http server does not run at the standard http port 80. May you have to ask your administrator to help your with this…

Now you can try is from your MF Natural …

DEFINE DATA LOCAL
1 #RESPONSE (B) DYNAMIC
1 #RESP (I4)
*
1 #VALUE (A) DYNAMIC
END-DEFINE
*
* replace <mypc> with of your pc's host name
REQUEST DOCUMENT FROM 'http://<mypc>/myfirst.xml'
  RETURN
    PAGE #RESPONSE
RESPONSE #RESP
*
IF #RESP = 200
  PARSE XML #RESPONSE INTO VALUE #VALUE
    PRINT #VALUE
  END-PARSE
ELSE
  PRINT 'http failed with:' #RESP
END-IF
END

If you get a http failed - see request documentation for the specific http error…

But you can also transfer your xml via RPC, or read it via work file or read it from your database or import to a work file via entire connection or … because Request Document has NOTHING to do with PARSE XML …

Weihnachtsb

For the 8304 error, check your XML profile settings, particularly the RDP* subparameters that identify your proxy server:
XML=(ON,RDP=‘proxysrvr.mycorp.com’,RDPPORT=8080,RDNOP=’*.mycorp.com’,
PARSE=ON,RDOC=ON)

  • RDP identifies your proxy server
  • RDPPORT is the port of the proxy server
  • RDNOP lists local address pattern(s) that should not go through the proxy server

thankyou for the info Mr. Kelly…

However, as programmers, we do not have access to most of the utilities, many of which I have come across while looking in the help section. When I look in the help section, it gives the example you just showed, but I do not know how to access XML profile settings information.

I will pass it on to the Database Manager, in hopes that he would know how to obtain this information.

you can supply it as a dynamic parameter (same as IM, ID, and other Natural profile parameters) - the syntax depends on your platform and where you are running Natural (CICS, TSO, COM-PLETE, batch).

For CICS, it is usually tran-id followed by parameters, eg:
NAT4 LS=80,XML=(ON,PARSE=ON)