# parser xml - NAT8312

**URL:** <https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes, Natural-on-Windows-Unix\
**Created:** [July 10, 2007, 6:05pm UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002 "2007-07-10T18:05:37Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcos\_Voj](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Marcos\_Voj](https://techcommunity.softwareag.com/u/Marcos_Voj)\
**Post date:** [July 10, 2007, 6:05pm UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/1 "2007-07-10T18:05:37Z")

</div>

I

---

<div class="post-metadata">

**Author:** ![Weihnachtsbar](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/weihnachtsbar/32/146_2.png) [@Weihnachtsbar](https://techcommunity.softwareag.com/u/Weihnachtsbar)\
**Post date:** [July 10, 2007, 7:47pm UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/2 "2007-07-10T19:47:55Z")

</div>

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

> [@](#):
>
> {?xml version=“1.0” ?}

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

---

<div class="post-metadata">

**Author:** ![gtb](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@gtb](https://techcommunity.softwareag.com/u/gtb)\
**Post date:** [August 17, 2007, 1:34am UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/3 "2007-08-17T01:34:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Weihnachtsbar](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/weihnachtsbar/32/146_2.png) [@Weihnachtsbar](https://techcommunity.softwareag.com/u/Weihnachtsbar)\
**Post date:** [August 17, 2007, 11:24am UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/4 "2007-08-17T11:24:25Z")

</div>

:?: 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.

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [August 17, 2007, 11:33pm UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/5 "2007-08-17T23:33:30Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![gtb](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@gtb](https://techcommunity.softwareag.com/u/gtb)\
**Post date:** [August 21, 2007, 3:45am UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/6 "2007-08-21T03:45:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [August 21, 2007, 6:52am UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/7 "2007-08-21T06:52:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Weihnachtsbar](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/weihnachtsbar/32/146_2.png) [@Weihnachtsbar](https://techcommunity.softwareag.com/u/Weihnachtsbar)\
**Post date:** [August 21, 2007, 11:48am UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/8 "2007-08-21T11:48:53Z")

</div>

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

If it doesn’t work, my try this…

```auto
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:

```auto
MARCOS
```

---

<div class="post-metadata">

**Author:** ![gtb](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@gtb](https://techcommunity.softwareag.com/u/gtb)\
**Post date:** [August 21, 2007, 8:20pm UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/9 "2007-08-21T20:20:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Weihnachtsbar](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/weihnachtsbar/32/146_2.png) [@Weihnachtsbar](https://techcommunity.softwareag.com/u/Weihnachtsbar)\
**Post date:** [August 22, 2007, 11:59am UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/10 "2007-08-22T11:59:17Z")

</div>

> [@](#):
>
> Does UH represent unicode hexadecimal?

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

```auto
#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

> [@](#):
>
> Can you explain what it means that this particular code worked?

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

> [@](#):
>
> …and it worked. I got ‘marcos’.

Now try:

```auto
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 …

---

<div class="post-metadata">

**Author:** ![gtb](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@gtb](https://techcommunity.softwareag.com/u/gtb)\
**Post date:** [August 23, 2007, 12:08am UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/11 "2007-08-23T00:08:58Z")

</div>

thankyou Weihnachtsb

---

<div class="post-metadata">

**Author:** ![Weihnachtsbar](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/weihnachtsbar/32/146_2.png) [@Weihnachtsbar](https://techcommunity.softwareag.com/u/Weihnachtsbar)\
**Post date:** [August 23, 2007, 12:02pm UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/12 "2007-08-23T12:02:49Z")

</div>

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:

```auto
{?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](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 …

```auto
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 …

---

<div class="post-metadata">

**Author:** ![gtb](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@gtb](https://techcommunity.softwareag.com/u/gtb)\
**Post date:** [August 24, 2007, 3:24am UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/13 "2007-08-24T03:24:16Z")

</div>

Weihnachtsb

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [August 24, 2007, 4:20am UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/14 "2007-08-24T04:20:40Z")

</div>

For the 8304 error, check your XML profile settings, particularly the RDP\* subparameters that identify your proxy server:  
XML=(ON,RDP=‘[proxysrvr.mycorp.com](http://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

---

<div class="post-metadata">

**Author:** ![gtb](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@gtb](https://techcommunity.softwareag.com/u/gtb)\
**Post date:** [August 24, 2007, 7:20pm UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/15 "2007-08-24T19:20:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [August 24, 2007, 9:05pm UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/16 "2007-08-24T21:05:49Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:48pm UTC](https://techcommunity.softwareag.com/t/parser-xml-nat8312/75002/17 "2021-04-02T14:48:32Z")

</div>


