|
1 | 1 | (******************************************************************************)
|
2 | 2 | (* uDomXML 07.10.2016 *)
|
3 | 3 | (* *)
|
4 |
| -(* Version : 0.09 *) |
| 4 | +(* Version : 0.10 *) |
5 | 5 | (* *)
|
6 | 6 | (* Author : Uwe Schächterle (Corpsman) *)
|
7 | 7 | (* *)
|
|
32 | 32 | (* 0.07 - ExpandEmptyNodes *)
|
33 | 33 | (* 0.08 - Erste implementierung zu "escaping" *)
|
34 | 34 | (* 0.09 - generisches AddChild für TDomnode *)
|
| 35 | +(* 0.10 - FIX scan for invalid characters in Attributes *) |
35 | 36 | (* *)
|
36 | 37 | (* Known Bugs : -Unsinnige Fehlermeldung wenn gar keine gültige xml Datei *)
|
37 | 38 | (* geparst werden soll. *)
|
|
171 | 172 | result := StringReplace(result, '&', '&', [rfReplaceAll]);
|
172 | 173 | End;
|
173 | 174 |
|
| 175 | +(* |
| 176 | + * Konvertiert einen String in einen String der in einem XML-Attribut stehen darf |
| 177 | + * & -> & , ... |
| 178 | + *) |
| 179 | + |
| 180 | +Function StringToXMLAttributeString(Value: String): String; |
| 181 | +Begin |
| 182 | + result := value; |
| 183 | + result := StringReplace(result, '&', '&', [rfReplaceAll]); |
| 184 | + result := StringReplace(result, '<', '<', [rfReplaceAll]); |
| 185 | + result := StringReplace(result, '"', '"', [rfReplaceAll]); |
| 186 | +End; |
| 187 | + |
| 188 | +(* |
| 189 | + * Umkehrfunktion zu StringToXMLAttributeString |
| 190 | + *) |
| 191 | + |
| 192 | +Function XMLAttributeStringToString(Value: String): String; |
| 193 | +Begin |
| 194 | + result := value; |
| 195 | + result := StringReplace(result, '"', '"', [rfReplaceAll, rfIgnoreCase]); |
| 196 | + result := StringReplace(result, '<', '<', [rfReplaceAll, rfIgnoreCase]); |
| 197 | + result := StringReplace(result, '&', '&', [rfReplaceAll, rfIgnoreCase]); |
| 198 | +End; |
| 199 | + |
174 | 200 | { TDOMXML }
|
175 | 201 |
|
176 | 202 | Procedure TDOMXML.Clear;
|
|
412 | 438 | If (Not inString) And ((ord(Buffer[Index]) <= 32) Or (Buffer[Index] = '>') Or (Buffer[Index] = '/') Or (isProcessingNode And (Buffer[Index] = '?'))) Then Begin
|
413 | 439 | setlength(result.fAttributes, High(result.fAttributes) + 2);
|
414 | 440 | result.fAttributes[High(result.fAttributes)].AttributeName := an;
|
415 |
| - result.fAttributes[High(result.fAttributes)].AttributeValue := StringReplace(t, '"', '"', [rfReplaceAll, rfIgnoreCase]); |
| 441 | + result.fAttributes[High(result.fAttributes)].AttributeValue := XMLAttributeStringToString(t); |
416 | 442 | t := '';
|
417 | 443 | If (ord(Buffer[Index]) <= 32) Then Begin // Es folgt ein weiteres Attribut
|
418 | 444 | state := ReadNameAttr;
|
|
539 | 565 | s := '<' + Node.NodeName;
|
540 | 566 | End;
|
541 | 567 | For i := 0 To High(Node.fAttributes) Do Begin
|
542 |
| - s := s + ' ' + Node.fAttributes[i].AttributeName + '="' + StringReplace(Node.fAttributes[i].AttributeValue, '"', '"', [rfReplaceAll, rfIgnoreCase]) + '"'; |
| 568 | + s := s + ' ' + Node.fAttributes[i].AttributeName + '="' + StringToXMLAttributeString(Node.fAttributes[i].AttributeValue) + '"'; |
543 | 569 | End;
|
544 | 570 | // Ein Node mit nur Attributen
|
545 | 571 | If (High(Node.fNodes) = -1) And (trim(Node.NodeValue) = '') Then Begin
|
|
844 | 870 |
|
845 | 871 | End.
|
846 | 872 |
|
| 873 | + |
0 commit comments