METHOD PROTECTED CHARACTER stringToXSD (
INPUT pcString AS CHARACTER, /* String value */
INPUT pcProviderIdSymbol AS CHARACTER, /* Identification symbol of the provider */
OUTPUT plModified AS LOGICAL ): /* Flag indicating that the string was modified */
/*------------------------------------------------------------------------------
Purpose: Properly format the given string value to conform with XML XSD
Notes: In another words, strip off or convert unwanted characters which
should not be present using ISO 8859-1 (Latin-1 / Western European)
encoding, e.g. ASCII. But since this logic is very expensive we only
want to do the full blown check if absouletly necessary. Therefore
we check the provider identification symbol to decide what check we
do.
------------------------------------------------------------------------------*/
&SCOPED-DEFINE ASCII-CODE '192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,216,217,218,219,220,221,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,248,249,250,251,252,253,255':U
&SCOPED-DEFINE ASCII-CHAR 'A,A,A,A,AE,A,AE,C,E,E,E,E,I,I,I,I,D,N,O,O,O,O,OE,O,U,U,U,UE,Y,ss,a,a,a,a,ae,a,ae,c,e,e,e,e,i,i,i,i,d,n,o,o,o,o,oe,o,u,u,u,ue,y,y':U
DEFINE VARIABLE cErrorMessage AS CHARACTER NO-UNDO.
DEFINE VARIABLE cString AS CHARACTER NO-UNDO.
DEFINE VARIABLE cCharacter AS CHARACTER NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.
DEFINE VARIABLE iPosition AS INTEGER NO-UNDO.
DEFINE VARIABLE iASCIICode AS INTEGER NO-UNDO.
STRING-TO-XSD-BLK:
DO ON ERROR UNDO STRING-TO-XSD-BLK, LEAVE STRING-TO-XSD-BLK:
/* Faulty characters should only be present in attributes which have been delivered from providers
other than Telekurs ... */
IF pcProviderIdSymbol <> 'TK':U THEN do:
DO iLoop = 1 TO LENGTH ( pcString ):
ASSIGN cCharacter = SUBSTRING ( pcString, iLoop, 1 )
iASCIICode = ASC ( cCharacter )
iPosition = LOOKUP ( STRING ( iASCIICode ), {&ASCII-CODE} ).
/* Replace CR/LF with blank ... */
IF iASCIICode = 10 THEN
ASSIGN cString = cString + ' ':U.
/* Standard ASCII characters (32 - 126) */
ELSE IF iASCIICode >= 32 AND iASCIICode <= 126 THEN
ASSIGN cString = cString + cCharacter.
/* Some special characters converted into similar ASCII characters */
ELSE IF iPosition > 0 THEN
ASSIGN cString = cString + ENTRY ( iPosition, {&ASCII-CHAR} )
plModified = TRUE.
/* Skip the rest ... */
ELSE
ASSIGN plModified = TRUE.
END.
END. /* Expensive check */
/* No work request - inexpensive check */
ELSE DO:
ASSIGN plModified = FALSE
cString = REPLACE ( pcString, CHR(10), ' ':U ).
END.
/* Error handling */
CATCH oAnyError AS Progress.Lang.Error:
{&BEGIN-CATCH-ANY-ERROR}
ASSIGN cErrorMessage = 'Unhandled exception formatting string value according to XSD [' + cErrorMessage + '].'
cString = ''.
{&END-CATCH-ANY-ERROR}
END CATCH.
END. /* STRING-TO-XSD-BLK */
RETURN cString.
&UNDEFINE ASCII-CODE
&UNDEFINE ASCII-CHAR
END METHOD.