Archive for the ‘xml’ category

XMLDataSet component

September 9, 2006

There’s this nifty XML import-export component we use a lot in our projects. Unfortuantely the development of this has ended and there are quite a lot of bugs in the code. Here are some of them that I’ve found in XMLDataSet.pas:

Someone forgot to clear the Result value:

  Function MimeEncodeString(
    Const AInputString: AnsiString): AnsiString; //rjMime
    Result := ''; {!! indrek 20060901}
    If Pointer(AInputString) <> Nil Then Begin

That’s a bad one: every time You had some nonallowed character (like space) in the datapacket name, an EXMLInvalidpacket exception was created but not raised causing 1) a memory leak 2) illegal characters in datapacket name. After making this modification You have to check all Your datapacket names because they might have nonallowed characters.

Procedure TXMLDataset.SetPacketName(AName: AnsiString);
    While tI1 <= Len1 Do Begin
      // If Not (AName[tI1] In AllAllowed) Then
      // EXMLInvalidPacket.Create('Invalid DataPacket name');
      {!! indrek 20051010}
      If Not (AName[tI1] In AllAllowed) Then
        Raise EXMLInvalidPacket.Create('Invalid DataPacket name');

This bug caused a lot of headache for us at first. The apostrophe (‘) character has to be converted to XML entity (&apos;) when exporting and reconverted back during importing. The converting was OK, but it left the trailing ‘s’ in the string (i.e. “Harry’s” become “Harry’ss” after exporting-importing).

Procedure TXMLDataset.ConvertDatasetToXML;

  'P': Case Chars1[3] Of
      'O': Case Chars1[4] Of
          'S': Case AIgnoreSemicolon Of
              True: Begin
                  AOutput[OutputIndex1] := APOSTROPHE_CHAR;
                  // Inc(InputIndex1, 4);
                  Inc(InputIndex1, 5); { indrek 20050216 }
                Case Chars1[5] Of
                  SEMICOLON_CHAR: Begin
                      AOutput[OutputIndex1] := APOSTROPHE_CHAR;
                      // Inc(InputIndex1, 5);
                      Inc(InputIndex1, 6); { indrek 20050216 }