Thanks.
You can use BASE64 encoding for that.
Check out our XmlDocuments component, it supports automatic BASE64 encoding
through the TXmlNode.BinaryString property.
www.simdesign.nl/xml.html
Kind regards,
Nils Haeck
www.simdesign.nl
"stan" <st...@yahoo.com> wrote in message
news:41bea80f$1...@newsgroups.borland.com...
Base64 encode and enclose in a CDATA section.
This is a modified snippet of code from my XMLTable control
that converts a Dataset to XML, this is the code that handles
ftTypedBinary, ftBlob, and ftGraphic field types.
var
oXMLDoc: TdomDocument;
oRoot: TdomNode;
oChild: TdomElement;
oXMLdecl: TdomXmlDeclaration;
oXMLCDATASection: TdomCDATASection;
DecBlobStream: TMemoryStream;
EncBlobStream: TMemoryStream;
cDatasl: TStringList;
sFieldName: String;
sFieldValue: String;
begin
oXMLDoc := TdomDocument.Create;
try
oRoot := nil;
oChild := nil;
oNode := nil;
oAttr := nil;
oXMLdecl := nil;
oXMLCDATASection := nil;
oDTD := nil;
oRoot := TdomNode.Create(oXMLDoc);
oRoot := FXMLDoc.CreateElement('ROWSET');
oXMLDoc.AppendChild(oRoot);
oXMLdecl := oXMLDoc.CreateXmlDeclaration('1.0', 'UTF-8', 'yes');
oXMLDoc.InsertBefore(oXMLdecl, oXMLDoc.ChildNodes.Item(0));
oNode := oXMLDoc.CreateElement('ROW');
oXMLDoc.DocumentElement.AppendChild(oNode);
// Can't have spaces in Node Name so replace with underscore '_'
sFieldName := StringReplace(Source.FieldList.Fields[i].FieldName,
' ', '_', [rfReplaceAll]);
oChild := FXMLDoc.CreateElement(sFieldName);
oNode.AppendChild(oChild);
cDatasl := TStringList.Create;
DecBlobStream := TMemoryStream.Create;
EncBlobStream := TMemoryStream.Create;
try
TBlobField(Source.Fields[i]).SaveToStream(DecBlobStream);
DecBlobStream.Position := 0;
// base64 encoding source cut from Andreas
// Horstmeier's TCP/IP component suite
// email me at mr_delphi_developer at yahoo dot com
// if you want the converted source
cDatasl := encode_base64(DecBlobStream);
sFieldValue := cDatasl.Text;
oXMLCDATASection := TdomCDATASection.Create(oXMLDoc);
oXMLCDATASection.Data := sFieldValue;
oChild.AppendChild(oXMLCDATASection);
finally
FreeAndNil(EncBlobStream);
FreeAndNil(DecBlobStream);
FreeAndNil(cDatasl);
end;
finally
FreeAndNil(oXMLDoc);
end;
end;
Do you need to store it in CDATA section? Once it's Base64 encoded I think
you should be able to store it as an element.
If you really want to know, check the RFC. I think it
is a requirement.
> If you really want to know, check the RFC. I think it
> is a requirement.
base64Binary is a native XML data type (in XML schema).
Danny
---
But he didn't specify that he would be using a schema and thus I gave
him an answer that he could use without using one or with using a DTD
only.