Ignore:
Timestamp:
Aug 22, 2002, 9:45:41 PM (23 years ago)
Author:
umoeller
Message:

Misc changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/xml.c

    r196 r212  
    31013101
    31023102/*
     3103 *@@ ESCAPES:
     3104 *
     3105 *@@added V0.9.21 (2002-08-21) [umoeller]
     3106 */
     3107
     3108typedef struct _ESCAPES
     3109{
     3110    XSTRING strQuot1,       // "
     3111            strQuot2,       // "
     3112            strAmp1,        // &
     3113            strAmp2,        // &
     3114            strLT1,         // <
     3115            strLT2,         // &lt;
     3116            strGT1,         // >
     3117            strGT2;         // &gt;
     3118
     3119    XSTRING strTemp;        // temp buffer
     3120
     3121} ESCAPES, *PESCAPES;
     3122
     3123/*
     3124 *@@ DoEscapes:
     3125 *
     3126 *@@added V0.9.21 (2002-08-21) [umoeller]
     3127 */
     3128
     3129VOID DoEscapes(PESCAPES pEscapes,
     3130               BOOL fQuotesToo)
     3131{
     3132    ULONG   ulOfs;
     3133    size_t  ShiftTable[256];
     3134    BOOL    fRepeat;
     3135
     3136    if (fQuotesToo)
     3137    {
     3138        ulOfs = 0;
     3139        fRepeat = FALSE;
     3140        while (xstrFindReplace(&pEscapes->strTemp,
     3141                               &ulOfs,
     3142                               &pEscapes->strQuot1,
     3143                               &pEscapes->strQuot2,
     3144                               ShiftTable,
     3145                               &fRepeat))
     3146            ;
     3147    }
     3148
     3149    ulOfs = 0;
     3150    fRepeat = FALSE;
     3151    while (xstrFindReplace(&pEscapes->strTemp,
     3152                           &ulOfs,
     3153                           &pEscapes->strLT1,
     3154                           &pEscapes->strLT2,
     3155                           ShiftTable,
     3156                           &fRepeat))
     3157        ;
     3158
     3159    ulOfs = 0;
     3160    fRepeat = FALSE;
     3161    while (xstrFindReplace(&pEscapes->strTemp,
     3162                           &ulOfs,
     3163                           &pEscapes->strGT1,
     3164                           &pEscapes->strGT2,
     3165                           ShiftTable,
     3166                           &fRepeat))
     3167        ;
     3168
     3169    // replace ampersands last
     3170    ulOfs = 0;
     3171    fRepeat = FALSE;
     3172    while (xstrFindReplace(&pEscapes->strTemp,
     3173                           &ulOfs,
     3174                           &pEscapes->strAmp1,
     3175                           &pEscapes->strAmp2,
     3176                           ShiftTable,
     3177                           &fRepeat))
     3178        ;
     3179}
     3180
     3181/*
    31033182 *@@ WriteNodes:
    31043183 *      internal helper for writing out the nodes.
     
    31063185 *
    31073186 *@@added V0.9.12 (2001-05-21) [umoeller]
     3187 *@@changed V0.9.21 (2002-08-21) [umoeller]: changed prototype, fixed unescaped characters in attributes and content
    31083188 */
    31093189
    31103190static VOID WriteNodes(PXSTRING pxstr,
     3191                       PESCAPES pEscapes,
    31113192                       PDOMNODE pDomNode)       // in: node whose children are to be written (initially DOCUMENT)
    31123193{
     
    31433224                    xstrcats(pxstr, &pAttribNode->NodeBase.strNodeName);
    31443225                    xstrcat(pxstr, "=\"", 0);
    3145                     xstrcats(pxstr, pAttribNode->pstrNodeValue);
     3226
     3227                    // copy attribute value to temp buffer first
     3228                    // so we can escape quotes and ampersands
     3229                    // V0.9.21 (2002-08-21) [umoeller]
     3230                    xstrcpys(&pEscapes->strTemp, pAttribNode->pstrNodeValue);
     3231
     3232                    DoEscapes(pEscapes,
     3233                              TRUE);        // quotes too
     3234
     3235                    // alright, use that
     3236                    xstrcats(pxstr, &pEscapes->strTemp);
    31463237                    xstrcatc(pxstr, '\"');
    31473238                }
     
    31543245
    31553246                    // recurse into this child element
    3156                     WriteNodes(pxstr, pChildNode);
     3247                    WriteNodes(pxstr, pEscapes, pChildNode);
    31573248
    31583249                    if (!fMixedContent)
     
    31763267            case DOMNODE_COMMENT:
    31773268                // that's simple
    3178                 xstrcats(pxstr, pChildNode->pstrNodeValue);
     3269                xstrcpys(&pEscapes->strTemp,
     3270                         pChildNode->pstrNodeValue);
     3271
     3272                DoEscapes(pEscapes,         // V0.9.21 (2002-08-21) [umoeller]
     3273                          FALSE);           // quotes not
     3274
     3275                xstrcats(pxstr, &pEscapes->strTemp);
    31793276            break;
    31803277
     
    32883385    else
    32893386    {
     3387        ESCAPES esc;
     3388
    32903389        // <?xml version="1.0" encoding="ISO-8859-1"?>
    32913390        xstrcpy(pxstr, "<?xml version=\"1.0\" encoding=\"", 0);
     
    33013400        }
    33023401
     3402        xstrInitCopy(&esc.strQuot1, "\"", 0);
     3403        xstrInitCopy(&esc.strQuot2, "&quot;", 0);
     3404        xstrInitCopy(&esc.strAmp1, "&", 0);
     3405        xstrInitCopy(&esc.strAmp2, "&amp;", 0);
     3406        xstrInitCopy(&esc.strLT1, "<", 0);
     3407        xstrInitCopy(&esc.strLT2, "&lt;", 0);
     3408        xstrInitCopy(&esc.strGT1, ">", 0);
     3409        xstrInitCopy(&esc.strGT2, "&gt;", 0);
     3410
     3411        xstrInit(&esc.strTemp, 0);       // temp buffer
     3412
    33033413        // write out children
    3304         WriteNodes(pxstr, (PDOMNODE)pDocument);
     3414        WriteNodes(pxstr, &esc, (PDOMNODE)pDocument);
     3415
     3416        xstrClear(&esc.strQuot1);
     3417        xstrClear(&esc.strQuot2);
     3418        xstrClear(&esc.strAmp1);
     3419        xstrClear(&esc.strAmp2);
     3420        xstrClear(&esc.strLT1);
     3421        xstrClear(&esc.strLT2);
     3422        xstrClear(&esc.strGT1);
     3423        xstrClear(&esc.strGT2);
     3424
     3425        xstrClear(&esc.strTemp);       // temp buffer
    33053426
    33063427        xstrcatc(pxstr, '\n');
Note: See TracChangeset for help on using the changeset viewer.