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 := '
'
'
'
XmlDocument.ReadFrom(reqText, ParXmlDoc); // This works!
TempBlob.Blob.CreateOutStream(ReqBodyOutStream);
ReqBodyOutStream.Write(reqText);
TempBlob.Blob.CreateInStream(ReqBodyInStream);
XmlDocument.ReadFrom(ReqBodyInStream, ParXmlDoc2); // Error
Versions:
@angela2389 this seems to be an encoding issue. Is the stream that you reading from have the encoding set to UTF-8?
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:
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
Thanks for looking into this! We'll take it as a bug and fix it in the following weeks.