XmlParseError class: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
<!-- XmlParseError class --> | <!-- XmlParseError class --> | ||
__NOTOC__ | __NOTOC__ | ||
The XmlParseError exception class catches parsing errors (including syntax, translation, and encoding errors) thrown by the deserialization methods: <var>[[LoadXml_(XmlDoc/XmlNode_function)|LoadXml]]</var> and <var>[[WebReceive_(XmlDoc_function)|WebReceive]]</var> of the <var class="product"> | The XmlParseError exception class catches parsing errors (including syntax, translation, and encoding errors) thrown by the deserialization methods: <var>[[LoadXml_(XmlDoc/XmlNode_function)|LoadXml]]</var> and <var>[[WebReceive_(XmlDoc_function)|WebReceive]]</var> of the <var class="product">Janus SOAP</var> <var>[[XmlDoc_API]]</var>, and the <var>[[ParseXml]]</var> method of the <var>[[HttpResponse]]</var> class. | ||
This class is available as of <var class="product">[[Sirius Mods]]</var> Version 7.6. | This class is available as of <var class="product">[[Sirius Mods]]</var> Version 7.6. | ||
Line 21: | Line 21: | ||
This <var>[[Classes and Objects#readWrite|ReadOnly]]</var> property returns a number that indicates the position within the input character stream (starting with 1) at or before which the error was detected. | This <var>[[Classes and Objects#readWrite|ReadOnly]]</var> property returns a number that indicates the position within the input character stream (starting with 1) at or before which the error was detected. | ||
<h4>Syntax</h4> | |||
{{Template:XmlParseError:CharacterPosition syntax}} | {{Template:XmlParseError:CharacterPosition syntax}} | ||
<h4>Syntax terms</h4> | |||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%number</th> | <tr><th>%number</th> | ||
Line 32: | Line 32: | ||
</table> | </table> | ||
<h4>Usage notes</h4> | |||
<ul> | <ul> | ||
<li>The number of bytes that constitute a character depends on the type of string that causes the exception: | <li>The number of bytes that constitute a character depends on the type of string that causes the exception: | ||
Line 51: | Line 51: | ||
Each argument to <var>New</var> sets the value of the corresponding property of the newly constructed <var>XmlParseError</var> object. | Each argument to <var>New</var> sets the value of the corresponding property of the newly constructed <var>XmlParseError</var> object. | ||
<h4>Syntax</h4> | |||
{{Template:XmlParseError:New syntax}} | {{Template:XmlParseError:New syntax}} | ||
<h4>Syntax terms</h4> | |||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>xmlParsError</th> | <tr><th>xmlParsError</th> | ||
Line 80: | Line 80: | ||
This <var>[[Classes and Objects#readWrite|ReadOnly]]</var> property returns a string that contains a brief description of the exception. | This <var>[[Classes and Objects#readWrite|ReadOnly]]</var> property returns a string that contains a brief description of the exception. | ||
<h4>Syntax</h4> | |||
{{Template:XmlParseError:Description syntax}} | {{Template:XmlParseError:Description syntax}} | ||
<h4>Syntax terms</h4> | |||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%string</th> | <tr><th>%string</th> | ||
Line 97: | Line 97: | ||
{{Template:XmlParseError:InputHexValue subtitle}} | {{Template:XmlParseError:InputHexValue subtitle}} | ||
This <var> | This <var>ReadOnly</var> property returns a string that contains the hexadecimal representation of the bytes that caused the exception to be thrown. | ||
<var>InputHexvalue</var> returns a value for all [[Reason (XmlParseError property)|reasons]] except <var>SyntaxError</var>. | <var>InputHexvalue</var> returns a value for all [[Reason (XmlParseError property)|reasons]] except <var>SyntaxError</var>. | ||
<h4>Syntax</h4> | |||
{{Template:XmlParseError:InputHexValue syntax}} | {{Template:XmlParseError:InputHexValue syntax}} | ||
<h4>Syntax terms</h4> | |||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%string</th> | <tr><th>%string</th> | ||
Line 116: | Line 116: | ||
{{Template:XmlParseError:Reason subtitle}} | {{Template:XmlParseError:Reason subtitle}} | ||
This <var> | This <var>ReadOnly</var> property returns an <var>XmlParseErrorReason</var> enumeration value that describes the error that caused the <var>[[XmlParseError_class|XmlParseError]]</var> exception. | ||
<h4>Syntax</h4> | |||
{{Template:XmlParseError:Reason syntax}} | {{Template:XmlParseError:Reason syntax}} | ||
<h4>Syntax terms</h4> | |||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%reason</th> | <tr><th>%reason</th> | ||
Line 130: | Line 130: | ||
</table> | </table> | ||
<h4>Usage notes</h4> | |||
<ul> | <ul> | ||
<li>An <var>XmlParseErrorReason</var> enumeration may have one of the following values, each of which is demonstrated in the [[#Example|examples]] below. | <li>An <var>XmlParseErrorReason</var> enumeration may have one of the following values, each of which is demonstrated in the [[#Example|examples]] below. | ||
Line 153: | Line 153: | ||
</ul> | </ul> | ||
<h4>Example</h4> | |||
The following template is used to apply the <var>[[LoadXml_(XmlDoc/XmlNode_function)|LoadXml]]</var> deserialization method to a series of test ''input-string'' values to demonstrate the <var>XmlParseError</var> exception output: | The following template is used to apply the <var>[[LoadXml_(XmlDoc/XmlNode_function)|LoadXml]]</var> deserialization method to a series of test ''input-string'' values to demonstrate the <var>XmlParseError</var> exception output: | ||
<p class="code"> [[try]] | <p class="code"> [[try]] | ||
Line 191: | Line 191: | ||
</p> | </p> | ||
<li>When called with: | <li>When called with: | ||
<p class="code"> '''%d:LoadXml('<a>&#x2122;</a>':U)''' | <p class="code"> '''%d:LoadXml('<a>&#x2122;</a>':[[U (String function)|U]])''' | ||
</p> | </p> | ||
The results are: | The results are: | ||
Line 204: | Line 204: | ||
</p> | </p> | ||
<li>When called with: | <li>When called with: | ||
<p class="code"> '''%d:LoadXml('FEFF003C33':X)''' | <p class="code"> '''%d:LoadXml('FEFF003C33':[[X (String function)|X]])''' | ||
</p> | </p> | ||
The results are: | The results are: |
Revision as of 15:56, 11 May 2011
The XmlParseError exception class catches parsing errors (including syntax, translation, and encoding errors) thrown by the deserialization methods: LoadXml and WebReceive of the Janus SOAP XmlDoc_API, and the ParseXml method of the HttpResponse class.
This class is available as of Sirius Mods Version 7.6.
The XmlParseError methods
The following are the available XmlParseError class methods.
Method | Description |
---|---|
CharacterPosition | Position of character at of before which the error occurred |
Description | Brief description of the exception |
InputHexValue | Hexadecimal value of bytes causing the exception |
New | Create a new XmlParseError object |
Reason | Enumerated cause of the exception |
The methods in the class are described in the subsections that follow. In addition:
- "Notation conventions for methods" has information about the conventions followed.
- "XmlParseError methods syntax" is a single page that contains the syntax diagrams of all the methods in the class.
CharacterPosition property
Position of character at of before which the error occurred (XmlParseError class)
This ReadOnly property returns a number that indicates the position within the input character stream (starting with 1) at or before which the error was detected.
Syntax
%number = xmlParseError:CharacterPosition
Syntax terms
%number | The position at or before which the error was detected. |
---|---|
xmlParsError | A reference to an instance of an XmlParseError object. |
Usage notes
- The number of bytes that constitute a character depends on the type of string that causes the exception:
- If EBCDIC, one byte corresponds to one character.
- If Unicode, two bytes correspond to one character.
- If UTF-16, two bytes correspond to one character.
- If UTF-8, the relationship between bytes and characters is variable, depending on the code points.
New constructor
Create a new XmlParseError object (XmlParseError class)
This constructor generates an instance of an XmlParseError exception. As shown in the syntax that follows, the New method arguments set the values of the class properties that have the corresponding names.
Each argument to New sets the value of the corresponding property of the newly constructed XmlParseError object.
Syntax
%xmlParseError = [%(XmlParseError):]New( Reason= xmlParseErrorReason, - [CharacterPosition= number], - [Description= string], - [InputHexValue= string])
Syntax terms
xmlParsError | A reference to an instance of a XmlParseError object. |
---|---|
%(XmlParseError) | The class name in parentheses denotes a shared method. |
Reason | This name required parameter specifies the value to be assigned to the exception object's Reason property.
Reason settings are XmlParseErrorReason enumeration values, which are described below in "Reason property". The Reason parameter is not optional. |
CharacterPosition | This optional, but name required, parameter specifies the numeric value (number) to be assigned to the object's CharacterPosition property. Its default value is 0. |
Description | This optional, but name required, parameter specifies the string value (string) to be assigned to the object's Description property. Its default value is a null string. |
InputHexValue | This optional, but name required, parameter specifies the string value (string) to be assigned to the object's InputHexValue property. Its default value is a null string. |
Description property
Brief description of the exception (XmlParseError class)
This ReadOnly property returns a string that contains a brief description of the exception.
Syntax
%string = xmlParseError:Description
Syntax terms
%string | A string to receive the description of the exception. |
---|---|
xmlParsError | A reference to an instance of a XmlParseError object. |
InputHexValue property
Hexadecimal value of bytes causing the exception (XmlParseError class)
This ReadOnly property returns a string that contains the hexadecimal representation of the bytes that caused the exception to be thrown.
InputHexvalue returns a value for all reasons except SyntaxError.
Syntax
%string = xmlParseError:InputHexValue
Syntax terms
%string | A string to receive the hexadecimal value of the bytes that caused the exception to be thrown. |
---|---|
xmlParsError | A reference to an instance of a XmlParseError object. |
Reason property
Enumerated cause of the exception (XmlParseError class)
This ReadOnly property returns an XmlParseErrorReason enumeration value that describes the error that caused the XmlParseError exception.
Syntax
%xmlParseErrorReason = xmlParseError:Reason
Syntax terms
%reason | This XmlParseErrorReason enumeration value describes the parsing error. |
---|---|
xmlParsError | A reference to an instance of a XmlParseError object. |
Usage notes
- An XmlParseErrorReason enumeration may have one of the following values, each of which is demonstrated in the examples below.
- InvalidUnicodeCharacter
- The Unicode input contains an invalid character.
- InvalidUTF8Encoding
- The input UTF8 stream is invalid.
- InvalidUTF16Encoding
- The input UTF16 stream is invalid.
- SyntaxError
- A violation of the syntax of an XML document.
- UntranslatableEBCDIC
- The EBCDIC input contains a character that is not translatable to Unicode.
- UntranslatableISOn
- The ISO-8859-n input contains a character that is not translatable to Unicode.
- UntranslatableUnicode
- The Unicode input contains a character that is not translatable to EBCDIC.
This exception can be avoided using the
AllowUntranslatable
option of the deserialization method.
Example
The following template is used to apply the LoadXml deserialization method to a series of test input-string values to demonstrate the XmlParseError exception output:
try printText {~}: {%d:LoadXml(input-string)} catch XmlParseError to %err print ' ' print 'Error Reason:' And %err:Reason:ToString print 'Error Description:' And %err:Description print 'Error Character Position:' And %err:CharacterPosition print 'Error Input Hex Value:' And %err:InputHexValue print ' - - -' end try
- When called with:
%d:LoadXml('<a>'):
The results are:
Error Reason: SyntaxError Error Description: XML doc parse error: missing ETag for top level element near or before position 4 (end of input) Error Character Position: 4 Error Input Hex Value: - - -
- When called with:
%d:LoadXml('<' With 'FF':X With '>')
The results are:
Error Reason: UntranslatableEBCDIC Error Description: XML doc parse error: EBCDIC character not translatable to Unicode near or before position 3 Error Character Position: 3 Error Input Hex Value: FF - - -
- When called with:
%d:LoadXml('<a>™</a>':U)
The results are:
Error Reason: UntranslatableUnicode Error Description: XML doc parse error: invalid Unicode character - not translatable to EBCDIC near or before position 5 Error Character Position: 5 Error Input Hex Value: 2122 - - -
- When called with:
%d:LoadXml('FEFF003C33':X)
The results are:
Error Reason: InvalidUTF16Encoding Error Description: XML doc parse error: expecting additional byte of UTF-16 encoding near or before position 2 (end of input) Error Character Position: 2 Error Input Hex Value: 33 - - -
- When called with:
%d:LoadXml('FEFFD800':X)
The results are:
Error Reason: InvalidUnicodeCharacter Error Description: XML doc parse error: surrogate point in UTF-16 input near or before position 1 Error Character Position: 1 Error Input Hex Value: D800 - - -
- When called with:
%d:LoadXml('C181':X)
The results are:
Error Reason: InvalidUTF8Encoding Error Description: XML doc parse error: byte 1 of 2 too low in UTF-8 encoding near or before position 2 Error Character Position: 2 Error Input Hex Value: C181 - - -
- When called with:
%d:LoadXml('FF818256':X)
The results are:
Error Reason: InvalidUTF8Encoding Error Description: XML doc parse error: attempt to use 4-byte UTF-8 encoding of surrogate point near or before position 2 Error Character Position: 2 Error Input Hex Value: FF - - -
- When called with:
%d:LoadXml('EDA080':X)
The results are:
Error Reason: InvalidUnicodeCharacter Error Description: XML doc parse error: invalid Unicode character (surrogate range) near or before position 2 Error Character Position: 2 Error Input Hex Value: EDA080 - - -