Changeset 212 for trunk/src/helpers/xml.c
- Timestamp:
- Aug 22, 2002, 9:45:41 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/xml.c
r196 r212 3101 3101 3102 3102 /* 3103 *@@ ESCAPES: 3104 * 3105 *@@added V0.9.21 (2002-08-21) [umoeller] 3106 */ 3107 3108 typedef struct _ESCAPES 3109 { 3110 XSTRING strQuot1, // " 3111 strQuot2, // " 3112 strAmp1, // & 3113 strAmp2, // & 3114 strLT1, // < 3115 strLT2, // < 3116 strGT1, // > 3117 strGT2; // > 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 3129 VOID 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 /* 3103 3182 *@@ WriteNodes: 3104 3183 * internal helper for writing out the nodes. … … 3106 3185 * 3107 3186 *@@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 3108 3188 */ 3109 3189 3110 3190 static VOID WriteNodes(PXSTRING pxstr, 3191 PESCAPES pEscapes, 3111 3192 PDOMNODE pDomNode) // in: node whose children are to be written (initially DOCUMENT) 3112 3193 { … … 3143 3224 xstrcats(pxstr, &pAttribNode->NodeBase.strNodeName); 3144 3225 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); 3146 3237 xstrcatc(pxstr, '\"'); 3147 3238 } … … 3154 3245 3155 3246 // recurse into this child element 3156 WriteNodes(pxstr, p ChildNode);3247 WriteNodes(pxstr, pEscapes, pChildNode); 3157 3248 3158 3249 if (!fMixedContent) … … 3176 3267 case DOMNODE_COMMENT: 3177 3268 // 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); 3179 3276 break; 3180 3277 … … 3288 3385 else 3289 3386 { 3387 ESCAPES esc; 3388 3290 3389 // <?xml version="1.0" encoding="ISO-8859-1"?> 3291 3390 xstrcpy(pxstr, "<?xml version=\"1.0\" encoding=\"", 0); … … 3301 3400 } 3302 3401 3402 xstrInitCopy(&esc.strQuot1, "\"", 0); 3403 xstrInitCopy(&esc.strQuot2, """, 0); 3404 xstrInitCopy(&esc.strAmp1, "&", 0); 3405 xstrInitCopy(&esc.strAmp2, "&", 0); 3406 xstrInitCopy(&esc.strLT1, "<", 0); 3407 xstrInitCopy(&esc.strLT2, "<", 0); 3408 xstrInitCopy(&esc.strGT1, ">", 0); 3409 xstrInitCopy(&esc.strGT2, ">", 0); 3410 3411 xstrInit(&esc.strTemp, 0); // temp buffer 3412 3303 3413 // 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 3305 3426 3306 3427 xstrcatc(pxstr, '\n');
Note:
See TracChangeset
for help on using the changeset viewer.