Blog Archive

iSeries XML parsing error RNX0351 - The XML parser detected error code 6

How to resolve XML parsing error RNX0351? While parsing an XML document for an RPG procedure, the parser detected an error at offset .. with reason code 6

Well in this case I received an XML from Amazon into the IFS. And when I tried to parse this using the RPGLE SAX parser the Buyer name element had some special character causing it to fail. After quite a bit of research found that you have modify the CCSID of the XML file in IFS. The CCSID of my XML file was 819 and I had to change that to 1208. This method worked for most of my XML files but not all. You can look at the ccsid=ucs2 feature to figure it out. I haven't tried this yet.
XML = %trim(filePath);                           
xml-sax %handler(mySaxHandler: ignoreMe)         
        %XML(XML: 'doc=file ccsid=ucs2');    

How to catch RNX0351 error during XML SAX parsing

monitor;                                   
                                           
  //Error Checking only                    
  xml-sax %handler(mySaxHandler: ignoreMe) 
          %XML(XML: 'doc=file');            
on-error 00351;                                      
                                                     
  ErrorEmail($fileName:$path);                       
  @CmdStr = 'MOV OBJ(' + @Apostr +                   
            %trim($filePath) + @Apostr +             
            ') TOOBJ(' + @Apostr +                   
            %trim($errorPath) + @Apostr + ')';       
  ExcCmd(%Trim(@CmdStr) :                            
        %Len(%Trim(@CmdStr)));                       
                                                     
endmon;     

How to change CCSID in a CLP Program

CHGATR OBJ(filePath) ATR(*CCSID) VALUE(1208)

How to change CCSID in a RPGLE Program

 *   Execute A Command                                          
d ExcCmd          PR                  ExtPgm('QCMDEXC')         
d  Cmd_Str                     512a   Options(*VARSIZE)         
d                                     Const                     
d  Cmd_Len                      15p 5 Const         
    
d @Apostr         s              1a   inz(X'7D')             

@CmdStr = 'CHGATR  OBJ(' + @Apostr + %trim(filePath) +      
           @Apostr + ') ATR(*CCSID) VALUE(1208)';           
ExcCmd(%Trim(@CmdStr) :                                     
      %Len(%Trim(@CmdStr)));          

XML Parser Error Codes

If the XML parser detects an error in the XML document during parsing, message RNX0351 will be issued. From the message, you can get the specific error code associated with the error, as well as the offset in the document where the error was discovered.

The following table shows the meaning of each parser error code:

XML Parser Error Code Description
1 The parser found an invalid character while scanning white space outside element content.
2 The parser found an invalid start of a processing instruction, element, comment, or document type declaration outside element content.
3 The parser found a duplicate attribute name.
4 The parser found the markup character '<' in an attribute value.
5 The start and end tag names of an element did not match.
6 The parser found an invalid character in element content.
7 The parser found an invalid start of an element, comment, processing instruction, or CDATA section in element content.
8 The parser found in element content the CDATA closing character sequence ']]>' without the matching opening character sequence '<![CDATA['.
9 The parser found an invalid character in a comment.
10 The parser found in a comment the character sequence '--' (two hyphens) not followed by '>'.
11 The parser found an invalid character in a processing instruction data segment.
12 A processing instruction target name was 'xml' in lowercase, uppercase or mixed case.
13 The parser found an invalid digit in a hexadecimal character reference (of the form &#xdddd;, for example &#x0eb1).
14 The parser found an invalid digit in a decimal character reference (of the form &#dddd;).
15 A character reference did not refer to a legal XML character.
16 The parser found an invalid character in an entity reference name.
17 The parser found an invalid character in an attribute value.
18 The parser found a possible invalid start of a document type declaration.
19 The parser found a second document type declaration.
20 An element name was not specified correctly. The first character was not a letter, '_', or ':', or the parser found an invalid character either in or following the element name.
21 An attribute was not specified correctly. The first character of the attribute name was not a letter, '_', or ':', or a character other than '=' was found following the attribute name, or one of the delimiters of the value was not correct, or an invalid character was found in or following the name.
22 An empty element tag was not terminated by a '>' following the '/'.
23 The element end tag was not specified correctly. The first character was not a letter, '_', or ':', or the tag was not terminated by '>'.
24 The parser found an invalid start of a comment or CDATA section in element content.
25 A processing instruction target name was not specified correctly. The first character of the processing instruction target name was not a letter, '_', or ':', or the parser found an invalid character in or following the processing instruction target name.
26 A processing instruction was not terminated by the closing character sequence '?>'.
27 The parser found an invalid character following '&' in a character reference or entity reference.
28 The version information was not present in the XML declaration.
29 The 'version' in the XML declaration was not specified correctly. 'version' was not followed by '=', or the value was missing or improperly delimited, or the value specified a bad character, or the start and end delimiters did not match, or the parser found an invalid character following the version information value closing delimiter in the XML declaration.
30 The parser found an invalid attribute instead of the optional encoding declaration in the XML declaration.
31 The encoding declaration value in the XML declaration was missing or incorrect. The value did not begin with lowercase or uppercase A through Z, or 'encoding' was not followed by '=', or the value was missing or improperly delimited or it specified a bad character, or the start and end delimiters did not match, or the parser found an invalid character following the closing delimiter.
32 The parser found an invalid attribute instead of the optional standalone declaration in the XML declaration.
33 The 'standalone' attribute in the XML declaration was not specified correctly. 'standalone' was not followed by a '=', or the value was either missing or improperly delimited, or the value was neither 'yes' nor 'no', or the value specified a bad character, or the start and end delimiters did not match, or the parser found an invalid character following the closing delimiter.
34 The XML declaration was not terminated by the proper character sequence '?>', or contained an invalid attribute.
35 The parser found the start of a document type declaration after the end of the root element.
36 The parser found the start of an element after the end of the root element.
300 The parser reached the end of the document before the document was complete.
301 The %HANDLER procedure for XML-INTO or XML-SAX returned a non-zero value, causing the XML parsing to end.
302 The parser does not support the requested CCSID value or the first character of the XML document was not '<'.
303 The document was too large for the parser to handle. The parser attempted to parse the incomplete document, but the data at the end of the document was necessary for the parsing to complete.
500-999 Internal error in the external parser. Please report the error to your service representative.
10001-19999 Internal error in the parser. Please report the error to your service representative.

CCSID Limitations of the XML Parser

The parser does not support every CCSID. If your job CCSID is one of the CCSIDs that the parser does not handle, you must parse your document in UCS-2.

  • The following EBCDIC CCSIDs are supported: 1047, 37, 1140, 273, 1141, 277, 1142, 278, 1143, 280, 1144, 284, 1145, 285, 1146, 297, 1147, 500, 1148, 871, and 1149.
  • The following ASCII CCSIDs are supported: 819, 813, 920.
  • The following Unicode CCSIDs are supported: 1200, 13488, 17584.