AL icon indicating copy to clipboard operation
AL copied to clipboard

XmlDocument.ReadFrom doesn't work with Instream, only Text

Open angela2389 opened this issue 7 years ago • 4 comments

Describe the bug When putting an (xml)text in Tempblob and then from Tempblob into XmlDocument with Instream, I get the following message:

De volgende uitzondering is opgetreden tijdens het verwerken van XML-gegevens: '.', hexadecimal value 0x00, is an invalid character. Line 1, position 237.

If I direct put my Text directly (so without tempblob) into XmlDocument.ReadFrom, it does work.

In C/AL we also use (succesfully) Text to Tempblob, Tempblob to Instream, Instream to XML DOM Management: XMLDOMManagement.LoadXMLDocumentFromInStream(InStream,XmlDocument);

To Reproduce reqText := '<nav:FuncValidateUser xmlns:nav="urn:microsoft-dynamics-schemas/codeunit/ClientAutomaticUpdates">' + 'nav:parUsername' + Format(parUserName, 0, 9) + '</nav:parUsername>' + 'nav:parPassword' + Format(parPassword, 0, 9) + '</nav:parPassword>' + '</nav:FuncValidateUser>';

    XmlDocument.ReadFrom(reqText, ParXmlDoc);    // This works!
    TempBlob.Blob.CreateOutStream(ReqBodyOutStream);
    ReqBodyOutStream.Write(reqText);

    TempBlob.Blob.CreateInStream(ReqBodyInStream);
    XmlDocument.ReadFrom(ReqBodyInStream, ParXmlDoc2); // Error

Versions:

  • AL Language: 3.0.152816
  • Business Central: 14.0.28850.0

angela2389 avatar Aug 27 '19 08:08 angela2389

@angela2389 this seems to be an encoding issue. Is the stream that you reading from have the encoding set to UTF-8?

atoader avatar Aug 27 '19 14:08 atoader

Hello @atoader ,

No, is not an encoding issue, I tested the code from @angela2389 and looks like XmlDocument.ReadFrom is reading beyond the end of string, in this case the string length is 205 and the error is the following:

image

It is complaining about the position 206 and the char 0x00, that must mark the end of the string.

You can create a project with AL:Go! and copy paste the next code to reproduce:

pageextension 50100 CustomerListExt extends "Customer List"
{
    trigger OnOpenPage();
    var
        reqText: Text;
        parUserName: Text;
        parPassword: Text;
        TempBlob: Record TempBlob;
        ReqBodyOutStream: OutStream;
        ReqBodyInStream: InStream;
        ParXmlDoc: XmlDocument;
        ParXmlDoc2: XmlDocument;
        qLen: Integer;
    begin
        parPassword := 'password';
        parUserName := 'usuario';
        reqText := '<nav:FuncValidateUser xmlns:nav="urn:microsoft-dynamics-schemas/codeunit/ClientAutomaticUpdates">' +
                   '<nav:parUsername>' + Format(parUserName, 0, 9) + '</nav:parUsername>' +
                   '<nav:parPassword>' + Format(parPassword, 0, 9) + '</nav:parPassword>' +
                   '</nav:FuncValidateUser>';

        XmlDocument.ReadFrom(reqText, ParXmlDoc);    // This works!
        TempBlob.Blob.CreateOutStream(ReqBodyOutStream, TextEncoding::UTF8);
        qLen := StrLen(reqText);
        ReqBodyOutStream.Write(reqText, qLen);

        TempBlob.Blob.CreateInStream(ReqBodyInStream, TextEncoding::UTF8);
        XmlDocument.ReadFrom(ReqBodyInStream, ParXmlDoc2); // Error

        Message('App published: Hello world');
    end;
}

Regards

ftornero9 avatar Aug 28 '19 08:08 ftornero9

Thanks for looking into this! We'll take it as a bug and fix it in the following weeks.

atoader avatar Aug 28 '19 08:08 atoader

Hi,

Many thanks for raising this issue. Unfortunately we have not been able to get to this issue as soon as we'd have liked. Since it has been a long time since this issue was last updated, it is possible that this has been fixed by a newer release of Business Central and the AL extension for Visual Studio Code. We have thus decided to close it.

If the issue still affects you on the latest insider build of Business Central, please help us and open a new issue for us with the latest steps to reproduce the issue, and link back to this closed issue to track any comments or discussions.

Thanks,
Thaddeus

github-actions[bot] avatar Jan 31 '22 02:01 github-actions[bot]