|
@@ -23,7 +23,7 @@ unit XMLRead;
|
|
interface
|
|
interface
|
|
|
|
|
|
uses
|
|
uses
|
|
- SysUtils, Classes, DOM;
|
|
|
|
|
|
+ SysUtils, Classes, DOM, xmlutils;
|
|
|
|
|
|
type
|
|
type
|
|
TErrorSeverity = (esWarning, esError, esFatal);
|
|
TErrorSeverity = (esWarning, esError, esFatal);
|
|
@@ -98,18 +98,18 @@ type
|
|
private
|
|
private
|
|
FStream: TStream;
|
|
FStream: TStream;
|
|
FStringData: string;
|
|
FStringData: string;
|
|
- FBaseURI: WideString;
|
|
|
|
- FSystemID: WideString;
|
|
|
|
- FPublicID: WideString;
|
|
|
|
|
|
+ FBaseURI: XMLString;
|
|
|
|
+ FSystemID: XMLString;
|
|
|
|
+ FPublicID: XMLString;
|
|
// FEncoding: string;
|
|
// FEncoding: string;
|
|
public
|
|
public
|
|
constructor Create(AStream: TStream); overload;
|
|
constructor Create(AStream: TStream); overload;
|
|
constructor Create(const AStringData: string); overload;
|
|
constructor Create(const AStringData: string); overload;
|
|
property Stream: TStream read FStream;
|
|
property Stream: TStream read FStream;
|
|
property StringData: string read FStringData;
|
|
property StringData: string read FStringData;
|
|
- property BaseURI: WideString read FBaseURI write FBaseURI;
|
|
|
|
- property SystemID: WideString read FSystemID write FSystemID;
|
|
|
|
- property PublicID: WideString read FPublicID write FPublicID;
|
|
|
|
|
|
+ property BaseURI: XMLString read FBaseURI write FBaseURI;
|
|
|
|
+ property SystemID: XMLString read FSystemID write FSystemID;
|
|
|
|
+ property PublicID: XMLString read FPublicID write FPublicID;
|
|
// property Encoding: string read FEncoding write FEncoding;
|
|
// property Encoding: string read FEncoding write FEncoding;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -121,7 +121,7 @@ type
|
|
constructor Create;
|
|
constructor Create;
|
|
destructor Destroy; override;
|
|
destructor Destroy; override;
|
|
procedure Parse(Src: TXMLInputSource; out ADoc: TXMLDocument);
|
|
procedure Parse(Src: TXMLInputSource; out ADoc: TXMLDocument);
|
|
- procedure ParseUri(const URI: WideString; out ADoc: TXMLDocument);
|
|
|
|
|
|
+ procedure ParseUri(const URI: XMLString; out ADoc: TXMLDocument);
|
|
function ParseWithContext(Src: TXMLInputSource; Context: TDOMNode;
|
|
function ParseWithContext(Src: TXMLInputSource; Context: TDOMNode;
|
|
Action: TXMLContextAction): TDOMNode;
|
|
Action: TXMLContextAction): TDOMNode;
|
|
property Options: TDOMParseOptions read FOptions;
|
|
property Options: TDOMParseOptions read FOptions;
|
|
@@ -143,7 +143,7 @@ procedure RegisterDecoder(Proc: TGetDecoderProc);
|
|
implementation
|
|
implementation
|
|
|
|
|
|
uses
|
|
uses
|
|
- UriParser, xmlutils, dtdmodel;
|
|
|
|
|
|
+ UriParser, dtdmodel;
|
|
|
|
|
|
const
|
|
const
|
|
PubidChars: TSetOfChar = [' ', #13, #10, 'a'..'z', 'A'..'Z', '0'..'9',
|
|
PubidChars: TSetOfChar = [' ', #13, #10, 'a'..'z', 'A'..'Z', '0'..'9',
|
|
@@ -172,25 +172,25 @@ type
|
|
FLineNo: Integer;
|
|
FLineNo: Integer;
|
|
LFPos: PWideChar;
|
|
LFPos: PWideChar;
|
|
FXML11Rules: Boolean;
|
|
FXML11Rules: Boolean;
|
|
- FSystemID: WideString;
|
|
|
|
|
|
+ FSystemID: XMLString;
|
|
FCharCount: Cardinal;
|
|
FCharCount: Cardinal;
|
|
FStartNesting: Integer;
|
|
FStartNesting: Integer;
|
|
FXMLVersion: TXMLVersion;
|
|
FXMLVersion: TXMLVersion;
|
|
- FXMLEncoding: WideString;
|
|
|
|
- function GetSystemID: WideString;
|
|
|
|
|
|
+ FXMLEncoding: XMLString;
|
|
|
|
+ function GetSystemID: XMLString;
|
|
protected
|
|
protected
|
|
function Reload: Boolean; virtual;
|
|
function Reload: Boolean; virtual;
|
|
public
|
|
public
|
|
Kind: TXMLSourceKind;
|
|
Kind: TXMLSourceKind;
|
|
- constructor Create(const AData: WideString);
|
|
|
|
|
|
+ constructor Create(const AData: XMLString);
|
|
procedure NextChar;
|
|
procedure NextChar;
|
|
procedure NewLine; virtual;
|
|
procedure NewLine; virtual;
|
|
function SkipUntil(var ToFill: TWideCharBuf; const Delim: TSetOfChar;
|
|
function SkipUntil(var ToFill: TWideCharBuf; const Delim: TSetOfChar;
|
|
wsflag: PBoolean = nil): WideChar; virtual;
|
|
wsflag: PBoolean = nil): WideChar; virtual;
|
|
procedure Initialize; virtual;
|
|
procedure Initialize; virtual;
|
|
function SetEncoding(const AEncoding: string): Boolean; virtual;
|
|
function SetEncoding(const AEncoding: string): Boolean; virtual;
|
|
- function Matches(const arg: WideString): Boolean;
|
|
|
|
- property SystemID: WideString read GetSystemID write FSystemID;
|
|
|
|
|
|
+ function Matches(const arg: XMLString): Boolean;
|
|
|
|
+ property SystemID: XMLString read GetSystemID write FSystemID;
|
|
end;
|
|
end;
|
|
|
|
|
|
TXMLDecodingSource = class(TXMLCharSource)
|
|
TXMLDecodingSource = class(TXMLCharSource)
|
|
@@ -241,7 +241,7 @@ type
|
|
|
|
|
|
PForwardRef = ^TForwardRef;
|
|
PForwardRef = ^TForwardRef;
|
|
TForwardRef = record
|
|
TForwardRef = record
|
|
- Value: WideString;
|
|
|
|
|
|
+ Value: XMLString;
|
|
Loc: TLocation;
|
|
Loc: TLocation;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -324,7 +324,7 @@ type
|
|
procedure XML11_BuildTables;
|
|
procedure XML11_BuildTables;
|
|
function ParseQuantity: TCPQuant;
|
|
function ParseQuantity: TCPQuant;
|
|
procedure StoreLocation(out Loc: TLocation);
|
|
procedure StoreLocation(out Loc: TLocation);
|
|
- function ValidateAttrSyntax(AttrDef: TAttributeDef; const aValue: WideString): Boolean;
|
|
|
|
|
|
+ function ValidateAttrSyntax(AttrDef: TAttributeDef; const aValue: XMLString): Boolean;
|
|
procedure ValidateAttrValue(AttrDef: TAttributeDef; attrData: PNodeData);
|
|
procedure ValidateAttrValue(AttrDef: TAttributeDef; attrData: PNodeData);
|
|
procedure AddForwardRef(Buf: PWideChar; Length: Integer);
|
|
procedure AddForwardRef(Buf: PWideChar; Length: Integer);
|
|
procedure ClearForwardRefs;
|
|
procedure ClearForwardRefs;
|
|
@@ -373,7 +373,7 @@ type
|
|
procedure RaiseNameNotFound;
|
|
procedure RaiseNameNotFound;
|
|
function CheckName(aFlags: TCheckNameFlags = []): Boolean;
|
|
function CheckName(aFlags: TCheckNameFlags = []): Boolean;
|
|
procedure CheckNCName;
|
|
procedure CheckNCName;
|
|
- function ExpectName: WideString; // [5]
|
|
|
|
|
|
+ function ExpectName: XMLString; // [5]
|
|
function ParseLiteral(var ToFill: TWideCharBuf; aType: TLiteralType;
|
|
function ParseLiteral(var ToFill: TWideCharBuf; aType: TLiteralType;
|
|
Required: Boolean): Boolean;
|
|
Required: Boolean): Boolean;
|
|
procedure ExpectAttValue(attrData: PNodeData; NonCDATA: Boolean); // [10]
|
|
procedure ExpectAttValue(attrData: PNodeData; NonCDATA: Boolean); // [10]
|
|
@@ -402,7 +402,7 @@ type
|
|
function PrefetchEntity(AEntity: TEntityDecl): Boolean;
|
|
function PrefetchEntity(AEntity: TEntityDecl): Boolean;
|
|
procedure StartPE;
|
|
procedure StartPE;
|
|
function ParseRef(var ToFill: TWideCharBuf): Boolean; // [67]
|
|
function ParseRef(var ToFill: TWideCharBuf): Boolean; // [67]
|
|
- function ParseExternalID(out SysID, PubID: WideString; // [75]
|
|
|
|
|
|
+ function ParseExternalID(out SysID, PubID: XMLString; // [75]
|
|
SysIdOptional: Boolean): Boolean;
|
|
SysIdOptional: Boolean): Boolean;
|
|
|
|
|
|
procedure BadPENesting(S: TErrorSeverity = esError);
|
|
procedure BadPENesting(S: TErrorSeverity = esError);
|
|
@@ -411,7 +411,7 @@ type
|
|
procedure ExpectChoiceOrSeq(CP: TContentParticle; MustEndIn: TObject);
|
|
procedure ExpectChoiceOrSeq(CP: TContentParticle; MustEndIn: TObject);
|
|
procedure ParseElementDecl;
|
|
procedure ParseElementDecl;
|
|
procedure ParseNotationDecl;
|
|
procedure ParseNotationDecl;
|
|
- function ResolveResource(const ASystemID, APublicID, ABaseURI: WideString; out Source: TXMLCharSource): Boolean;
|
|
|
|
|
|
+ function ResolveResource(const ASystemID, APublicID, ABaseURI: XMLString; out Source: TXMLCharSource): Boolean;
|
|
procedure ProcessDefaultAttributes(ElDef: TElementDecl);
|
|
procedure ProcessDefaultAttributes(ElDef: TElementDecl);
|
|
procedure ProcessNamespaceAtts;
|
|
procedure ProcessNamespaceAtts;
|
|
function AddBinding(attrData: PNodeData): Boolean;
|
|
function AddBinding(attrData: PNodeData): Boolean;
|
|
@@ -425,7 +425,7 @@ type
|
|
procedure DTDReloadHook;
|
|
procedure DTDReloadHook;
|
|
procedure ConvertSource(SrcIn: TXMLInputSource; out SrcOut: TXMLCharSource);
|
|
procedure ConvertSource(SrcIn: TXMLInputSource; out SrcOut: TXMLCharSource);
|
|
function DoCDSect(ch: PWideChar; Count: Integer): TDOMNode;
|
|
function DoCDSect(ch: PWideChar; Count: Integer): TDOMNode;
|
|
- procedure DoNotationDecl(const aName, aPubID, aSysID: WideString);
|
|
|
|
|
|
+ procedure DoNotationDecl(const aName, aPubID, aSysID: XMLString);
|
|
public
|
|
public
|
|
doc: TDOMDocument;
|
|
doc: TDOMDocument;
|
|
constructor Create; overload;
|
|
constructor Create; overload;
|
|
@@ -548,7 +548,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TDOMParser.ParseUri(const URI: WideString; out ADoc: TXMLDocument);
|
|
|
|
|
|
+procedure TDOMParser.ParseUri(const URI: XMLString; out ADoc: TXMLDocument);
|
|
var
|
|
var
|
|
Src: TXMLCharSource;
|
|
Src: TXMLCharSource;
|
|
begin
|
|
begin
|
|
@@ -611,7 +611,7 @@ end;
|
|
|
|
|
|
{ TXMLCharSource }
|
|
{ TXMLCharSource }
|
|
|
|
|
|
-constructor TXMLCharSource.Create(const AData: WideString);
|
|
|
|
|
|
+constructor TXMLCharSource.Create(const AData: XMLString);
|
|
begin
|
|
begin
|
|
inherited Create;
|
|
inherited Create;
|
|
FLineNo := 1;
|
|
FLineNo := 1;
|
|
@@ -630,7 +630,7 @@ begin
|
|
Result := True; // always succeed
|
|
Result := True; // always succeed
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TXMLCharSource.GetSystemID: WideString;
|
|
|
|
|
|
+function TXMLCharSource.GetSystemID: XMLString;
|
|
begin
|
|
begin
|
|
if FSystemID <> '' then
|
|
if FSystemID <> '' then
|
|
Result := FSystemID
|
|
Result := FSystemID
|
|
@@ -674,7 +674,7 @@ begin
|
|
wsflag^ := wsflag^ or nonws;
|
|
wsflag^ := wsflag^ or nonws;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TXMLCharSource.Matches(const arg: WideString): Boolean;
|
|
|
|
|
|
+function TXMLCharSource.Matches(const arg: XMLString): Boolean;
|
|
begin
|
|
begin
|
|
Result := False;
|
|
Result := False;
|
|
if (FBufEnd >= FBuf + Length(arg)) or Reload then
|
|
if (FBufEnd >= FBuf + Length(arg)) or Reload then
|
|
@@ -983,9 +983,9 @@ begin
|
|
Loc.LinePos := FSource.FBuf-FSource.LFPos;
|
|
Loc.LinePos := FSource.FBuf-FSource.LFPos;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TXMLTextReader.ResolveResource(const ASystemID, APublicID, ABaseURI: WideString; out Source: TXMLCharSource): Boolean;
|
|
|
|
|
|
+function TXMLTextReader.ResolveResource(const ASystemID, APublicID, ABaseURI: XMLString; out Source: TXMLCharSource): Boolean;
|
|
var
|
|
var
|
|
- AbsSysID: WideString;
|
|
|
|
|
|
+ AbsSysID: XMLString;
|
|
Filename: string;
|
|
Filename: string;
|
|
Stream: TStream;
|
|
Stream: TStream;
|
|
fd: THandle;
|
|
fd: THandle;
|
|
@@ -1047,7 +1047,7 @@ end;
|
|
|
|
|
|
procedure TXMLTextReader.ValidationErrorWithName(const Msg: string; LineOffs: Integer);
|
|
procedure TXMLTextReader.ValidationErrorWithName(const Msg: string; LineOffs: Integer);
|
|
var
|
|
var
|
|
- ws: WideString;
|
|
|
|
|
|
+ ws: XMLString;
|
|
begin
|
|
begin
|
|
SetString(ws, FName.Buffer, FName.Length);
|
|
SetString(ws, FName.Buffer, FName.Length);
|
|
ValidationError(Msg, [ws], LineOffs);
|
|
ValidationError(Msg, [ws], LineOffs);
|
|
@@ -1076,7 +1076,7 @@ end;
|
|
procedure TXMLTextReader.DoErrorPos(Severity: TErrorSeverity; const descr: string; const ErrPos: TLocation);
|
|
procedure TXMLTextReader.DoErrorPos(Severity: TErrorSeverity; const descr: string; const ErrPos: TLocation);
|
|
var
|
|
var
|
|
E: EXMLReadError;
|
|
E: EXMLReadError;
|
|
- sysid: WideString;
|
|
|
|
|
|
+ sysid: XMLString;
|
|
begin
|
|
begin
|
|
if Assigned(FSource) then
|
|
if Assigned(FSource) then
|
|
begin
|
|
begin
|
|
@@ -1464,7 +1464,7 @@ begin
|
|
FatalError('Name starts with invalid character');
|
|
FatalError('Name starts with invalid character');
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TXMLTextReader.ExpectName: WideString;
|
|
|
|
|
|
+function TXMLTextReader.ExpectName: XMLString;
|
|
begin
|
|
begin
|
|
CheckName;
|
|
CheckName;
|
|
SetString(Result, FName.Buffer, FName.Length);
|
|
SetString(Result, FName.Buffer, FName.Length);
|
|
@@ -1709,7 +1709,7 @@ end;
|
|
|
|
|
|
function TXMLTextReader.EntityCheck(NoExternals: Boolean): TEntityDecl;
|
|
function TXMLTextReader.EntityCheck(NoExternals: Boolean): TEntityDecl;
|
|
var
|
|
var
|
|
- RefName: WideString;
|
|
|
|
|
|
+ RefName: XMLString;
|
|
cnt: Integer;
|
|
cnt: Integer;
|
|
begin
|
|
begin
|
|
Result := nil;
|
|
Result := nil;
|
|
@@ -1923,7 +1923,7 @@ end;
|
|
|
|
|
|
function TXMLTextReader.CreatePINode: TDOMNode;
|
|
function TXMLTextReader.CreatePINode: TDOMNode;
|
|
var
|
|
var
|
|
- NameStr, ValueStr: WideString;
|
|
|
|
|
|
+ NameStr, ValueStr: DOMString;
|
|
begin
|
|
begin
|
|
SetString(NameStr, FName.Buffer, FName.Length);
|
|
SetString(NameStr, FName.Buffer, FName.Length);
|
|
SetString(ValueStr, FValue.Buffer, FValue.Length);
|
|
SetString(ValueStr, FValue.Buffer, FValue.Length);
|
|
@@ -2267,7 +2267,7 @@ end;
|
|
|
|
|
|
procedure TXMLTextReader.ParseNotationDecl; // [82]
|
|
procedure TXMLTextReader.ParseNotationDecl; // [82]
|
|
var
|
|
var
|
|
- NameStr, SysID, PubID: WideString;
|
|
|
|
|
|
+ NameStr, SysID, PubID: XMLString;
|
|
begin
|
|
begin
|
|
ExpectWhitespace;
|
|
ExpectWhitespace;
|
|
NameStr := ExpectName;
|
|
NameStr := ExpectName;
|
|
@@ -2280,7 +2280,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
const
|
|
const
|
|
- AttrDataTypeNames: array[TAttrDataType] of WideString = (
|
|
|
|
|
|
+ AttrDataTypeNames: array[TAttrDataType] of XMLString = (
|
|
'CDATA',
|
|
'CDATA',
|
|
'ID',
|
|
'ID',
|
|
'IDREF',
|
|
'IDREF',
|
|
@@ -3536,7 +3536,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TXMLTextReader.ParseExternalID(out SysID, PubID: WideString; // [75]
|
|
|
|
|
|
+function TXMLTextReader.ParseExternalID(out SysID, PubID: XMLString; // [75]
|
|
SysIdOptional: Boolean): Boolean;
|
|
SysIdOptional: Boolean): Boolean;
|
|
var
|
|
var
|
|
I: Integer;
|
|
I: Integer;
|
|
@@ -3569,7 +3569,7 @@ begin
|
|
Result := True;
|
|
Result := True;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TXMLTextReader.ValidateAttrSyntax(AttrDef: TAttributeDef; const aValue: WideString): Boolean;
|
|
|
|
|
|
+function TXMLTextReader.ValidateAttrSyntax(AttrDef: TAttributeDef; const aValue: XMLString): Boolean;
|
|
begin
|
|
begin
|
|
case AttrDef.DataType of
|
|
case AttrDef.DataType of
|
|
dtId, dtIdRef, dtEntity: Result := IsXmlName(aValue, FXML11) and
|
|
dtId, dtIdRef, dtEntity: Result := IsXmlName(aValue, FXML11) and
|
|
@@ -3639,7 +3639,7 @@ end;
|
|
|
|
|
|
function TXMLTextReader.DoCDSect(ch: PWideChar; Count: Integer): TDOMNode;
|
|
function TXMLTextReader.DoCDSect(ch: PWideChar; Count: Integer): TDOMNode;
|
|
var
|
|
var
|
|
- s: WideString;
|
|
|
|
|
|
+ s: XMLString;
|
|
begin
|
|
begin
|
|
Assert(not FCDSectionsAsText, 'Should not be called when CDSectionsAsText=True');
|
|
Assert(not FCDSectionsAsText, 'Should not be called when CDSectionsAsText=True');
|
|
|
|
|
|
@@ -3647,7 +3647,7 @@ begin
|
|
result := doc.CreateCDATASection(s);
|
|
result := doc.CreateCDATASection(s);
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TXMLTextReader.DoNotationDecl(const aName, aPubID, aSysID: WideString);
|
|
|
|
|
|
+procedure TXMLTextReader.DoNotationDecl(const aName, aPubID, aSysID: XMLString);
|
|
var
|
|
var
|
|
Notation: TNotationDecl;
|
|
Notation: TNotationDecl;
|
|
Entry: PHashItem;
|
|
Entry: PHashItem;
|