123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617 |
- {
- This file is part of the Free Component Library
- Implementation of DOM interfaces
- Copyright (c) 1999-2000 by Sebastian Guenther, [email protected]
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- {
- This unit provides classes which implement the interfaces defined in the
- DOM (Document Object Model) specification.
- The current state is:
- DOM Level 1 - Almost completely implemented
- DOM Level 2 - Partially implemented
- Specification used for this implementation:
- "Document Object Model (DOM) Level 2 Specification Version 1.0
- W3C Candidate Recommendation 07 March, 2000"
- http://www.w3.org/TR/2000/CR-DOM-Level-2-20000307
- }
- unit DOM;
- {$MODE objfpc}
- {$H+}
- interface
- {off $DEFINE MEM_CHECK}
- uses
- {$IFDEF MEM_CHECK}MemCheck,{$ENDIF}
- SysUtils, Classes, AVL_Tree;
- type
- TDOMImplementation = class;
- TDOMDocumentFragment = class;
- TDOMDocument = class;
- TDOMNode = class;
- TDOMNodeList = class;
- TDOMNamedNodeMap = class;
- TDOMCharacterData = class;
- TDOMAttr = class;
- TDOMElement = class;
- TDOMText = class;
- TDOMComment = class;
- TDOMCDATASection = class;
- TDOMDocumentType = class;
- TDOMNotation = class;
- TDOMEntity = class;
- TDOMEntityReference = class;
- TDOMProcessingInstruction = class;
- // -------------------------------------------------------
- // DOMString
- // -------------------------------------------------------
- DOMString = WideString;
- DOMPChar = PWideChar;
- // -------------------------------------------------------
- // DOMException
- // -------------------------------------------------------
- const
- // DOM Level 1 exception codes:
- INDEX_SIZE_ERR = 1; // index or size is negative, or greater than the allowed value
- DOMSTRING_SIZE_ERR = 2; // Specified range of text does not fit into a DOMString
- HIERARCHY_REQUEST_ERR = 3; // node is inserted somewhere it does not belong
- WRONG_DOCUMENT_ERR = 4; // node is used in a different document than the one that created it (that does not support it)
- INVALID_CHARACTER_ERR = 5; // invalid or illegal character is specified, such as in a name
- NO_DATA_ALLOWED_ERR = 6; // data is specified for a node which does not support data
- NO_MODIFICATION_ALLOWED_ERR = 7; // an attempt is made to modify an object where modifications are not allowed
- NOT_FOUND_ERR = 8; // an attempt is made to reference a node in a context where it does not exist
- NOT_SUPPORTED_ERR = 9; // implementation does not support the type of object requested
- INUSE_ATTRIBUTE_ERR = 10; // an attempt is made to add an attribute that is already in use elsewhere
- // DOM Level 2 exception codes:
- INVALID_STATE_ERR = 11; // an attempt is made to use an object that is not, or is no longer, usable
- SYNTAX_ERR = 12; // invalid or illegal string specified
- INVALID_MODIFICATION_ERR = 13; // an attempt is made to modify the type of the underlying object
- NAMESPACE_ERR = 14; // an attempt is made to create or change an object in a way which is incorrect with regard to namespaces
- INVALID_ACCESS_ERR = 15; // parameter or operation is not supported by the underlying object
- type
- EDOMError = class(Exception)
- public
- constructor Create(ACode: Integer; const ASituation: String);
- Code: Integer;
- end;
- EDOMIndexSize = class(EDOMError)
- public
- constructor Create(const ASituation: String);
- end;
- EDOMHierarchyRequest = class(EDOMError)
- public
- constructor Create(const ASituation: String);
- end;
- EDOMWrongDocument = class(EDOMError)
- public
- constructor Create(const ASituation: String);
- end;
- EDOMNotFound = class(EDOMError)
- public
- constructor Create(const ASituation: String);
- end;
- EDOMNotSupported = class(EDOMError)
- public
- constructor Create(const ASituation: String);
- end;
- EDOMInUseAttribute = class(EDOMError)
- public
- constructor Create(const ASituation: String);
- end;
- EDOMInvalidState = class(EDOMError)
- public
- constructor Create(const ASituation: String);
- end;
- EDOMSyntax = class(EDOMError)
- public
- constructor Create(const ASituation: String);
- end;
- EDOMInvalidModification = class(EDOMError)
- public
- constructor Create(const ASituation: String);
- end;
- EDOMNamespace = class(EDOMError)
- public
- constructor Create(const ASituation: String);
- end;
- EDOMInvalidAccess = class(EDOMError)
- public
- constructor Create(const ASituation: String);
- end;
- // -------------------------------------------------------
- // Node
- // -------------------------------------------------------
- const
- ELEMENT_NODE = 1;
- ATTRIBUTE_NODE = 2;
- TEXT_NODE = 3;
- CDATA_SECTION_NODE = 4;
- ENTITY_REFERENCE_NODE = 5;
- ENTITY_NODE = 6;
- PROCESSING_INSTRUCTION_NODE = 7;
- COMMENT_NODE = 8;
- DOCUMENT_NODE = 9;
- DOCUMENT_TYPE_NODE = 10;
- DOCUMENT_FRAGMENT_NODE = 11;
- NOTATION_NODE = 12;
- type
- TRefClass = class
- protected
- RefCounter: LongInt;
- public
- constructor Create;
- function AddRef: LongInt; virtual;
- function Release: LongInt; virtual;
- end;
- TDOMNode = class
- protected
- FNodeName, FNodeValue: DOMString;
- FNodeType: Integer;
- FParentNode: TDOMNode;
- FPreviousSibling, FNextSibling: TDOMNode;
- FOwnerDocument: TDOMDocument;
- function GetNodeValue: DOMString; virtual;
- procedure SetNodeValue(const AValue: DOMString); virtual;
- function GetFirstChild: TDOMNode; virtual;
- function GetLastChild: TDOMNode; virtual;
- function GetAttributes: TDOMNamedNodeMap; virtual;
- public
- constructor Create(AOwner: TDOMDocument);
- // Free NodeList with TDOMNodeList.Release!
- function GetChildNodes: TDOMNodeList; virtual;
- property NodeName: DOMString read FNodeName;
- property NodeValue: DOMString read GetNodeValue write SetNodeValue;
- property NodeType: Integer read FNodeType;
- property ParentNode: TDOMNode read FParentNode;
- property FirstChild: TDOMNode read GetFirstChild;
- property LastChild: TDOMNode read GetLastChild;
- property ChildNodes: TDOMNodeList read GetChildNodes;
- property PreviousSibling: TDOMNode read FPreviousSibling;
- property NextSibling: TDOMNode read FNextSibling;
- property Attributes: TDOMNamedNodeMap read GetAttributes;
- property OwnerDocument: TDOMDocument read FOwnerDocument;
- function InsertBefore(NewChild, RefChild: TDOMNode): TDOMNode; virtual;
- function ReplaceChild(NewChild, OldChild: TDOMNode): TDOMNode; virtual;
- function RemoveChild(OldChild: TDOMNode): TDOMNode; virtual;
- function AppendChild(NewChild: TDOMNode): TDOMNode; virtual;
- function HasChildNodes: Boolean; virtual;
- function CloneNode(deep: Boolean): TDOMNode; overload;
- // Extensions to DOM interface:
- function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; overload; virtual;
- function FindNode(const ANodeName: DOMString): TDOMNode; virtual;
- end;
- { The following class is an implementation specific extension, it is just an
- extended implementation of TDOMNode, the generic DOM::Node interface
- implementation. (Its main purpose is to save memory in a big node tree) }
- TDOMNode_WithChildren = class(TDOMNode)
- protected
- FFirstChild, FLastChild: TDOMNode;
- FChildNodeTree: TAVLTree;
- function GetFirstChild: TDOMNode; override;
- function GetLastChild: TDOMNode; override;
- procedure CloneChildren(ACopy: TDOMNode; ACloneOwner: TDOMDocument);
- procedure AddToChildNodeTree(NewNode: TDOMNode);
- procedure RemoveFromChildNodeTree(OldNode: TDOMNode);
- public
- destructor Destroy; override;
- function InsertBefore(NewChild, RefChild: TDOMNode): TDOMNode; override;
- function ReplaceChild(NewChild, OldChild: TDOMNode): TDOMNode; override;
- function RemoveChild(OldChild: TDOMNode): TDOMNode; override;
- function AppendChild(NewChild: TDOMNode): TDOMNode; override;
- function HasChildNodes: Boolean; override;
- function FindNode(const ANodeName: DOMString): TDOMNode; override;
- end;
- // -------------------------------------------------------
- // NodeList
- // -------------------------------------------------------
- TDOMNodeList = class(TRefClass)
- protected
- node: TDOMNode;
- filter: DOMString;
- UseFilter: Boolean;
- function GetCount: LongWord;
- function GetItem(index: LongWord): TDOMNode;
- public
- constructor Create(ANode: TDOMNode; const AFilter: DOMString);
- property Item[index: LongWord]: TDOMNode read GetItem;
- property Count: LongWord read GetCount;
- end;
- // -------------------------------------------------------
- // NamedNodeMap
- // -------------------------------------------------------
- TDOMNamedNodeMap = class(TList)
- protected
- OwnerDocument: TDOMDocument;
- function GetItem(index: LongWord): TDOMNode;
- procedure SetItem(index: LongWord; AItem: TDOMNode);
- function GetLength: LongWord;
- public
- constructor Create(AOwner: TDOMDocument);
- function GetNamedItem(const name: DOMString): TDOMNode;
- function SetNamedItem(arg: TDOMNode): TDOMNode;
- function RemoveNamedItem(const name: DOMString): TDOMNode;
- property Item[index: LongWord]: TDOMNode read GetItem write SetItem; default;
- property Length: LongWord read GetLength;
- end;
- // -------------------------------------------------------
- // CharacterData
- // -------------------------------------------------------
- TDOMCharacterData = class(TDOMNode)
- protected
- function GetLength: LongWord;
- public
- property Data: DOMString read FNodeValue;
- property Length: LongWord read GetLength;
- function SubstringData(offset, count: LongWord): DOMString;
- procedure AppendData(const arg: DOMString);
- procedure InsertData(offset: LongWord; const arg: DOMString);
- procedure DeleteData(offset, count: LongWord);
- procedure ReplaceData(offset, count: LongWord; const arg: DOMString);
- end;
- // -------------------------------------------------------
- // DOMImplementation
- // -------------------------------------------------------
- TDOMImplementation = class
- public
- function HasFeature(const feature, version: DOMString): Boolean;
- // Introduced in DOM Level 2:
- function CreateDocumentType(const QualifiedName, PublicID,
- SystemID: DOMString): TDOMDocumentType;
- function CreateDocument(const NamespaceURI, QualifiedName: DOMString;
- doctype: TDOMDocumentType): TDOMDocument;
- end;
- // -------------------------------------------------------
- // DocumentFragment
- // -------------------------------------------------------
- TDOMDocumentFragment = class(TDOMNode_WithChildren)
- public
- constructor Create(AOwner: TDOMDocument);
- end;
- // -------------------------------------------------------
- // Document
- // -------------------------------------------------------
- TDOMDocument = class(TDOMNode_WithChildren)
- protected
- FDocType: TDOMDocumentType;
- FImplementation: TDOMImplementation;
- function GetDocumentElement: TDOMElement;
- public
- property DocType: TDOMDocumentType read FDocType;
- property Impl: TDOMImplementation read FImplementation;
- property DocumentElement: TDOMElement read GetDocumentElement;
- function CreateElement(const tagName: DOMString): TDOMElement; virtual;
- function CreateDocumentFragment: TDOMDocumentFragment;
- function CreateTextNode(const data: DOMString): TDOMText;
- function CreateComment(const data: DOMString): TDOMComment;
- function CreateCDATASection(const data: DOMString): TDOMCDATASection;
- virtual;
- function CreateProcessingInstruction(const target, data: DOMString):
- TDOMProcessingInstruction; virtual;
- function CreateAttribute(const name: DOMString): TDOMAttr; virtual;
- function CreateEntityReference(const name: DOMString): TDOMEntityReference;
- virtual;
- // Free NodeList with TDOMNodeList.Release!
- function GetElementsByTagName(const tagname: DOMString): TDOMNodeList;
- // Extensions to DOM interface:
- constructor Create;
- function CreateEntity(const data: DOMString): TDOMEntity;
- end;
- TXMLDocument = class(TDOMDocument)
- public
- // These fields are extensions to the DOM interface:
- XMLVersion, Encoding, StylesheetType, StylesheetHRef: DOMString;
- function CreateCDATASection(const data: DOMString): TDOMCDATASection; override;
- function CreateProcessingInstruction(const target, data: DOMString):
- TDOMProcessingInstruction; override;
- function CreateEntityReference(const name: DOMString): TDOMEntityReference; override;
- end;
- // -------------------------------------------------------
- // Attr
- // -------------------------------------------------------
- TDOMAttr = class(TDOMNode_WithChildren)
- protected
- FSpecified: Boolean;
- AttrOwner: TDOMNamedNodeMap;
- function GetNodeValue: DOMString; override;
- procedure SetNodeValue(const AValue: DOMString); override;
- public
- constructor Create(AOwner: TDOMDocument);
- function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; overload; override;
- property Name: DOMString read FNodeName;
- property Specified: Boolean read FSpecified;
- property Value: DOMString read GetNodeValue write SetNodeValue;
- end;
- // -------------------------------------------------------
- // Element
- // -------------------------------------------------------
- TDOMElement = class(TDOMNode_WithChildren)
- private
- FAttributes: TDOMNamedNodeMap;
- protected
- function GetAttributes: TDOMNamedNodeMap; override;
- public
- constructor Create(AOwner: TDOMDocument);
- destructor Destroy; override;
- function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; overload; override;
- property TagName: DOMString read FNodeName;
- function GetAttribute(const name: DOMString): DOMString;
- procedure SetAttribute(const name, value: DOMString);
- procedure RemoveAttribute(const name: DOMString);
- function GetAttributeNode(const name: DOMString): TDOMAttr;
- procedure SetAttributeNode(NewAttr: TDOMAttr);
- function RemoveAttributeNode(OldAttr: TDOMAttr): TDOMAttr;
- // Free NodeList with TDOMNodeList.Release!
- function GetElementsByTagName(const name: DOMString): TDOMNodeList;
- procedure Normalize;
- property AttribStrings[const Name: DOMString]: DOMString
- read GetAttribute write SetAttribute; default;
- end;
- // -------------------------------------------------------
- // Text
- // -------------------------------------------------------
- TDOMText = class(TDOMCharacterData)
- public
- constructor Create(AOwner: TDOMDocument);
- function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; overload; override;
- function SplitText(offset: LongWord): TDOMText;
- end;
- // -------------------------------------------------------
- // Comment
- // -------------------------------------------------------
- TDOMComment = class(TDOMCharacterData)
- public
- constructor Create(AOwner: TDOMDocument);
- function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; overload; override;
- end;
- // -------------------------------------------------------
- // CDATASection
- // -------------------------------------------------------
- TDOMCDATASection = class(TDOMText)
- public
- constructor Create(AOwner: TDOMDocument);
- function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; overload; override;
- end;
- // -------------------------------------------------------
- // DocumentType
- // -------------------------------------------------------
- TDOMDocumentType = class(TDOMNode)
- protected
- FEntities, FNotations: TDOMNamedNodeMap;
- public
- constructor Create(AOwner: TDOMDocument);
- function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; overload; override;
- property Name: DOMString read FNodeName;
- property Entities: TDOMNamedNodeMap read FEntities;
- property Notations: TDOMNamedNodeMap read FEntities;
- end;
- // -------------------------------------------------------
- // Notation
- // -------------------------------------------------------
- TDOMNotation = class(TDOMNode)
- protected
- FPublicID, FSystemID: DOMString;
- public
- constructor Create(AOwner: TDOMDocument);
- function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; overload; override;
- property PublicID: DOMString read FPublicID;
- property SystemID: DOMString read FSystemID;
- end;
- // -------------------------------------------------------
- // Entity
- // -------------------------------------------------------
- TDOMEntity = class(TDOMNode_WithChildren)
- protected
- FPublicID, FSystemID, FNotationName: DOMString;
- public
- constructor Create(AOwner: TDOMDocument);
- property PublicID: DOMString read FPublicID;
- property SystemID: DOMString read FSystemID;
- property NotationName: DOMString read FNotationName;
- end;
- // -------------------------------------------------------
- // EntityReference
- // -------------------------------------------------------
- TDOMEntityReference = class(TDOMNode_WithChildren)
- public
- constructor Create(AOwner: TDOMDocument);
- end;
- // -------------------------------------------------------
- // ProcessingInstruction
- // -------------------------------------------------------
- TDOMProcessingInstruction = class(TDOMNode)
- public
- constructor Create(AOwner: TDOMDocument);
- property Target: DOMString read FNodeName;
- property Data: DOMString read FNodeValue;
- end;
- // =======================================================
- // =======================================================
- implementation
- constructor TRefClass.Create;
- begin
- inherited Create;
- RefCounter := 1;
- end;
- function TRefClass.AddRef: LongInt;
- begin
- Inc(RefCounter);
- Result := RefCounter;
- end;
- function TRefClass.Release: LongInt;
- begin
- Dec(RefCounter);
- Result := RefCounter;
- if RefCounter <= 0 then Free;
- end;
- // -------------------------------------------------------
- // DOM Exception
- // -------------------------------------------------------
- constructor EDOMError.Create(ACode: Integer; const ASituation: String);
- begin
- Code := ACode;
- inherited Create(Self.ClassName + ' in ' + ASituation);
- end;
- constructor EDOMIndexSize.Create(const ASituation: String); // 1
- begin
- inherited Create(INDEX_SIZE_ERR, ASituation);
- end;
- constructor EDOMHierarchyRequest.Create(const ASituation: String); // 3
- begin
- inherited Create(HIERARCHY_REQUEST_ERR, ASituation);
- end;
- constructor EDOMWrongDocument.Create(const ASituation: String); // 4
- begin
- inherited Create(WRONG_DOCUMENT_ERR, ASituation);
- end;
- constructor EDOMNotFound.Create(const ASituation: String); // 8
- begin
- inherited Create(NOT_FOUND_ERR, ASituation);
- end;
- constructor EDOMNotSupported.Create(const ASituation: String); // 9
- begin
- inherited Create(NOT_SUPPORTED_ERR, ASituation);
- end;
- constructor EDOMInUseAttribute.Create(const ASituation: String); // 10
- begin
- inherited Create(INUSE_ATTRIBUTE_ERR, ASituation);
- end;
- constructor EDOMInvalidState.Create(const ASituation: String); // 11
- begin
- inherited Create(INVALID_STATE_ERR, ASituation);
- end;
- constructor EDOMSyntax.Create(const ASituation: String); // 12
- begin
- inherited Create(SYNTAX_ERR, ASituation);
- end;
- constructor EDOMInvalidModification.Create(const ASituation: String); // 13
- begin
- inherited Create(INVALID_MODIFICATION_ERR, ASituation);
- end;
- constructor EDOMNamespace.Create(const ASituation: String); // 14
- begin
- inherited Create(NAMESPACE_ERR, ASituation);
- end;
- constructor EDOMInvalidAccess.Create(const ASituation: String); // 15
- begin
- inherited Create(INVALID_ACCESS_ERR, ASituation);
- end;
- // -------------------------------------------------------
- // Node
- // -------------------------------------------------------
- constructor TDOMNode.Create(AOwner: TDOMDocument);
- begin
- FOwnerDocument := AOwner;
- inherited Create;
- end;
- function TDOMNode.GetNodeValue: DOMString;
- begin
- Result := FNodeValue;
- end;
- procedure TDOMNode.SetNodeValue(const AValue: DOMString);
- begin
- FNodeValue := AValue;
- end;
- function TDOMNode.GetChildNodes: TDOMNodeList;
- begin
- Result := TDOMNodeList.Create(Self, '*');
- end;
- function TDOMNode.GetFirstChild: TDOMNode;
- begin
- Result := nil;
- end;
- function TDOMNode.GetLastChild: TDOMNode;
- begin
- Result := nil;
- end;
- function TDOMNode.GetAttributes: TDOMNamedNodeMap;
- begin
- Result := nil;
- end;
- function TDOMNode.InsertBefore(NewChild, RefChild: TDOMNode): TDOMNode;
- begin
- raise EDOMHierarchyRequest.Create('Node.InsertBefore');
- if (NewChild=nil) and (RefChild=nil) then ;
- Result:=nil;
- end;
- function TDOMNode.ReplaceChild(NewChild, OldChild: TDOMNode): TDOMNode;
- begin
- raise EDOMHierarchyRequest.Create('Node.ReplaceChild');
- if (NewChild=nil) and (OldChild=nil) then ;
- Result:=nil;
- end;
- function TDOMNode.RemoveChild(OldChild: TDOMNode): TDOMNode;
- begin
- raise EDOMHierarchyRequest.Create('Node.RemoveChild');
- if (OldChild=nil) then ;
- Result:=nil;
- end;
- function TDOMNode.AppendChild(NewChild: TDOMNode): TDOMNode;
- begin
- raise EDOMHierarchyRequest.Create('Node.AppendChild');
- if (NewChild=nil) then ;
- Result:=nil;
- end;
- function TDOMNode.HasChildNodes: Boolean;
- begin
- Result := False;
- end;
- function TDOMNode.CloneNode(deep: Boolean): TDOMNode;
- begin
- Result:=CloneNode(deep, FOwnerDocument);
- if deep then ;
- end;
- function TDOMNode.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
- begin
- raise EDOMNotSupported.Create('CloneNode not implemented for ' + ClassName);
- if (deep) and (ACloneOwner=nil) then ;
- Result:=nil;
- end;
- function TDOMNode.FindNode(const ANodeName: DOMString): TDOMNode;
- var
- child: TDOMNode;
- begin
- child := FirstChild;
- while Assigned(child) do
- begin
- if child.NodeName = ANodeName then
- begin
- Result := child;
- exit;
- end;
- child := child.NextSibling;
- end;
- Result := nil;
- end;
- //------------------------------------------------------------------------------
- function CompareDOMStrings(const s1, s2: DOMPChar; l1, l2: integer): integer;
- var i: integer;
- begin
- Result:=l1-l2;
- i:=0;
- while (i<l1) and (Result=0) do begin
- Result:=ord(s1[i])-ord(s2[i]);
- inc(i);
- end;
- end;
- function CompareDOMNodeWithDOMNode(Node1, Node2: Pointer): integer;
- begin
- Result:=CompareDOMStrings(DOMPChar(TDOMNode(Node1).NodeName),
- DOMPChar(TDOMNode(Node2).NodeName),
- length(TDOMNode(Node1).NodeName),
- length(TDOMNode(Node2).NodeName)
- );
- end;
- function CompareDOMStringWithDOMNode(AKey, ANode: Pointer): integer;
- begin
- Result:=CompareDOMStrings(DOMPChar(AKey),
- DOMPChar(TDOMNode(ANode).NodeName),
- length(DOMString(AKey)),
- length(TDOMNode(ANode).NodeName)
- );
- end;
- function TDOMNode_WithChildren.GetFirstChild: TDOMNode;
- begin
- Result := FFirstChild;
- end;
- function TDOMNode_WithChildren.GetLastChild: TDOMNode;
- begin
- Result := FLastChild;
- end;
- destructor TDOMNode_WithChildren.Destroy;
- var
- child, next: TDOMNode;
- begin
- if FChildNodeTree<>nil then begin
- FChildNodeTree.Free;
- FChildNodeTree:=nil;
- end;
- child := FirstChild;
- while Assigned(child) do
- begin
- next := child.NextSibling;
- child.Free;
- child := next;
- end;
- inherited Destroy;
- end;
- function TDOMNode_WithChildren.InsertBefore(NewChild, RefChild: TDOMNode):
- TDOMNode;
- begin
- Result := NewChild;
- if not Assigned(RefChild) then
- begin
- AppendChild(NewChild);
- exit;
- end;
- if NewChild.FOwnerDocument <> FOwnerDocument then
- raise EDOMWrongDocument.Create('NodeWC.InsertBefore');
- if RefChild.ParentNode <> Self then
- raise EDOMHierarchyRequest.Create('NodeWC.InsertBefore');
- if NewChild.NodeType = DOCUMENT_FRAGMENT_NODE then
- raise EDOMNotSupported.Create('NodeWC.InsertBefore for DocumentFragment');
- NewChild.FNextSibling := RefChild;
- if RefChild = FFirstChild then
- FFirstChild := NewChild
- else
- begin
- RefChild.FPreviousSibling.FNextSibling := NewChild;
- NewChild.FPreviousSibling := RefChild.FPreviousSibling;
- end;
- RefChild.FPreviousSibling := NewChild;
- NewChild.FParentNode := Self;
- AddToChildNodeTree(NewChild);
- end;
- function TDOMNode_WithChildren.ReplaceChild(NewChild, OldChild: TDOMNode):
- TDOMNode;
- begin
- RemoveFromChildNodeTree(OldChild);
- InsertBefore(NewChild, OldChild);
- if Assigned(OldChild) then
- RemoveChild(OldChild);
- Result := NewChild;
- end;
- function TDOMNode_WithChildren.RemoveChild(OldChild: TDOMNode):
- TDOMNode;
- begin
- if OldChild.ParentNode <> Self then
- raise EDOMHierarchyRequest.Create('NodeWC.RemoveChild');
- if OldChild = FFirstChild then
- FFirstChild := FFirstChild.NextSibling
- else
- OldChild.FPreviousSibling.FNextSibling := OldChild.FNextSibling;
- if OldChild = FLastChild then
- FLastChild := FLastChild.FPreviousSibling
- else
- OldChild.FNextSibling.FPreviousSibling := OldChild.FPreviousSibling;
- RemoveFromChildNodeTree(OldChild);
- OldChild.Free;
- Result:=nil;
- end;
- function TDOMNode_WithChildren.AppendChild(NewChild: TDOMNode): TDOMNode;
- var
- Parent: TDOMNode;
- begin
- if NewChild.FOwnerDocument <> FOwnerDocument then
- raise EDOMWrongDocument.Create('NodeWC.AppendChild');
- Parent := Self;
- while Assigned(Parent) do
- begin
- if Parent = NewChild then
- raise EDOMHierarchyRequest.Create('NodeWC.AppendChild (cycle in tree)');
- Parent := Parent.ParentNode;
- end;
- if NewChild.FParentNode = Self then
- RemoveChild(NewChild);
- if NewChild.NodeType = DOCUMENT_FRAGMENT_NODE then
- raise EDOMNotSupported.Create('NodeWC.AppendChild for DocumentFragments')
- else begin
- if Assigned(FFirstChild) then
- begin
- FLastChild.FNextSibling := NewChild;
- NewChild.FPreviousSibling := FLastChild;
- end else
- FFirstChild := NewChild;
- FLastChild := NewChild;
- NewChild.FParentNode := Self;
- end;
- AddToChildNodeTree(NewChild);
- Result := NewChild;
- end;
- function TDOMNode_WithChildren.HasChildNodes: Boolean;
- begin
- Result := Assigned(FFirstChild);
- end;
- function TDOMNode_WithChildren.FindNode(const ANodeName: DOMString): TDOMNode;
- var AVLNode: TAVLTreeNode;
- begin
- Result:=nil;
- if FChildNodeTree<>nil then begin
- AVLNode:=FChildNodeTree.FindKey(DOMPChar(ANodeName),
- @CompareDOMStringWithDOMNode);
- if AVLNode<>nil then
- Result:=TDOMNode(AVLNode.Data);
- end;
- end;
- procedure TDOMNode_WithChildren.CloneChildren(ACopy: TDOMNode;
- ACloneOwner: TDOMDocument);
- var
- node: TDOMNode;
- begin
- node := FirstChild;
- while Assigned(node) do
- begin
- ACopy.AppendChild(node.CloneNode(True, ACloneOwner));
- node := node.NextSibling;
- end;
- end;
- procedure TDOMNode_WithChildren.AddToChildNodeTree(NewNode: TDOMNode);
- begin
- if FChildNodeTree=nil then
- FChildNodeTree:=TAVLTree.Create(@CompareDOMNodeWithDOMNode);
- if FChildNodeTree.Find(NewNode)=nil then
- FChildNodeTree.Add(NewNode);
- end;
- procedure TDOMNode_WithChildren.RemoveFromChildNodeTree(OldNode: TDOMNode);
- begin
- if FChildNodeTree<>nil then
- FChildNodeTree.Remove(OldNode);
- end;
- // -------------------------------------------------------
- // NodeList
- // -------------------------------------------------------
- constructor TDOMNodeList.Create(ANode: TDOMNode; const AFilter: DOMString);
- begin
- inherited Create;
- node := ANode;
- filter := AFilter;
- UseFilter := filter <> '*';
- end;
- function TDOMNodeList.GetCount: LongWord;
- var
- child: TDOMNode;
- begin
- Result := 0;
- child := node.FirstChild;
- while Assigned(child) do
- begin
- if (not UseFilter) or (child.NodeName = filter) then
- Inc(Result);
- child := child.NextSibling;
- end;
- end;
- function TDOMNodeList.GetItem(index: LongWord): TDOMNode;
- var
- child: TDOMNode;
- begin
- Result := nil;
- child := node.FirstChild;
- while Assigned(child) do
- begin
- if index = 0 then
- begin
- Result := child;
- break;
- end;
- if (not UseFilter) or (child.NodeName = filter) then
- Dec(index);
- child := child.NextSibling;
- end;
- end;
- // -------------------------------------------------------
- // NamedNodeMap
- // -------------------------------------------------------
- constructor TDOMNamedNodeMap.Create(AOwner: TDOMDocument);
- begin
- inherited Create;
- OwnerDocument := AOwner;
- end;
- function TDOMNamedNodeMap.GetItem(index: LongWord): TDOMNode;
- begin
- Result := TDOMNode(Items[index]);
- end;
- procedure TDOMNamedNodeMap.SetItem(index: LongWord; AItem: TDOMNode);
- begin
- Items[index] := AItem;
- end;
- function TDOMNamedNodeMap.GetLength: LongWord;
- begin
- Result := Count;
- end;
- function TDOMNamedNodeMap.GetNamedItem(const name: DOMString): TDOMNode;
- var
- i: Integer;
- begin
- for i := 0 to Count - 1 do
- begin
- Result := Item[i];
- if Result.NodeName = name then
- exit;
- end;
- Result := nil;
- end;
- function TDOMNamedNodeMap.SetNamedItem(arg: TDOMNode): TDOMNode;
- var
- i: Integer;
- begin
- if arg.FOwnerDocument <> OwnerDocument then
- raise EDOMWrongDocument.Create('NamedNodeMap.SetNamedItem');
- if arg.NodeType = ATTRIBUTE_NODE then
- begin
- if Assigned(TDOMAttr(arg).AttrOwner) then
- raise EDOMInUseAttribute.Create('NamedNodeMap.SetNamedItem');
- TDOMAttr(arg).AttrOwner := Self;
- end;
- for i := 0 to Count - 1 do
- if Item[i].NodeName = arg.NodeName then
- begin
- Result := Item[i];
- Item[i] := arg;
- exit;
- end;
- Add(arg);
- Result := nil;
- end;
- function TDOMNamedNodeMap.RemoveNamedItem(const name: DOMString): TDOMNode;
- var
- i: Integer;
- begin
- for i := 0 to Count - 1 do
- if Item[i].NodeName = name then
- begin
- Result := Item[i];
- Result.FParentNode := nil;
- exit;
- end;
- raise EDOMNotFound.Create('NamedNodeMap.RemoveNamedItem');
- end;
- // -------------------------------------------------------
- // CharacterData
- // -------------------------------------------------------
- function TDOMCharacterData.GetLength: LongWord;
- begin
- Result := system.Length(FNodeValue);
- end;
- function TDOMCharacterData.SubstringData(offset, count: LongWord): DOMString;
- begin
- if (offset > Length) then
- raise EDOMIndexSize.Create('CharacterData.SubstringData');
- Result := Copy(FNodeValue, offset + 1, count);
- end;
- procedure TDOMCharacterData.AppendData(const arg: DOMString);
- begin
- FNodeValue := FNodeValue + arg;
- end;
- procedure TDOMCharacterData.InsertData(offset: LongWord; const arg: DOMString);
- begin
- if (offset > Length) then
- raise EDOMIndexSize.Create('CharacterData.InsertData');
- FNodeValue := Copy(FNodeValue, 1, offset) + arg +
- Copy(FNodeValue, offset + 1, Length);
- end;
- procedure TDOMCharacterData.DeleteData(offset, count: LongWord);
- begin
- if (offset > Length) then
- raise EDOMIndexSize.Create('CharacterData.DeleteData');
- FNodeValue := Copy(FNodeValue, 1, offset) +
- Copy(FNodeValue, offset + count + 1, Length);
- end;
- procedure TDOMCharacterData.ReplaceData(offset, count: LongWord; const arg: DOMString);
- begin
- DeleteData(offset, count);
- InsertData(offset, arg);
- end;
- // -------------------------------------------------------
- // DocumentFragmet
- // -------------------------------------------------------
- constructor TDOMDocumentFragment.Create(AOwner: TDOMDocument);
- begin
- FNodeType := DOCUMENT_FRAGMENT_NODE;
- FNodeName := '#document-fragment';
- inherited Create(AOwner);
- end;
- // -------------------------------------------------------
- // DOMImplementation
- // -------------------------------------------------------
- function TDOMImplementation.HasFeature(const feature, version: DOMString):
- Boolean;
- begin
- Result := False;
- if (feature='') and (version='') then ;
- end;
- function TDOMImplementation.CreateDocumentType(const QualifiedName, PublicID,
- SystemID: DOMString): TDOMDocumentType;
- begin
- // !!!: Implement this method (easy to do)
- raise EDOMNotSupported.Create('DOMImplementation.CreateDocumentType');
- if (QualifiedName='') and (PublicID='') and (SystemID='') then ;
- Result:=nil;
- end;
- function TDOMImplementation.CreateDocument(const NamespaceURI,
- QualifiedName: DOMString; doctype: TDOMDocumentType): TDOMDocument;
- begin
- // !!!: Implement this method (easy to do)
- raise EDOMNotSupported.Create('DOMImplementation.CreateDocument');
- if (NamespaceURI='') and (QualifiedName='') and (doctype=nil) then ;
- Result:=nil;
- end;
- // -------------------------------------------------------
- // Document
- // -------------------------------------------------------
- constructor TDOMDocument.Create;
- begin
- FNodeType := DOCUMENT_NODE;
- FNodeName := '#document';
- inherited Create(nil);
- FOwnerDocument := Self;
- end;
- function TDOMDocument.GetDocumentElement: TDOMElement;
- var
- node: TDOMNode;
- begin
- node := FFirstChild;
- while Assigned(node) do
- begin
- if node.FNodeType = ELEMENT_NODE then
- begin
- Result := TDOMElement(node);
- exit;
- end;
- node := node.NextSibling;
- end;
- Result := nil;
- end;
- function TDOMDocument.CreateElement(const tagName: DOMString): TDOMElement;
- begin
- Result := TDOMElement.Create(Self);
- Result.FNodeName := tagName;
- end;
- function TDOMDocument.CreateDocumentFragment: TDOMDocumentFragment;
- begin
- Result := TDOMDocumentFragment.Create(Self);
- end;
- function TDOMDocument.CreateTextNode(const data: DOMString): TDOMText;
- begin
- Result := TDOMText.Create(Self);
- Result.FNodeValue := data;
- end;
- function TDOMDocument.CreateComment(const data: DOMString): TDOMComment;
- begin
- Result := TDOMComment.Create(Self);
- Result.FNodeValue := data;
- end;
- function TDOMDocument.CreateCDATASection(const data: DOMString):
- TDOMCDATASection;
- begin
- raise EDOMNotSupported.Create('DOMDocument.CreateCDATASection');
- if data='' then ;
- Result:=nil;
- end;
- function TDOMDocument.CreateProcessingInstruction(const target,
- data: DOMString): TDOMProcessingInstruction;
- begin
- raise EDOMNotSupported.Create('DOMDocument.CreateProcessingInstruction');
- if (target='') and (data='') then ;
- Result:=nil;
- end;
- function TDOMDocument.CreateAttribute(const name: DOMString): TDOMAttr;
- begin
- Result := TDOMAttr.Create(Self);
- Result.FNodeName := name;
- end;
- function TDOMDocument.CreateEntityReference(const name: DOMString):
- TDOMEntityReference;
- begin
- raise EDOMNotSupported.Create('DOMDocument.CreateEntityReference');
- if name='' then ;
- Result:=nil;
- end;
- function TDOMDocument.CreateEntity(const data: DOMString): TDOMEntity;
- begin
- Result := TDOMEntity.Create(Self);
- Result.FNodeName := data;
- end;
- function TDOMDocument.GetElementsByTagName(const tagname: DOMString): TDOMNodeList;
- begin
- Result := TDOMNodeList.Create(Self, tagname);
- end;
- function TXMLDocument.CreateCDATASection(const data: DOMString):
- TDOMCDATASection;
- begin
- Result := TDOMCDATASection.Create(Self);
- Result.FNodeValue := data;
- end;
- function TXMLDocument.CreateProcessingInstruction(const target,
- data: DOMString): TDOMProcessingInstruction;
- begin
- Result := TDOMProcessingInstruction.Create(Self);
- Result.FNodeName := target;
- Result.FNodeValue := data;
- end;
- function TXMLDocument.CreateEntityReference(const name: DOMString):
- TDOMEntityReference;
- begin
- Result := TDOMEntityReference.Create(Self);
- Result.FNodeName := name;
- end;
- // -------------------------------------------------------
- // Attr
- // -------------------------------------------------------
- constructor TDOMAttr.Create(AOwner: TDOMDocument);
- begin
- FNodeType := ATTRIBUTE_NODE;
- inherited Create(AOwner);
- end;
- function TDOMAttr.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
- begin
- Result := TDOMAttr.Create(ACloneOwner);
- Result.FNodeName := FNodeName;
- TDOMAttr(Result).FSpecified := FSpecified;
- if deep then
- CloneChildren(Result, ACloneOwner);
- end;
- function TDOMAttr.GetNodeValue: DOMString;
- var
- child: TDOMNode;
- begin
- SetLength(Result, 0);
- if Assigned(FFirstChild) then
- begin
- child := FFirstChild;
- while Assigned(child) do
- begin
- if child.NodeType = ENTITY_REFERENCE_NODE then
- Result := Result + '&' + child.NodeName + ';'
- else
- Result := Result + child.NodeValue;
- child := child.NextSibling;
- end;
- end;
- end;
- procedure TDOMAttr.SetNodeValue(const AValue: DOMString);
- var
- tn: TDOMText;
- begin
- FSpecified := True;
- tn := TDOMText.Create(FOwnerDocument);
- tn.FNodeValue := AValue;
- if Assigned(FFirstChild) then
- ReplaceChild(tn, FFirstChild)
- else
- AppendChild(tn);
- end;
- // -------------------------------------------------------
- // Element
- // -------------------------------------------------------
- constructor TDOMElement.Create(AOwner: TDOMDocument);
- begin
- FNodeType := ELEMENT_NODE;
- inherited Create(AOwner);
- end;
- destructor TDOMElement.Destroy;
- var
- i: Integer;
- begin
- {As the attributes are _not_ childs of the element node, we have to free
- them manually here:}
- if FAttributes<>nil then begin
- for i := 0 to FAttributes.Count - 1 do
- FAttributes[i].Free;
- FAttributes.Free;
- FAttributes:=nil;
- end;
- inherited Destroy;
- end;
- function TDOMElement.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
- var
- i: Integer;
- begin
- Result := TDOMElement.Create(ACloneOwner);
- Result.FNodeName := FNodeName;
- if FAttributes<>nil then begin
- TDOMElement(Result).GetAttributes;
- for i := 0 to FAttributes.Count - 1 do
- TDOMElement(Result).FAttributes.Add(FAttributes[i].CloneNode(True, ACloneOwner));
- end;
- if deep then
- CloneChildren(Result, ACloneOwner);
- end;
- function TDOMElement.GetAttributes: TDOMNamedNodeMap;
- begin
- if FAttributes=nil then
- FAttributes := TDOMNamedNodeMap.Create(FOwnerDocument);
- Result := FAttributes;
- end;
- function TDOMElement.GetAttribute(const name: DOMString): DOMString;
- var
- i: Integer;
- begin
- if FAttributes<>nil then begin
- for i := 0 to FAttributes.Count - 1 do
- if FAttributes[i].NodeName = name then
- begin
- Result := FAttributes[i].NodeValue;
- exit;
- end;
- end;
- SetLength(Result, 0);
- end;
- procedure TDOMElement.SetAttribute(const name, value: DOMString);
- var
- i: Integer;
- attr: TDOMAttr;
- begin
- GetAttributes;
- for i := 0 to FAttributes.Count - 1 do
- if FAttributes[i].NodeName = name then
- begin
- FAttributes[i].NodeValue := value;
- exit;
- end;
- attr := TDOMAttr.Create(FOwnerDocument);
- attr.FNodeName := name;
- attr.NodeValue := value;
- FAttributes.Add(attr);
- end;
- procedure TDOMElement.RemoveAttribute(const name: DOMString);
- var
- i: Integer;
- begin
- if FAttributes=nil then exit;
- for i := 0 to FAttributes.Count - 1 do
- if FAttributes[i].NodeName = name then
- begin
- FAttributes[i].Free;
- FAttributes.Delete(i);
- exit;
- end;
- end;
- function TDOMElement.GetAttributeNode(const name: DOMString): TDOMAttr;
- var
- i: Integer;
- begin
- if FAttributes<>nil then begin
- for i := 0 to FAttributes.Count - 1 do
- if FAttributes[i].NodeName = name then
- begin
- Result := TDOMAttr(FAttributes[i]);
- exit;
- end;
- end;
- Result := nil;
- end;
- procedure TDOMElement.SetAttributeNode(NewAttr: TDOMAttr);
- var
- i: Integer;
- begin
- if FAttributes=nil then exit;
- for i := 0 to FAttributes.Count - 1 do
- if FAttributes[i].NodeName = NewAttr.NodeName then
- begin
- FAttributes[i].Free;
- FAttributes[i] := NewAttr;
- exit;
- end;
- end;
- function TDOMElement.RemoveAttributeNode(OldAttr: TDOMAttr): TDOMAttr;
- var
- i: Integer;
- node: TDOMNode;
- begin
- Result:=nil;
- if FAttributes=nil then exit;
- for i := 0 to FAttributes.Count - 1 do
- begin
- node := FAttributes[i];
- if node = OldAttr then
- begin
- FAttributes.Delete(i);
- Result := TDOMAttr(node);
- exit;
- end;
- end;
- end;
- function TDOMElement.GetElementsByTagName(const name: DOMString): TDOMNodeList;
- begin
- Result := TDOMNodeList.Create(Self, name);
- end;
- procedure TDOMElement.Normalize;
- begin
- // !!!: Not implemented
- end;
- // -------------------------------------------------------
- // Text
- // -------------------------------------------------------
- constructor TDOMText.Create(AOwner: TDOMDocument);
- begin
- FNodeType := TEXT_NODE;
- FNodeName := '#text';
- inherited Create(AOwner);
- end;
- function TDOMText.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
- begin
- Result := TDOMText.Create(ACloneOwner);
- Result.FNodeValue := FNodeValue;
- if deep and (ACloneOwner=nil) then ;
- end;
- function TDOMText.SplitText(offset: LongWord): TDOMText;
- begin
- if offset > Length then
- raise EDOMIndexSize.Create('Text.SplitText');
- Result := TDOMText.Create(FOwnerDocument);
- Result.FNodeValue := Copy(FNodeValue, offset + 1, Length);
- FNodeValue := Copy(FNodeValue, 1, offset);
- FParentNode.InsertBefore(Result, FNextSibling);
- end;
- // -------------------------------------------------------
- // Comment
- // -------------------------------------------------------
- constructor TDOMComment.Create(AOwner: TDOMDocument);
- begin
- FNodeType := COMMENT_NODE;
- FNodeName := '#comment';
- inherited Create(AOwner);
- end;
- function TDOMComment.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
- begin
- Result := TDOMComment.Create(ACloneOwner);
- Result.FNodeValue := FNodeValue;
- if deep and (ACloneOwner=nil) then ;
- end;
- // -------------------------------------------------------
- // CDATASection
- // -------------------------------------------------------
- constructor TDOMCDATASection.Create(AOwner: TDOMDocument);
- begin
- inherited Create(AOwner);
- FNodeType := CDATA_SECTION_NODE;
- FNodeName := '#cdata-section';
- end;
- function TDOMCDATASection.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
- begin
- Result := TDOMCDATASection.Create(ACloneOwner);
- Result.FNodeValue := FNodeValue;
- if deep and (ACloneOwner=nil) then ;
- end;
- // -------------------------------------------------------
- // DocumentType
- // -------------------------------------------------------
- constructor TDOMDocumentType.Create(AOwner: TDOMDocument);
- begin
- FNodeType := DOCUMENT_TYPE_NODE;
- inherited Create(AOwner);
- end;
- function TDOMDocumentType.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
- begin
- Result := TDOMDocumentType.Create(ACloneOwner);
- Result.FNodeName := FNodeName;
- if deep and (ACloneOwner=nil) then ;
- end;
- // -------------------------------------------------------
- // Notation
- // -------------------------------------------------------
- constructor TDOMNotation.Create(AOwner: TDOMDocument);
- begin
- FNodeType := NOTATION_NODE;
- inherited Create(AOwner);
- end;
- function TDOMNotation.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
- begin
- Result := TDOMNotation.Create(ACloneOwner);
- Result.FNodeName := FNodeName;
- if deep and (ACloneOwner=nil) then ;
- end;
- // -------------------------------------------------------
- // Entity
- // -------------------------------------------------------
- constructor TDOMEntity.Create(AOwner: TDOMDocument);
- begin
- FNodeType := ENTITY_NODE;
- inherited Create(AOwner);
- end;
- // -------------------------------------------------------
- // EntityReference
- // -------------------------------------------------------
- constructor TDOMEntityReference.Create(AOwner: TDOMDocument);
- begin
- FNodeType := ENTITY_REFERENCE_NODE;
- inherited Create(AOwner);
- end;
- // -------------------------------------------------------
- // ProcessingInstruction
- // -------------------------------------------------------
- constructor TDOMProcessingInstruction.Create(AOwner: TDOMDocument);
- begin
- FNodeType := PROCESSING_INSTRUCTION_NODE;
- inherited Create(AOwner);
- end;
- end.
|