📄 omnixml.pas
字号:
{ $OmniXML: OmniXML/OmniXML.pas,v 1.1.1.1 2004/04/17 11:16:33 mr Exp $ }
(*******************************************************************************
* The contents of this file are subject to the Mozilla Public License Version *
* 1.1 (the "License"); you may not use this file except in compliance with the *
* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ *
* *
* Software distributed under the License is distributed on an "AS IS" basis, *
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for *
* the specific language governing rights and limitations under the License. *
* *
* The Original Code is OmniXML.pas *
* *
* The Initial Developer of the Original Code is Miha Remec *
* http://www.MihaRemec.com/ *
* *
* Contributor(s): *
* Primoz Gabrijelcic (gp) *
* Erik Berry (eb) *
*******************************************************************************)
unit OmniXML;
interface
{$I OmniXML.inc}
uses
Classes, SysUtils
{$IFDEF MSWINDOWS}, GpTextStream {$ENDIF}
;
const
{$IFDEF LINUX}
// copied from GpTextStream.pas
CP_UNICODE = 1200; // Unicode pseudo-codepage,
ISO_8859_1 = 28591; // Western Alphabet (ISO)
ISO_8859_2 = 28592; // Central European Alphabet (ISO)
ISO_8859_3 = 28593; // Latin 3 Alphabet (ISO)
ISO_8859_4 = 28594; // Baltic Alphabet (ISO)
ISO_8859_5 = 28595; // Cyrillic Alphabet (ISO)
ISO_8859_6 = 28596; // Arabic Alphabet (ISO)
ISO_8859_7 = 28597; // Greek Alphabet (ISO)
ISO_8859_8 = 28598; // Hebrew Alphabet (ISO)
{$ENDIF}
CP_UTF16 = CP_UNICODE;
CP_UTF8 = 65001; // UTF-8 translation
const
HEADER_UTF16: WideChar = WideChar($FEFF); // don't change!
const
DEFAULT_DECIMALSEPARATOR = '.'; // don't change!
DEFAULT_TRUE = '1'; // don't change!
DEFAULT_FALSE = '0'; // don't change!
DEFAULT_DATETIMESEPARATOR = 'T'; // don't change!
DEFAULT_DATESEPARATOR = '-'; // don't change!
DEFAULT_TIMESEPARATOR = ':'; // don't change!
DEFAULT_MSSEPARATOR = '.'; // don't change!
const
// element node
ELEMENT_NODE = 1;
// attribute node
ATTRIBUTE_NODE = 2;
// text node
TEXT_NODE = 3;
// CDATA section node
CDATA_SECTION_NODE = 4;
// entity reference node
ENTITY_REFERENCE_NODE = 5;
// entity node
ENTITY_NODE = 6;
// processing instruction node
PROCESSING_INSTRUCTION_NODE = 7;
// comment node
COMMENT_NODE = 8;
// document node
DOCUMENT_NODE = 9;
// document type node
DOCUMENT_TYPE_NODE = 10;
// document fragment node
DOCUMENT_FRAGMENT_NODE = 11;
// notation node
NOTATION_NODE = 12;
type
TNodeType = 1..12;
const
// these codes are part of Exception codes
// index or size is negative, or greater than the allowed value
INDEX_SIZE_ERR = 1;
// the specified range of text does not fit into a WideString
XMLSTRING_SIZE_ERR = 2;
// any node is inserted somewhere it doesn't belong
HIERARCHY_REQUEST_ERR = 3;
// a node is used in a different document than the one that created it (that doesn't support it)
WRONG_DOCUMENT_ERR = 4;
// an invalid character is specified, such as in a name
INVALID_CHARACTER_ERR = 5;
// data is specified for a node which does not support data
NO_DATA_ALLOWED_ERR = 6;
// an attempt is made to modify an object where modifications are not allowed
NO_MODIFICATION_ALLOWED_ERR = 7;
// an attempt was made to reference a node in a context where it does not exist
NOT_FOUND_ERR = 8;
// the implementation does not support the type of object requested
NOT_SUPPORTED_ERR = 9;
// an attempt is made to add an attribute that is already inuse elsewhere
INUSE_ATTRIBUTE_ERR = 10;
const
MSG_E_NOTEXT = $0000;
MSG_E_BASE = $0001;
MSG_E_FORMATINDEX_BADINDEX = MSG_E_BASE + 0;
MSG_E_FORMATINDEX_BADFORMAT = MSG_E_BASE + 1;
MSG_E_SYSTEM_ERROR = MSG_E_BASE + 2;
MSG_E_MISSINGEQUALS = MSG_E_BASE + 3;
MSG_E_EXPECTED_TOKEN = MSG_E_BASE + 4;
MSG_E_UNEXPECTED_TOKEN = MSG_E_BASE + 5;
MSG_E_MISSINGQUOTE = MSG_E_BASE + 6;
MSG_E_COMMENTSYNTAX = MSG_E_BASE + 7;
MSG_E_BADSTARTNAMECHAR = MSG_E_BASE + 8;
MSG_E_BADNAMECHAR = MSG_E_BASE + 9;
MSG_E_BADCHARINSTRING = MSG_E_BASE + 10;
MSG_E_XMLDECLSYNTAX = MSG_E_BASE + 11;
MSG_E_BADCHARDATA = MSG_E_BASE + 12;
MSG_E_MISSINGWHITESPACE = MSG_E_BASE + 13;
MSG_E_EXPECTINGTAGEND = MSG_E_BASE + 14;
MSG_E_BADCHARINDTD = MSG_E_BASE + 15;
MSG_E_BADCHARINDECL = MSG_E_BASE + 16;
MSG_E_MISSINGSEMICOLON = MSG_E_BASE + 17;
MSG_E_BADCHARINENTREF = MSG_E_BASE + 18;
MSG_E_UNBALANCEDPAREN = MSG_E_BASE + 19;
MSG_E_EXPECTINGOPENBRACKET = MSG_E_BASE + 20;
MSG_E_BADENDCONDSECT = MSG_E_BASE + 21;
MSG_E_INTERNALERROR = MSG_E_BASE + 22;
MSG_E_UNEXPECTED_WHITESPACE = MSG_E_BASE + 23;
MSG_E_INCOMPLETE_ENCODING = MSG_E_BASE + 24;
MSG_E_BADCHARINMIXEDMODEL = MSG_E_BASE + 25;
MSG_E_MISSING_STAR = MSG_E_BASE + 26;
MSG_E_BADCHARINMODEL = MSG_E_BASE + 27;
MSG_E_MISSING_PAREN = MSG_E_BASE + 28;
MSG_E_BADCHARINENUMERATION = MSG_E_BASE + 29;
MSG_E_PIDECLSYNTAX = MSG_E_BASE + 30;
MSG_E_EXPECTINGCLOSEQUOTE = MSG_E_BASE + 31;
MSG_E_MULTIPLE_COLONS = MSG_E_BASE + 32;
MSG_E_INVALID_DECIMAL = MSG_E_BASE + 33;
MSG_E_INVALID_HEXADECIMAL = MSG_E_BASE + 34;
MSG_E_INVALID_UNICODE = MSG_E_BASE + 35;
MSG_E_WHITESPACEORQUESTIONMARK = MSG_E_BASE + 36;
MSG_E_SUSPENDED = MSG_E_BASE + 37;
MSG_E_STOPPED = MSG_E_BASE + 38;
MSG_E_UNEXPECTEDENDTAG = MSG_E_BASE + 39;
MSG_E_UNCLOSEDTAG = MSG_E_BASE + 40;
MSG_E_DUPLICATEATTRIBUTE = MSG_E_BASE + 41;
MSG_E_MULTIPLEROOTS = MSG_E_BASE + 42;
MSG_E_INVALIDATROOTLEVEL = MSG_E_BASE + 43;
MSG_E_BADXMLDECL = MSG_E_BASE + 44;
MSG_E_MISSINGROOT = MSG_E_BASE + 45;
MSG_E_UNEXPECTEDEOF = MSG_E_BASE + 46;
MSG_E_BADPEREFINSUBSET = MSG_E_BASE + 47;
MSG_E_PE_NESTING = MSG_E_BASE + 48;
MSG_E_INVALID_CDATACLOSINGTAG = MSG_E_BASE + 49;
MSG_E_UNCLOSEDPI = MSG_E_BASE + 50;
MSG_E_UNCLOSEDSTARTTAG = MSG_E_BASE + 51;
MSG_E_UNCLOSEDENDTAG = MSG_E_BASE + 52;
MSG_E_UNCLOSEDSTRING = MSG_E_BASE + 53;
MSG_E_UNCLOSEDCOMMENT = MSG_E_BASE + 54;
MSG_E_UNCLOSEDDECL = MSG_E_BASE + 55;
MSG_E_UNCLOSEDMARKUPDECL = MSG_E_BASE + 56;
MSG_E_UNCLOSEDCDATA = MSG_E_BASE + 57;
MSG_E_BADDECLNAME = MSG_E_BASE + 58;
MSG_E_BADEXTERNALID = MSG_E_BASE + 59;
MSG_E_BADELEMENTINDTD = MSG_E_BASE + 60;
MSG_E_RESERVEDNAMESPACE = MSG_E_BASE + 61;
MSG_E_EXPECTING_VERSION = MSG_E_BASE + 62;
MSG_E_EXPECTING_ENCODING = MSG_E_BASE + 63;
MSG_E_EXPECTING_NAME = MSG_E_BASE + 64;
MSG_E_UNEXPECTED_ATTRIBUTE = MSG_E_BASE + 65;
MSG_E_ENDTAGMISMATCH = MSG_E_BASE + 66;
MSG_E_INVALIDENCODING = MSG_E_BASE + 67;
MSG_E_INVALIDSWITCH = MSG_E_BASE + 68;
MSG_E_EXPECTING_NDATA = MSG_E_BASE + 69;
MSG_E_INVALID_MODEL = MSG_E_BASE + 70;
MSG_E_INVALID_TYPE = MSG_E_BASE + 71;
MSG_E_INVALIDXMLSPACE = MSG_E_BASE + 72;
MSG_E_MULTI_ATTR_VALUE = MSG_E_BASE + 73;
MSG_E_INVALID_PRESENCE = MSG_E_BASE + 74;
MSG_E_BADXMLCASE = MSG_E_BASE + 75;
MSG_E_CONDSECTINSUBSET = MSG_E_BASE + 76;
MSG_E_CDATAINVALID = MSG_E_BASE + 77;
MSG_E_INVALID_STANDALONE = MSG_E_BASE + 78;
MSG_E_UNEXPECTED_STANDALONE = MSG_E_BASE + 79;
MSG_E_DOCTYPE_IN_DTD = MSG_E_BASE + 80;
MSG_E_MISSING_ENTITY = MSG_E_BASE + 81;
MSG_E_ENTITYREF_INNAME = MSG_E_BASE + 82;
MSG_E_DOCTYPE_OUTSIDE_PROLOG = MSG_E_BASE + 83;
MSG_E_INVALID_VERSION = MSG_E_BASE + 84;
MSG_E_DTDELEMENT_OUTSIDE_DTD = MSG_E_BASE + 85;
MSG_E_DUPLICATEDOCTYPE = MSG_E_BASE + 86;
MSG_E_RESOURCE = MSG_E_BASE + 87;
// 2003-02-22 (mr): added MSG_E_INVALID_OPERATION
MSG_E_INVALID_OPERATION = MSG_E_BASE + 88;
XML_BASE = MSG_E_BASE + 89;
XML_IOERROR = XML_BASE + 0;
XML_ENTITY_UNDEFINED = XML_BASE + 1;
XML_INFINITE_ENTITY_LOOP = XML_BASE + 2;
XML_NDATA_INVALID_PE = XML_BASE + 3;
XML_REQUIRED_NDATA = XML_BASE + 4;
XML_NDATA_INVALID_REF = XML_BASE + 5;
XML_EXTENT_IN_ATTR = XML_BASE + 6;
XML_STOPPED_BY_USER = XML_BASE + 7;
XML_PARSING_ENTITY = XML_BASE + 8;
XML_E_MISSING_PE_ENTITY = XML_BASE + 9;
XML_E_MIXEDCONTENT_DUP_NAME = XML_BASE + 10;
XML_NAME_COLON = XML_BASE + 11;
XML_ELEMENT_UNDECLARED = XML_BASE + 12;
XML_ELEMENT_ID_NOT_FOUND = XML_BASE + 13;
XML_DEFAULT_ATTRIBUTE = XML_BASE + 14;
XML_XMLNS_RESERVED = XML_BASE + 15;
XML_EMPTY_NOT_ALLOWED = XML_BASE + 16;
XML_ELEMENT_NOT_COMPLETE = XML_BASE + 17;
XML_ROOT_NAME_MISMATCH = XML_BASE + 18;
XML_INVALID_CONTENT = XML_BASE + 19;
XML_ATTRIBUTE_NOT_DEFINED = XML_BASE + 20;
XML_ATTRIBUTE_FIXED = XML_BASE + 21;
XML_ATTRIBUTE_VALUE = XML_BASE + 22;
XML_ILLEGAL_TEXT = XML_BASE + 23;
XML_MULTI_FIXED_VALUES = XML_BASE + 24;
XML_NOTATION_DEFINED = XML_BASE + 25;
XML_ELEMENT_DEFINED = XML_BASE + 26;
XML_ELEMENT_UNDEFINED = XML_BASE + 27;
XML_XMLNS_UNDEFINED = XML_BASE + 28;
XML_XMLNS_FIXED = XML_BASE + 29;
XML_E_UNKNOWNERROR = XML_BASE + 30;
XML_REQUIRED_ATTRIBUTE_MISSING = XML_BASE + 31;
XML_MISSING_NOTATION = XML_BASE + 32;
XML_ATTLIST_DUPLICATED_ID = XML_BASE + 33;
XML_ATTLIST_ID_PRESENCE = XML_BASE + 34;
XML_XMLLANG_INVALIDID = XML_BASE + 35;
XML_PUBLICID_INVALID = XML_BASE + 36;
XML_DTD_EXPECTING = XML_BASE + 37;
XML_NAMESPACE_URI_EMPTY = XML_BASE + 38;
XML_LOAD_EXTERNALENTITY = XML_BASE + 39;
XML_BAD_ENCODING = XML_BASE + 40;
type
EXMLException = class(Exception)
private
FDOMCode: Integer;
FXMLCode: Integer;
public
property DOMCode: Integer read FDOMCode;
property XMLCode: Integer read FXMLCode;
constructor CreateParseError(const DOMCode, XMLCode: Integer; const Args: array of const);
end;
{ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
{ }
{ S T A R T O F I N T E R F A C E D E C L A R A T I O N }
{ }
{ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
type
TOutputFormat = (ofNone, ofFlat, ofIndent);
IUnicodeStream = interface
['{F3ECA11F-EA18-491C-B59A-4203D5DC8CCA}']
// private
function GetCodePage: Word;
procedure SetCodePage(const CodePage: Word);
function GetOutputFormat: TOutputFormat;
procedure SetOutputFormat(const Value: TOutputFormat);
// public
procedure IncreaseIndent;
procedure DecreaseIndent;
procedure WriteIndent(const ForceNextLine: Boolean = False);
property OutputFormat: TOutputFormat read GetOutputFormat write SetOutputFormat;
property CodePage: Word read GetCodePage write SetCodePage;
procedure UndoRead;
function ProcessChar(var Char: WideChar): Boolean;
function GetNextString(var ReadString: WideString; const Len: Integer): Boolean;
procedure WriteOutputChar(const OutChar: WideChar);
function GetOutputBuffer: WideString;
function OutputBufferLen: Integer;
procedure ClearOutputBuffer;
procedure WriteString(Value: WideString);
end;
type
TStreamMode = (smRead, smWrite);
{$IFDEF LINUX}
TUnicodeStream = class(TMemoryStream)
private
FOutputStream: TStream;
public
constructor Create(const OutputStream: TStream);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -