?? nativexml.pas
字號:
{ unit NativeXml
This is a small-footprint implementation to read and write XML documents
natively from Delpi code.
You can use this code to read XML documents from files, streams or strings.
The load routine generates events that can be used to display load progress
on the fly.
Author: Nils Haeck M.Sc. (n.haeck@simdesign.nl)
Version: 2.20
Original date: 01-Apr-2003
Last Modified: 16-Sep-2005
Latest changes:
06-Aug-2004
Removed unit Dialogs in registered version (required only for trial reminder
message), using defines.
08-Aug-2004
Added methods TXmlNode.NodeRemove, NodeIndexOf and Delete.
16-Aug-2004
Added public function DateTimeToString
Made TXmlNode.WriteToString public method
Changed name of TXmlDocument to TsdXmlDocument, and changed name of unit to
sdXmlDocuments. WARNING this change may impact the application code! Solution:
simply rename all the occurances of above object class and unit name.
17-Aug-2004
Removed bug with <!DOCTYPE...> declaration
27-Aug-2004
Added support for unicode. This is done by allowing strings in the document
and nodes to be encoded as UTF8 (see property TXmlDocument.Utf8Encoded).
Added support for loading UTF8 files.
Added TXmlNode methods ValueAsWidestring, ToWidestring, FromWidestring,
ToAnsiString, FromAnsiString, ReadWidestring, WriteWidestring.
Added TXmlNode method AttributeDelete.
01-Sep-2004
Added version string constant NativeXmlVersion.
Added conversion of character references (&#...; and &#x...;).
02-Sep-2004
Renamed DateTimeToString and DateTimeFromStringDefault to sdDateTimeToString
and sdDateTimeFromStringDefault to avoid naming conflict with SysUtils unit.
17-Sep-2004
Made compatible with Delphi 2, 3 and 4.
20-Sep-2004
Added method TXmlNode.ReadAttributeString
21-Sep-2004
Enhancements to stream converters to make writing faster when no conversion
is neccesary.
22-Sep-2004
Fixed bug in AttributeByName
25-Sep-2004
Added methods for buffered reading/writing to streams, this immensely speeds up
disk-based access. See classes TsdBufferedReadStream/TsdBufferedWriteStream.
Added option TNativeXml.DropCommentsOnParse. This provides for easier
processing of XML files with occasional comments in them. By default this
option is off.
03-Nov-2004
Changed attribute parsing code to allow controlchars #10 and #13 inside attribute
quoted strings.
Changed name TXmlNode.NodeReplace to TXmlNode.NodeFindOrCreate to be more
descriptive
Removed function AttributeValueByName and replaced it with property
AttributeValueByName, so that an attribute can also be written to it.
17-Nov-2004
Added TXmlNode methods WriteInt64 and ReadInt64, added property ValueAsInteger,
ValueAsFloat, ValueAsBool and ValueAsDateTime.
03-Dec-2004
Added TXmlNode method SortChildNodes
15-Dec-2004
Added compiler directives to make compatible with Delphi2005
17-Dec-2004
Added DTD parsing. Currently there is no validation yet. The <!ENTITY> elements
in the DTD will be used when ResolveEntityReferences is called.
18-Dec-2004
Added property EntityByName[] to TNativeXml
Added procedure ResolveEntityReferences to TNativeXml
22-Dec-2004
Added xeCharData type for elements with multiple chardata subelements. The
first xeCharData is converted to TXmlNode.ValueDirect.
19-Jan-2005
Corrected problem with Root property during parsing.
28-Jan-2005
Corrected problem with xeCharData parsing and checking for control characters.
Added IndentString property.
Added TXmlNodeList utility list class (to avoid casting).
Added EncodeBase64/DecodeBase64/EncodeBinHex/DecodeBinHex global functions
29-Jan-2005
Changed unit name from sdXmlDocuments to NativeXml, changed class name
TsdXmlDocument to TNativeXml. WARNING this change may impact the application
code! Solution: simply rename all the occurances of above object class and
unit name.
02-Feb-2005
Added TBigByteArray type to avoid compiler Range Check warnings
03-Feb-2005
Fixed bug with writing of DTD
Optimized TXmlNode memory usage by creating the FNodes and FAttributes objects
on the fly when neccesary instead of always at creation time
23-Feb-2005
Changed order of DoNodeLoaded and DoProgress, to avoid bug when freeing in
OnNodeLoaded.
29-Apr-2005
Added SortAttributes property
Added ParserWarnings property
Added RootNodeList property, to allow easier access to XML nodes in the header
Removed ExtraNodes and Comments properties
Changed Assign methods (faster now)
05-May-2005
Added function TXmlNode.NodeByElementType
Added boolean property TNativeXml.AbortParsing
25-Jul-2005
Fixed bug with end-tag reading (when reading CDATA sections with "]" in the
data string)
26-Jul-2005
Fixed bug with begin-tag reading
02-Aug-2005
Added TXmlNode.IsEqualTo function to compare nodes in documents
Fixed bug in FullPath property (one slash too much at start)
16-Sep-2005
Made compatible with Delphi 9 .NET
FindNodes can now also be used with full paths
Bugfix: no longer adds CRLF after ENTITY declarations
Bugfix: AttributeName[] setter now no longer strips quotes from attribute
value.
Added AttributeValueAsWidestring[] property
Added AttributeValueAsInteger[] property
Note: any external encoding (ANSI, UTF16, etc) is converted to an internal
encoding that is ANSI or UTF8. When the loaded document is ANSI based,
the encoding will be ANSI, in other cases (UTF8, UTF16) the encoding
will be UTF8.
Author: Nils Haeck M.Sc.
Copyright (c) 2003-2005 Simdesign B.V.
It is NOT allowed under ANY circumstances to publish or copy this code
without prior written permission of the Author!
This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
ANY KIND, either express or implied.
Please visit http://www.simdesign.nl/xml.html for more information.
}
{$DEFINE USEGRAPHICS} // uncomment if you do not want to include the Graphics unit.
// Delphi and BCB versions
// Delphi 3
{$IFDEF VER110}
{$DEFINE D3UP}
{$ENDIF}
// Delphi 4
{$IFDEF VER120}
{$DEFINE D3UP}
{$DEFINE D4UP}
{$ENDIF}
// BCB 4
{$IFDEF VER125}
{$DEFINE D4UP}
{$ENDIF}
// Delphi 5
{$IFDEF VER130}
{$DEFINE D3UP}
{$DEFINE D4UP}
{$DEFINE D5UP}
{$ENDIF}
//Delphi 6
{$IFDEF VER140}
{$DEFINE D3UP}
{$DEFINE D4UP}
{$DEFINE D5UP}
{$DEFINE D6UP}
{$ENDIF}
//Delphi 7
{$IFDEF VER150}
{$DEFINE D3UP}
{$DEFINE D4UP}
{$DEFINE D5UP}
{$DEFINE D6UP}
{$DEFINE D7UP}
{$ENDIF}
//Delphi 8
{$IFDEF VER160}
{$DEFINE D3UP}
{$DEFINE D4UP}
{$DEFINE D5UP}
{$DEFINE D6UP}
{$DEFINE D7UP}
{$DEFINE D8UP}
{$ENDIF}
// Delphi 2005
{$IFDEF VER170}
{$DEFINE D3UP}
{$DEFINE D4UP}
{$DEFINE D5UP}
{$DEFINE D6UP}
{$DEFINE D7UP}
{$DEFINE D8UP}
{$DEFINE D9UP}
{$ENDIF}
// above Delphi 2005
{$IFDEF VER180}
{$DEFINE D3UP}
{$DEFINE D4UP}
{$DEFINE D5UP}
{$DEFINE D6UP}
{$DEFINE D7UP}
{$DEFINE D8UP}
{$DEFINE D9UP}
{$DEFINE D10UP}
{$ENDIF}
unit NativeXml;
interface
uses
{$IFDEF D9UP}
Windows,
{$ENDIF}
{$IFDEF CLR}
System.Text,
{$ENDIF}
Classes,
{$IFDEF USEGRAPHICS}
{$IFDEF LINUX}
QGraphics,
{$ELSE}
Graphics,
{$ENDIF}
{$ENDIF}
SysUtils;
const
// Current version of the XmlDocuments unit
cNativeXmlVersion = '2.20';
// Delphi 3 and below stubs
{$IFNDEF D4UP}
type
TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);
function StringReplace(const S, OldPattern, NewPattern: string;
Flags: TReplaceFlags): string;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -