Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

creator API #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Header translation for Microsoft XmlLite

**Note**: This is a minimal translation, some parts were not implemented and most are untested.

**Note**: i only used it in Win32 projects, but Delphi/Win64 was independently tested at
* https://github.com/EtheaDev/SVGIconImageList/pull/97
* https://github.com/EtheaDev/SVGIconImageList/issues/96

Sample code taken from production. We use this to generate very large (>1GB) Xml files from an array of temporary files.

procedure AppendFile(const FileName: string; _IXMLWriter: IXMLWriter);
Expand Down Expand Up @@ -49,4 +53,4 @@ Sample code taken from production. We use this to generate very large (>1GB) Xm
_IXMLWriter.WriteEndElement;
_IXMLWriter.WriteEndDocument;
_IXMLWriter.Flush;
end;
end;
24 changes: 21 additions & 3 deletions Samples/DynArrays to-from files/fxsParser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ implementation
TTableList = TList< TfxsTable >;
TFieldList = TList< TfxsField >;


// 1: xml tags and attrs are case-sensitive !!!
// 2: xml always consists of s SINGLE root tag
Const
Expand All @@ -61,14 +60,27 @@ procedure WriteXML(const Data: TfxsTables; const ToFile: string);
t: TfxsTable; f: TfxsField;

begin
wx := CreateXmlFileWriter(ToFile);
// wx := CreateXmlFileWriter(ToFile);

wx := CreateXmlLite.Data(ToFile).Writer; // Default UTF-8

// wx := CreateXmlLite.Data(ToFile).Encoding(TEncoding.Unicode).Writer; // UTF-16
// wx := CreateXmlLite.Data(ToFile).Encoding(1251).Writer; // Windows GetACP for Russian
// wx := CreateXmlLite.Data(ToFile).Encoding('windows-1251').Writer; // Windows GetACP for Russian

// The following three variants fail within XmlLite.dll with bad encoding error :-(
// wx := CreateXmlLite.Data(ToFile).Encoding( 866).Writer; // Windows GetOEMCP for Russian
// wx := CreateXmlLite.Data(ToFile).Encoding('CP866').Writer; // Windows GetOEMCP for Russian
// wx := CreateXmlLite.Data(ToFile).Encoding('cp1251').Writer; // Windows GetACP for Russian

if wx = nil then raise Exception.Create(ToFile + #13#10 + 'Can not write to the given file.');

EXmlLite.Check( wx.SetProperty(XmlWriterProperty.Indent, LongInt(True)) );
// EXmlLite.Check( wx.SetProperty(XmlWriterProperty_OmitXmlDeclaration, LongInt(True)) );

EXmlLite.Check( wx.WriteStartDocument( XmlStandalone.Omit ) );
EXmlLite.Check( wx.WriteComment( ' Delphi XML-Lite Demo Sample File, can be deleted ' ) );
EXmlLite.Check( wx.WriteComment( ' Cyrillic text sample for encodings test. ������ �������������� ������. ' ) );
EXmlLite.Check( wx.Flush );

EXmlLite.Check( wx.WriteStartElement( nil, Tag_DocRoot, nil) );
Expand Down Expand Up @@ -115,7 +127,13 @@ function ReadXML (const FromFile: string): TfxsTables;
CurrTableLevel, CurrLevel: Cardinal;
begin
Result := nil;
rx := CreateXmlFileReader( FromFile );

// rx := CreateXmlFileReader( FromFile );
rx := CreateXmlLite.Data(FromFile).Reader;
// reader should auto-adapt to the file encoding unless that is impossible in very special cases
// so here is no fair reason to pin-point encodings.
// not that pin-pointing it was of much sense for writer as well

if rx = nil then raise Exception.Create( FromFile + #13#10 + 'Can not read from the given file.');

ts := nil; fs := nil;
Expand Down
12 changes: 12 additions & 0 deletions Samples/Privat_ExchRates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>

<account_order>
<unsupport/>
<logged sessioncount="0" visitscount="0"/>
<locale language="ru">
</locale>
<request url_base="http://privat24.privatbank.ua/p24/" url="/accountorder" os="Win" win="Y" ie="N"/>
<info>
</info>

<row><exchangerate ccy="RUR" base_ccy="UAH" buy="0.40800" sale="0.41800"/></row><row><exchangerate ccy="EUR" base_ccy="UAH" buy="28.70000" sale="28.90000"/></row><row><exchangerate ccy="USD" base_ccy="UAH" buy="25.80000" sale="26.00000"/></row></account_order>
Loading