AL
AL copied to clipboard
Import XML file into XML document in extension
Hi, Can anyone help me with how to import an existing xml file into a xmldocument? I have used the function xmldocument.load(path) before, but I can not use that in an extension.
thanks.
Hi, I have used the following code, which uses UploadIntoStream to load the xml file into an Instream, then XmlDocument.ReadFrom to read the stream into an xmldocument. Hope it helps.
var
Tempblob : Record Tempblob;
TargetXmlDoc : XmlDocument;
XmlDec : XmlDeclaration;
begin
// Create Xml Document
TargetXmlDoc := XmlDocument.Create;
xmlDec := xmlDeclaration.Create('1.0','UTF-8','');
TargetXmlDoc.SetDeclaration(xmlDec);
// Create Instream & upload file into it
Tempblob.blob.CreateInStream(Instr);
filename := 'Content.xml';
filepath := 'C:\Temp';
UploadIntoStream('Window Title',filepath,'',filename,Instr);
// Read stream into new xml document
Xmldocument.ReadFrom(Instr, TargetXmlDoc);
end