dom.pp 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517
  1. {
  2. $Id$
  3. This file is part of the Free Component Library
  4. Implementation of DOM interfaces
  5. Copyright (c) 1999-2000 by Sebastian Guenther, [email protected]
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. This unit provides classes which implement the interfaces defined in the
  14. DOM (Document Object Model) specification.
  15. The current state is:
  16. DOM Level 1 - Almost completely implemented
  17. DOM Level 2 - Partially implemented
  18. Specification used for this implementation:
  19. "Document Object Model (DOM) Level 2 Specification Version 1.0
  20. W3C Candidate Recommendation 07 March, 2000"
  21. http://www.w3.org/TR/2000/CR-DOM-Level-2-20000307
  22. }
  23. unit DOM;
  24. {$MODE objfpc}
  25. {$H+}
  26. interface
  27. uses SysUtils, Classes;
  28. type
  29. TDOMImplementation = class;
  30. TDOMDocumentFragment = class;
  31. TDOMDocument = class;
  32. TDOMNode = class;
  33. TDOMNodeList = class;
  34. TDOMNamedNodeMap = class;
  35. TDOMCharacterData = class;
  36. TDOMAttr = class;
  37. TDOMElement = class;
  38. TDOMText = class;
  39. TDOMComment = class;
  40. TDOMCDATASection = class;
  41. TDOMDocumentType = class;
  42. TDOMNotation = class;
  43. TDOMEntity = class;
  44. TDOMEntityReference = class;
  45. TDOMProcessingInstruction = class;
  46. // -------------------------------------------------------
  47. // DOMString
  48. // -------------------------------------------------------
  49. DOMString = String; // !!!: should be WideString as soon as this is supported by the compiler
  50. // -------------------------------------------------------
  51. // DOMException
  52. // -------------------------------------------------------
  53. const
  54. // DOM Level 1 exception codes:
  55. INDEX_SIZE_ERR = 1; // index or size is negative, or greater than the allowed value
  56. DOMSTRING_SIZE_ERR = 2; // Specified range of text does not fit into a DOMString
  57. HIERARCHY_REQUEST_ERR = 3; // node is inserted somewhere it does not belong
  58. WRONG_DOCUMENT_ERR = 4; // node is used in a different document than the one that created it (that does not support it)
  59. INVALID_CHARACTER_ERR = 5; // invalid or illegal character is specified, such as in a name
  60. NO_DATA_ALLOWED_ERR = 6; // data is specified for a node which does not support data
  61. NO_MODIFICATION_ALLOWED_ERR = 7; // an attempt is made to modify an object where modifications are not allowed
  62. NOT_FOUND_ERR = 8; // an attempt is made to reference a node in a context where it does not exist
  63. NOT_SUPPORTED_ERR = 9; // implementation does not support the type of object requested
  64. INUSE_ATTRIBUTE_ERR = 10; // an attempt is made to add an attribute that is already in use elsewhere
  65. // DOM Level 2 exception codes:
  66. INVALID_STATE_ERR = 11; // an attempt is made to use an object that is not, or is no longer, usable
  67. SYNTAX_ERR = 12; // invalid or illegal string specified
  68. INVALID_MODIFICATION_ERR = 13; // an attempt is made to modify the type of the underlying object
  69. NAMESPACE_ERR = 14; // an attempt is made to create or change an object in a way which is incorrect with regard to namespaces
  70. INVALID_ACCESS_ERR = 15; // parameter or operation is not supported by the underlying object
  71. type
  72. EDOMError = class(Exception)
  73. protected
  74. constructor Create(ACode: Integer; const ASituation: String);
  75. public
  76. Code: Integer;
  77. end;
  78. EDOMIndexSize = class(EDOMError)
  79. public
  80. constructor Create(const ASituation: String);
  81. end;
  82. EDOMHierarchyRequest = class(EDOMError)
  83. public
  84. constructor Create(const ASituation: String);
  85. end;
  86. EDOMWrongDocument = class(EDOMError)
  87. public
  88. constructor Create(const ASituation: String);
  89. end;
  90. EDOMNotFound = class(EDOMError)
  91. public
  92. constructor Create(const ASituation: String);
  93. end;
  94. EDOMNotSupported = class(EDOMError)
  95. public
  96. constructor Create(const ASituation: String);
  97. end;
  98. EDOMInUseAttribute = class(EDOMError)
  99. public
  100. constructor Create(const ASituation: String);
  101. end;
  102. EDOMInvalidState = class(EDOMError)
  103. public
  104. constructor Create(const ASituation: String);
  105. end;
  106. EDOMSyntax = class(EDOMError)
  107. public
  108. constructor Create(const ASituation: String);
  109. end;
  110. EDOMInvalidModification = class(EDOMError)
  111. public
  112. constructor Create(const ASituation: String);
  113. end;
  114. EDOMNamespace = class(EDOMError)
  115. public
  116. constructor Create(const ASituation: String);
  117. end;
  118. EDOMInvalidAccess = class(EDOMError)
  119. public
  120. constructor Create(const ASituation: String);
  121. end;
  122. // -------------------------------------------------------
  123. // Node
  124. // -------------------------------------------------------
  125. const
  126. ELEMENT_NODE = 1;
  127. ATTRIBUTE_NODE = 2;
  128. TEXT_NODE = 3;
  129. CDATA_SECTION_NODE = 4;
  130. ENTITY_REFERENCE_NODE = 5;
  131. ENTITY_NODE = 6;
  132. PROCESSING_INSTRUCTION_NODE = 7;
  133. COMMENT_NODE = 8;
  134. DOCUMENT_NODE = 9;
  135. DOCUMENT_TYPE_NODE = 10;
  136. DOCUMENT_FRAGMENT_NODE = 11;
  137. NOTATION_NODE = 12;
  138. type
  139. TRefClass = class
  140. protected
  141. RefCounter: LongInt;
  142. public
  143. constructor Create;
  144. function AddRef: LongInt; virtual;
  145. function Release: LongInt; virtual;
  146. end;
  147. TDOMNode = class
  148. protected
  149. FNodeName, FNodeValue: DOMString;
  150. FNodeType: Integer;
  151. FParentNode: TDOMNode;
  152. FPreviousSibling, FNextSibling: TDOMNode;
  153. FOwnerDocument: TDOMDocument;
  154. function GetNodeValue: DOMString; virtual;
  155. procedure SetNodeValue(AValue: DOMString); virtual;
  156. function GetFirstChild: TDOMNode; virtual;
  157. function GetLastChild: TDOMNode; virtual;
  158. function GetAttributes: TDOMNamedNodeMap; virtual;
  159. constructor Create(AOwner: TDOMDocument);
  160. public
  161. // Free NodeList with TDOMNodeList.Release!
  162. function GetChildNodes: TDOMNodeList; virtual;
  163. property NodeName: DOMString read FNodeName;
  164. property NodeValue: DOMString read GetNodeValue write SetNodeValue;
  165. property NodeType: Integer read FNodeType;
  166. property ParentNode: TDOMNode read FParentNode;
  167. property FirstChild: TDOMNode read GetFirstChild;
  168. property LastChild: TDOMNode read GetLastChild;
  169. property ChildNodes: TDOMNodeList read GetChildNodes;
  170. property PreviousSibling: TDOMNode read FPreviousSibling;
  171. property NextSibling: TDOMNode read FNextSibling;
  172. property Attributes: TDOMNamedNodeMap read GetAttributes;
  173. property OwnerDocument: TDOMDocument read FOwnerDocument;
  174. function InsertBefore(NewChild, RefChild: TDOMNode): TDOMNode; virtual;
  175. function ReplaceChild(NewChild, OldChild: TDOMNode): TDOMNode; virtual;
  176. function RemoveChild(OldChild: TDOMNode): TDOMNode; virtual;
  177. function AppendChild(NewChild: TDOMNode): TDOMNode; virtual;
  178. function HasChildNodes: Boolean; virtual;
  179. function CloneNode(deep: Boolean): TDOMNode;
  180. // Extensions to DOM interface:
  181. function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; virtual;
  182. function FindNode(const ANodeName: DOMString): TDOMNode;
  183. end;
  184. { The following class is an implementation specific extension, it is just an
  185. extended implementation of TDOMNode, the generic DOM::Node interface
  186. implementation. (Its main purpose is to save memory in a big node tree) }
  187. TDOMNode_WithChildren = class(TDOMNode)
  188. protected
  189. FFirstChild, FLastChild: TDOMNode;
  190. function GetFirstChild: TDOMNode; override;
  191. function GetLastChild: TDOMNode; override;
  192. procedure CloneChildren(ACopy: TDOMNode; ACloneOwner: TDOMDocument);
  193. public
  194. destructor Destroy; override;
  195. function InsertBefore(NewChild, RefChild: TDOMNode): TDOMNode; override;
  196. function ReplaceChild(NewChild, OldChild: TDOMNode): TDOMNode; override;
  197. function RemoveChild(OldChild: TDOMNode): TDOMNode; override;
  198. function AppendChild(NewChild: TDOMNode): TDOMNode; override;
  199. function HasChildNodes: Boolean; override;
  200. end;
  201. // -------------------------------------------------------
  202. // NodeList
  203. // -------------------------------------------------------
  204. TDOMNodeList = class(TRefClass)
  205. protected
  206. node: TDOMNode;
  207. filter: DOMString;
  208. UseFilter: Boolean;
  209. constructor Create(ANode: TDOMNode; AFilter: DOMString);
  210. function GetCount: LongInt;
  211. function GetItem(index: LongWord): TDOMNode;
  212. public
  213. property Item[index: LongWord]: TDOMNode read GetItem;
  214. property Count: LongInt read GetCount;
  215. end;
  216. // -------------------------------------------------------
  217. // NamedNodeMap
  218. // -------------------------------------------------------
  219. TDOMNamedNodeMap = class(TList)
  220. protected
  221. OwnerDocument: TDOMDocument;
  222. function GetItem(index: LongWord): TDOMNode;
  223. procedure SetItem(index: LongWord; AItem: TDOMNode);
  224. function GetLength: LongInt;
  225. constructor Create(AOwner: TDOMDocument);
  226. public
  227. function GetNamedItem(const name: DOMString): TDOMNode;
  228. function SetNamedItem(arg: TDOMNode): TDOMNode;
  229. function RemoveNamedItem(const name: DOMString): TDOMNode;
  230. property Item[index: LongWord]: TDOMNode read GetItem write SetItem; default;
  231. property Length: LongInt read GetLength;
  232. end;
  233. // -------------------------------------------------------
  234. // CharacterData
  235. // -------------------------------------------------------
  236. TDOMCharacterData = class(TDOMNode)
  237. protected
  238. function GetLength: LongInt;
  239. public
  240. property Data: DOMString read FNodeValue;
  241. property Length: LongInt read GetLength;
  242. function SubstringData(offset, count: LongWord): DOMString;
  243. procedure AppendData(const arg: DOMString);
  244. procedure InsertData(offset: LongWord; const arg: DOMString);
  245. procedure DeleteData(offset, count: LongWord);
  246. procedure ReplaceData(offset, count: LongWord; const arg: DOMString);
  247. end;
  248. // -------------------------------------------------------
  249. // DOMImplementation
  250. // -------------------------------------------------------
  251. TDOMImplementation = class
  252. public
  253. function HasFeature(const feature, version: DOMString): Boolean;
  254. // Introduced in DOM Level 2:
  255. function CreateDocumentType(const QualifiedName, PublicID,
  256. SystemID: DOMString): TDOMDocumentType;
  257. function CreateDocument(const NamespaceURI, QualifiedName: DOMString;
  258. doctype: TDOMDocumentType): TDOMDocument;
  259. end;
  260. // -------------------------------------------------------
  261. // DocumentFragment
  262. // -------------------------------------------------------
  263. TDOMDocumentFragment = class(TDOMNode_WithChildren)
  264. protected
  265. constructor Create(AOwner: TDOMDocument);
  266. end;
  267. // -------------------------------------------------------
  268. // Document
  269. // -------------------------------------------------------
  270. TDOMDocument = class(TDOMNode_WithChildren)
  271. protected
  272. FDocType: TDOMDocumentType;
  273. FImplementation: TDOMImplementation;
  274. function GetDocumentElement: TDOMElement;
  275. public
  276. property DocType: TDOMDocumentType read FDocType;
  277. property Impl: TDOMImplementation read FImplementation;
  278. property DocumentElement: TDOMElement read GetDocumentElement;
  279. function CreateElement(const tagName: DOMString): TDOMElement; virtual;
  280. function CreateDocumentFragment: TDOMDocumentFragment;
  281. function CreateTextNode(const data: DOMString): TDOMText;
  282. function CreateComment(const data: DOMString): TDOMComment;
  283. function CreateCDATASection(const data: DOMString): TDOMCDATASection;
  284. virtual;
  285. function CreateProcessingInstruction(const target, data: DOMString):
  286. TDOMProcessingInstruction; virtual;
  287. function CreateAttribute(const name: DOMString): TDOMAttr; virtual;
  288. function CreateEntityReference(const name: DOMString): TDOMEntityReference;
  289. virtual;
  290. // Free NodeList with TDOMNodeList.Release!
  291. function GetElementsByTagName(const tagname: DOMString): TDOMNodeList;
  292. // Extensions to DOM interface:
  293. constructor Create; virtual;
  294. function CreateEntity(const data: DOMString): TDOMEntity;
  295. end;
  296. TXMLDocument = class(TDOMDocument)
  297. public
  298. function CreateCDATASection(const data: DOMString): TDOMCDATASection; override;
  299. function CreateProcessingInstruction(const target, data: DOMString):
  300. TDOMProcessingInstruction; override;
  301. function CreateEntityReference(const name: DOMString): TDOMEntityReference; override;
  302. // Extensions to DOM interface:
  303. XMLVersion, Encoding, StylesheetType, StylesheetHRef: DOMString;
  304. end;
  305. // -------------------------------------------------------
  306. // Attr
  307. // -------------------------------------------------------
  308. TDOMAttr = class(TDOMNode_WithChildren)
  309. protected
  310. FSpecified: Boolean;
  311. AttrOwner: TDOMNamedNodeMap;
  312. function GetNodeValue: DOMString; override;
  313. procedure SetNodeValue(AValue: DOMString); override;
  314. constructor Create(AOwner: TDOMDocument);
  315. public
  316. function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; override;
  317. property Name: DOMString read FNodeName;
  318. property Specified: Boolean read FSpecified;
  319. property Value: DOMString read FNodeValue write SetNodeValue;
  320. end;
  321. // -------------------------------------------------------
  322. // Element
  323. // -------------------------------------------------------
  324. TDOMElement = class(TDOMNode_WithChildren)
  325. protected
  326. FAttributes: TDOMNamedNodeMap;
  327. function GetAttributes: TDOMNamedNodeMap; override;
  328. constructor Create(AOwner: TDOMDocument); virtual;
  329. public
  330. destructor Destroy; override;
  331. function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; override;
  332. property TagName: DOMString read FNodeName;
  333. function GetAttribute(const name: DOMString): DOMString;
  334. procedure SetAttribute(const name, value: DOMString);
  335. procedure RemoveAttribute(const name: DOMString);
  336. function GetAttributeNode(const name: DOMString): TDOMAttr;
  337. procedure SetAttributeNode(NewAttr: TDOMAttr);
  338. function RemoveAttributeNode(OldAttr: TDOMAttr): TDOMAttr;
  339. // Free NodeList with TDOMNodeList.Release!
  340. function GetElementsByTagName(const name: DOMString): TDOMNodeList;
  341. procedure Normalize;
  342. property AttribStrings[const Name: DOMString]: DOMString
  343. read GetAttribute write SetAttribute; default;
  344. end;
  345. // -------------------------------------------------------
  346. // Text
  347. // -------------------------------------------------------
  348. TDOMText = class(TDOMCharacterData)
  349. protected
  350. constructor Create(AOwner: TDOMDocument);
  351. public
  352. function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; override;
  353. function SplitText(offset: LongWord): TDOMText;
  354. end;
  355. // -------------------------------------------------------
  356. // Comment
  357. // -------------------------------------------------------
  358. TDOMComment = class(TDOMCharacterData)
  359. protected
  360. constructor Create(AOwner: TDOMDocument);
  361. public
  362. function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; override;
  363. end;
  364. // -------------------------------------------------------
  365. // CDATASection
  366. // -------------------------------------------------------
  367. TDOMCDATASection = class(TDOMText)
  368. protected
  369. constructor Create(AOwner: TDOMDocument);
  370. public
  371. function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; override;
  372. end;
  373. // -------------------------------------------------------
  374. // DocumentType
  375. // -------------------------------------------------------
  376. TDOMDocumentType = class(TDOMNode)
  377. protected
  378. FEntities, FNotations: TDOMNamedNodeMap;
  379. constructor Create(AOwner: TDOMDocument);
  380. public
  381. function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; override;
  382. property Name: DOMString read FNodeName;
  383. property Entities: TDOMNamedNodeMap read FEntities;
  384. property Notations: TDOMNamedNodeMap read FEntities;
  385. end;
  386. // -------------------------------------------------------
  387. // Notation
  388. // -------------------------------------------------------
  389. TDOMNotation = class(TDOMNode)
  390. protected
  391. FPublicID, FSystemID: DOMString;
  392. constructor Create(AOwner: TDOMDocument);
  393. public
  394. function CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode; override;
  395. property PublicID: DOMString read FPublicID;
  396. property SystemID: DOMString read FSystemID;
  397. end;
  398. // -------------------------------------------------------
  399. // Entity
  400. // -------------------------------------------------------
  401. TDOMEntity = class(TDOMNode_WithChildren)
  402. protected
  403. FPublicID, FSystemID, FNotationName: DOMString;
  404. constructor Create(AOwner: TDOMDocument);
  405. public
  406. property PublicID: DOMString read FPublicID;
  407. property SystemID: DOMString read FSystemID;
  408. property NotationName: DOMString read FNotationName;
  409. end;
  410. // -------------------------------------------------------
  411. // EntityReference
  412. // -------------------------------------------------------
  413. TDOMEntityReference = class(TDOMNode_WithChildren)
  414. protected
  415. constructor Create(AOwner: TDOMDocument);
  416. end;
  417. // -------------------------------------------------------
  418. // ProcessingInstruction
  419. // -------------------------------------------------------
  420. TDOMProcessingInstruction = class(TDOMNode)
  421. protected
  422. constructor Create(AOwner: TDOMDocument);
  423. public
  424. property Target: DOMString read FNodeName;
  425. property Data: DOMString read FNodeValue;
  426. end;
  427. // =======================================================
  428. // =======================================================
  429. implementation
  430. constructor TRefClass.Create;
  431. begin
  432. inherited Create;
  433. RefCounter := 1;
  434. end;
  435. function TRefClass.AddRef: LongInt;
  436. begin
  437. Inc(RefCounter);
  438. Result := RefCounter;
  439. end;
  440. function TRefClass.Release: LongInt;
  441. begin
  442. Dec(RefCounter);
  443. Result := RefCounter;
  444. if RefCounter <= 0 then Free;
  445. end;
  446. // -------------------------------------------------------
  447. // DOM Exception
  448. // -------------------------------------------------------
  449. constructor EDOMError.Create(ACode: Integer; const ASituation: String);
  450. begin
  451. Code := ACode;
  452. inherited Create(Self.ClassName + ' in ' + ASituation);
  453. end;
  454. constructor EDOMIndexSize.Create(const ASituation: String); // 1
  455. begin
  456. inherited Create(INDEX_SIZE_ERR, ASituation);
  457. end;
  458. constructor EDOMHierarchyRequest.Create(const ASituation: String); // 3
  459. begin
  460. inherited Create(HIERARCHY_REQUEST_ERR, ASituation);
  461. end;
  462. constructor EDOMWrongDocument.Create(const ASituation: String); // 4
  463. begin
  464. inherited Create(WRONG_DOCUMENT_ERR, ASituation);
  465. end;
  466. constructor EDOMNotFound.Create(const ASituation: String); // 8
  467. begin
  468. inherited Create(NOT_FOUND_ERR, ASituation);
  469. end;
  470. constructor EDOMNotSupported.Create(const ASituation: String); // 9
  471. begin
  472. inherited Create(NOT_SUPPORTED_ERR, ASituation);
  473. end;
  474. constructor EDOMInUseAttribute.Create(const ASituation: String); // 10
  475. begin
  476. inherited Create(INUSE_ATTRIBUTE_ERR, ASituation);
  477. end;
  478. constructor EDOMInvalidState.Create(const ASituation: String); // 11
  479. begin
  480. inherited Create(INVALID_STATE_ERR, ASituation);
  481. end;
  482. constructor EDOMSyntax.Create(const ASituation: String); // 12
  483. begin
  484. inherited Create(SYNTAX_ERR, ASituation);
  485. end;
  486. constructor EDOMInvalidModification.Create(const ASituation: String); // 13
  487. begin
  488. inherited Create(INVALID_MODIFICATION_ERR, ASituation);
  489. end;
  490. constructor EDOMNamespace.Create(const ASituation: String); // 14
  491. begin
  492. inherited Create(NAMESPACE_ERR, ASituation);
  493. end;
  494. constructor EDOMInvalidAccess.Create(const ASituation: String); // 15
  495. begin
  496. inherited Create(INVALID_ACCESS_ERR, ASituation);
  497. end;
  498. // -------------------------------------------------------
  499. // Node
  500. // -------------------------------------------------------
  501. constructor TDOMNode.Create(AOwner: TDOMDocument);
  502. begin
  503. FOwnerDocument := AOwner;
  504. inherited Create;
  505. end;
  506. function TDOMNode.GetNodeValue: DOMString;
  507. begin
  508. Result := FNodeValue;
  509. end;
  510. procedure TDOMNode.SetNodeValue(AValue: DOMString);
  511. begin
  512. FNodeValue := AValue;
  513. end;
  514. function TDOMNode.GetChildNodes: TDOMNodeList;
  515. begin
  516. Result := TDOMNodeList.Create(Self, '*');
  517. end;
  518. function TDOMNode.GetFirstChild: TDOMNode; begin Result := nil end;
  519. function TDOMNode.GetLastChild: TDOMNode; begin Result := nil end;
  520. function TDOMNode.GetAttributes: TDOMNamedNodeMap; begin Result := nil end;
  521. function TDOMNode.InsertBefore(NewChild, RefChild: TDOMNode): TDOMNode;
  522. begin
  523. raise EDOMHierarchyRequest.Create('Node.InsertBefore');
  524. end;
  525. function TDOMNode.ReplaceChild(NewChild, OldChild: TDOMNode): TDOMNode;
  526. begin
  527. raise EDOMHierarchyRequest.Create('Node.ReplaceChild');
  528. end;
  529. function TDOMNode.RemoveChild(OldChild: TDOMNode): TDOMNode;
  530. begin
  531. raise EDOMHierarchyRequest.Create('Node.RemoveChild');
  532. end;
  533. function TDOMNode.AppendChild(NewChild: TDOMNode): TDOMNode;
  534. begin
  535. raise EDOMHierarchyRequest.Create('Node.AppendChild');
  536. end;
  537. function TDOMNode.HasChildNodes: Boolean;
  538. begin
  539. Result := False;
  540. end;
  541. function TDOMNode.CloneNode(deep: Boolean): TDOMNode;
  542. begin
  543. CloneNode(deep, FOwnerDocument);
  544. end;
  545. function TDOMNode.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
  546. begin
  547. raise EDOMNotSupported.Create('CloneNode not implemented for ' + ClassName);
  548. end;
  549. function TDOMNode.FindNode(const ANodeName: DOMString): TDOMNode;
  550. var
  551. child: TDOMNode;
  552. begin
  553. child := FirstChild;
  554. while Assigned(child) do
  555. begin
  556. if child.NodeName = ANodeName then
  557. begin
  558. Result := child;
  559. exit;
  560. end;
  561. child := child.NextSibling;
  562. end;
  563. Result := nil;
  564. end;
  565. function TDOMNode_WithChildren.GetFirstChild: TDOMNode;
  566. begin
  567. Result := FFirstChild;
  568. end;
  569. function TDOMNode_WithChildren.GetLastChild: TDOMNode;
  570. begin
  571. Result := FLastChild;
  572. end;
  573. destructor TDOMNode_WithChildren.Destroy;
  574. var
  575. child, next: TDOMNode;
  576. begin
  577. child := FirstChild;
  578. while Assigned(child) do
  579. begin
  580. next := child.NextSibling;
  581. child.Free;
  582. child := next;
  583. end;
  584. inherited Destroy;
  585. end;
  586. function TDOMNode_WithChildren.InsertBefore(NewChild, RefChild: TDOMNode):
  587. TDOMNode;
  588. var
  589. i: Integer;
  590. begin
  591. Result := NewChild;
  592. if not Assigned(RefChild) then
  593. begin
  594. AppendChild(NewChild);
  595. exit;
  596. end;
  597. if NewChild.FOwnerDocument <> FOwnerDocument then
  598. raise EDOMWrongDocument.Create('NodeWC.InsertBefore');
  599. if RefChild.ParentNode <> Self then
  600. raise EDOMHierarchyRequest.Create('NodeWC.InsertBefore');
  601. if NewChild.NodeType = DOCUMENT_FRAGMENT_NODE then
  602. raise EDOMNotSupported.Create('NodeWC.InsertBefore for DocumentFragment');
  603. NewChild.FNextSibling := RefChild;
  604. if RefChild = FFirstChild then
  605. FFirstChild := NewChild
  606. else
  607. RefChild.FPreviousSibling.FNextSibling := NewChild;
  608. RefChild.FPreviousSibling := NewChild;
  609. NewChild.FParentNode := Self;
  610. end;
  611. function TDOMNode_WithChildren.ReplaceChild(NewChild, OldChild: TDOMNode):
  612. TDOMNode;
  613. begin
  614. InsertBefore(NewChild, OldChild);
  615. if Assigned(OldChild) then
  616. RemoveChild(OldChild);
  617. Result := NewChild;
  618. end;
  619. function TDOMNode_WithChildren.RemoveChild(OldChild: TDOMNode):
  620. TDOMNode;
  621. begin
  622. if OldChild.ParentNode <> Self then
  623. raise EDOMHierarchyRequest.Create('NodeWC.RemoveChild');
  624. if OldChild = FFirstChild then
  625. FFirstChild := FFirstChild.NextSibling
  626. else
  627. OldChild.FPreviousSibling.FNextSibling := OldChild.FNextSibling;
  628. if OldChild = FLastChild then
  629. FLastChild := FLastChild.FPreviousSibling
  630. else
  631. OldChild.FNextSibling.FPreviousSibling := OldChild.FPreviousSibling;
  632. OldChild.Free;
  633. end;
  634. function TDOMNode_WithChildren.AppendChild(NewChild: TDOMNode): TDOMNode;
  635. var
  636. Parent: TDOMNode;
  637. begin
  638. if NewChild.FOwnerDocument <> FOwnerDocument then
  639. raise EDOMWrongDocument.Create('NodeWC.AppendChild');
  640. Parent := Self;
  641. while Assigned(Parent) do
  642. begin
  643. if Parent = NewChild then
  644. raise EDOMHierarchyRequest.Create('NodeWC.AppendChild (cycle in tree)');
  645. Parent := Parent.ParentNode;
  646. end;
  647. if NewChild.FParentNode = Self then
  648. RemoveChild(NewChild);
  649. if NewChild.NodeType = DOCUMENT_FRAGMENT_NODE then
  650. raise EDOMNotSupported.Create('NodeWC.AppendChild for DocumentFragments')
  651. else begin
  652. if Assigned(FFirstChild) then
  653. begin
  654. FLastChild.FNextSibling := NewChild;
  655. NewChild.FPreviousSibling := FLastChild;
  656. end else
  657. FFirstChild := NewChild;
  658. FLastChild := NewChild;
  659. NewChild.FParentNode := Self;
  660. end;
  661. Result := NewChild;
  662. end;
  663. function TDOMNode_WithChildren.HasChildNodes: Boolean;
  664. begin
  665. Result := Assigned(FFirstChild);
  666. end;
  667. procedure TDOMNode_WithChildren.CloneChildren(ACopy: TDOMNode; ACloneOwner: TDOMDocument);
  668. var
  669. node: TDOMNode;
  670. begin
  671. node := FirstChild;
  672. while Assigned(node) do
  673. begin
  674. ACopy.AppendChild(node.CloneNode(True, ACloneOwner));
  675. node := node.NextSibling;
  676. end;
  677. end;
  678. // -------------------------------------------------------
  679. // NodeList
  680. // -------------------------------------------------------
  681. constructor TDOMNodeList.Create(ANode: TDOMNode; AFilter: DOMString);
  682. begin
  683. inherited Create;
  684. node := ANode;
  685. filter := AFilter;
  686. UseFilter := filter <> '*';
  687. end;
  688. function TDOMNodeList.GetCount: LongInt;
  689. var
  690. child: TDOMNode;
  691. begin
  692. Result := 0;
  693. child := node.FirstChild;
  694. while Assigned(child) do
  695. begin
  696. if (not UseFilter) or (child.NodeName = filter) then
  697. Inc(Result);
  698. child := child.NextSibling;
  699. end;
  700. end;
  701. function TDOMNodeList.GetItem(index: LongWord): TDOMNode;
  702. var
  703. child: TDOMNode;
  704. begin
  705. Result := nil;
  706. if index < 0 then
  707. exit;
  708. child := node.FirstChild;
  709. while Assigned(child) do
  710. begin
  711. if index = 0 then
  712. begin
  713. Result := child;
  714. break;
  715. end;
  716. if (not UseFilter) or (child.NodeName = filter) then
  717. Dec(index);
  718. child := child.NextSibling;
  719. end;
  720. end;
  721. // -------------------------------------------------------
  722. // NamedNodeMap
  723. // -------------------------------------------------------
  724. constructor TDOMNamedNodeMap.Create(AOwner: TDOMDocument);
  725. begin
  726. inherited Create;
  727. OwnerDocument := AOwner;
  728. end;
  729. function TDOMNamedNodeMap.GetItem(index: LongWord): TDOMNode;
  730. begin
  731. Result := TDOMNode(Items[index]);
  732. end;
  733. procedure TDOMNamedNodeMap.SetItem(index: LongWord; AItem: TDOMNode);
  734. begin
  735. Items[index] := AItem;
  736. end;
  737. function TDOMNamedNodeMap.GetLength: LongInt;
  738. begin
  739. Result := Count;
  740. end;
  741. function TDOMNamedNodeMap.GetNamedItem(const name: DOMString): TDOMNode;
  742. var
  743. i: Integer;
  744. begin
  745. for i := 0 to Count - 1 do
  746. if Item[i].NodeName = name then
  747. exit(Item[i]);
  748. Result := nil;
  749. end;
  750. function TDOMNamedNodeMap.SetNamedItem(arg: TDOMNode): TDOMNode;
  751. var
  752. i: Integer;
  753. begin
  754. if arg.FOwnerDocument <> OwnerDocument then
  755. raise EDOMWrongDocument.Create('NamedNodeMap.SetNamedItem');
  756. if arg.NodeType = ATTRIBUTE_NODE then
  757. begin
  758. if Assigned(TDOMAttr(arg).AttrOwner) then
  759. raise EDOMInUseAttribute.Create('NamedNodeMap.SetNamedItem');
  760. TDOMAttr(arg).AttrOwner := Self;
  761. end;
  762. for i := 0 to Count - 1 do
  763. if Item[i].NodeName = arg.NodeName then
  764. begin
  765. Result := Item[i];
  766. Item[i] := arg;
  767. exit;
  768. end;
  769. Add(arg);
  770. Result := nil;
  771. end;
  772. function TDOMNamedNodeMap.RemoveNamedItem(const name: DOMString): TDOMNode;
  773. var
  774. i: Integer;
  775. begin
  776. for i := 0 to Count - 1 do
  777. if Item[i].NodeName = name then
  778. begin
  779. Result := Item[i];
  780. Result.FParentNode := nil;
  781. exit;
  782. end;
  783. raise EDOMNotFound.Create('NamedNodeMap.RemoveNamedItem');
  784. end;
  785. // -------------------------------------------------------
  786. // CharacterData
  787. // -------------------------------------------------------
  788. function TDOMCharacterData.GetLength: LongInt;
  789. begin
  790. Result := system.Length(FNodeValue);
  791. end;
  792. function TDOMCharacterData.SubstringData(offset, count: LongWord): DOMString;
  793. begin
  794. if (offset < 0) or (offset > Length) or (count < 0) then
  795. raise EDOMIndexSize.Create('CharacterData.SubstringData');
  796. Result := Copy(FNodeValue, offset + 1, count);
  797. end;
  798. procedure TDOMCharacterData.AppendData(const arg: DOMString);
  799. begin
  800. FNodeValue := FNodeValue + arg;
  801. end;
  802. procedure TDOMCharacterData.InsertData(offset: LongWord; const arg: DOMString);
  803. begin
  804. if (offset < 0) or (offset > Length) then
  805. raise EDOMIndexSize.Create('CharacterData.InsertData');
  806. FNodeValue := Copy(FNodeValue, 1, offset) + arg +
  807. Copy(FNodeValue, offset + 1, Length);
  808. end;
  809. procedure TDOMCharacterData.DeleteData(offset, count: LongWord);
  810. begin
  811. if (offset < 0) or (offset > Length) or (count < 0) then
  812. raise EDOMIndexSize.Create('CharacterData.DeleteData');
  813. FNodeValue := Copy(FNodeValue, 1, offset) +
  814. Copy(FNodeValue, offset + count + 1, Length);
  815. end;
  816. procedure TDOMCharacterData.ReplaceData(offset, count: LongWord; const arg: DOMString);
  817. begin
  818. DeleteData(offset, count);
  819. InsertData(offset, arg);
  820. end;
  821. // -------------------------------------------------------
  822. // DocumentFragmet
  823. // -------------------------------------------------------
  824. constructor TDOMDocumentFragment.Create(AOwner: TDOMDocument);
  825. begin
  826. FNodeType := DOCUMENT_FRAGMENT_NODE;
  827. FNodeName := '#document-fragment';
  828. inherited Create(AOwner);
  829. end;
  830. // -------------------------------------------------------
  831. // DOMImplementation
  832. // -------------------------------------------------------
  833. function TDOMImplementation.HasFeature(const feature, version: DOMString):
  834. Boolean;
  835. begin
  836. Result := False;
  837. end;
  838. function TDOMImplementation.CreateDocumentType(const QualifiedName, PublicID,
  839. SystemID: DOMString): TDOMDocumentType;
  840. begin
  841. // !!!: Implement this method (easy to do)
  842. raise EDOMNotSupported.Create('DOMImplementation.CreateDocumentType');
  843. end;
  844. function TDOMImplementation.CreateDocument(const NamespaceURI,
  845. QualifiedName: DOMString; doctype: TDOMDocumentType): TDOMDocument;
  846. begin
  847. // !!!: Implement this method (easy to do)
  848. raise EDOMNotSupported.Create('DOMImplementation.CreateDocument');
  849. end;
  850. // -------------------------------------------------------
  851. // Document
  852. // -------------------------------------------------------
  853. constructor TDOMDocument.Create;
  854. begin
  855. FNodeType := DOCUMENT_NODE;
  856. FNodeName := '#document';
  857. inherited Create(nil);
  858. FOwnerDocument := Self;
  859. end;
  860. function TDOMDocument.GetDocumentElement: TDOMElement;
  861. var
  862. node: TDOMNode;
  863. begin
  864. node := FFirstChild;
  865. while Assigned(node) do
  866. begin
  867. if node.FNodeType = ELEMENT_NODE then
  868. begin
  869. Result := TDOMElement(node);
  870. exit;
  871. end;
  872. node := node.NextSibling;
  873. end;
  874. Result := nil;
  875. end;
  876. function TDOMDocument.CreateElement(const tagName: DOMString): TDOMElement;
  877. begin
  878. Result := TDOMElement.Create(Self);
  879. Result.FNodeName := tagName;
  880. end;
  881. function TDOMDocument.CreateDocumentFragment: TDOMDocumentFragment;
  882. begin
  883. Result := TDOMDocumentFragment.Create(Self);
  884. end;
  885. function TDOMDocument.CreateTextNode(const data: DOMString): TDOMText;
  886. begin
  887. Result := TDOMText.Create(Self);
  888. Result.FNodeValue := data;
  889. end;
  890. function TDOMDocument.CreateComment(const data: DOMString): TDOMComment;
  891. begin
  892. Result := TDOMComment.Create(Self);
  893. Result.FNodeValue := data;
  894. end;
  895. function TDOMDocument.CreateCDATASection(const data: DOMString):
  896. TDOMCDATASection;
  897. begin
  898. raise EDOMNotSupported.Create('DOMDocument.CreateCDATASection');
  899. end;
  900. function TDOMDocument.CreateProcessingInstruction(const target,
  901. data: DOMString): TDOMProcessingInstruction;
  902. begin
  903. raise EDOMNotSupported.Create('DOMDocument.CreateProcessingInstruction');
  904. end;
  905. function TDOMDocument.CreateAttribute(const name: DOMString): TDOMAttr;
  906. begin
  907. Result := TDOMAttr.Create(Self);
  908. Result.FNodeName := name;
  909. end;
  910. function TDOMDocument.CreateEntityReference(const name: DOMString):
  911. TDOMEntityReference;
  912. begin
  913. raise EDOMNotSupported.Create('DOMDocument.CreateEntityReference');
  914. end;
  915. function TDOMDocument.CreateEntity(const data: DOMString): TDOMEntity;
  916. begin
  917. Result := TDOMEntity.Create(Self);
  918. Result.FNodeName := data;
  919. end;
  920. function TDOMDocument.GetElementsByTagName(const tagname: DOMString): TDOMNodeList;
  921. begin
  922. Result := TDOMNodeList.Create(Self, tagname);
  923. end;
  924. function TXMLDocument.CreateCDATASection(const data: DOMString):
  925. TDOMCDATASection;
  926. begin
  927. Result := TDOMCDATASection.Create(Self);
  928. Result.FNodeValue := data;
  929. end;
  930. function TXMLDocument.CreateProcessingInstruction(const target,
  931. data: DOMString): TDOMProcessingInstruction;
  932. begin
  933. Result := TDOMProcessingInstruction.Create(Self);
  934. Result.FNodeName := target;
  935. Result.FNodeValue := data;
  936. end;
  937. function TXMLDocument.CreateEntityReference(const name: DOMString):
  938. TDOMEntityReference;
  939. begin
  940. Result := TDOMEntityReference.Create(Self);
  941. Result.FNodeName := name;
  942. end;
  943. // -------------------------------------------------------
  944. // Attr
  945. // -------------------------------------------------------
  946. constructor TDOMAttr.Create(AOwner: TDOMDocument);
  947. begin
  948. FNodeType := ATTRIBUTE_NODE;
  949. inherited Create(AOwner);
  950. end;
  951. function TDOMAttr.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
  952. begin
  953. Result := TDOMAttr.Create(ACloneOwner);
  954. Result.FNodeName := FNodeName;
  955. TDOMAttr(Result).FSpecified := FSpecified;
  956. if deep then
  957. CloneChildren(Result, ACloneOwner);
  958. end;
  959. function TDOMAttr.GetNodeValue: DOMString;
  960. var
  961. child: TDOMNode;
  962. begin
  963. SetLength(Result, 0);
  964. if Assigned(FFirstChild) then
  965. begin
  966. child := FFirstChild;
  967. while Assigned(child) do
  968. begin
  969. if child.NodeType = ENTITY_REFERENCE_NODE then
  970. Result := Result + '&' + child.NodeName + ';'
  971. else
  972. Result := Result + child.NodeValue;
  973. child := child.NextSibling;
  974. end;
  975. end;
  976. end;
  977. procedure TDOMAttr.SetNodeValue(AValue: DOMString);
  978. var
  979. tn: TDOMText;
  980. begin
  981. FSpecified := True;
  982. tn := TDOMText.Create(FOwnerDocument);
  983. tn.FNodeValue := AValue;
  984. if Assigned(FFirstChild) then
  985. ReplaceChild(tn, FFirstChild)
  986. else
  987. AppendChild(tn);
  988. end;
  989. // -------------------------------------------------------
  990. // Element
  991. // -------------------------------------------------------
  992. constructor TDOMElement.Create(AOwner: TDOMDocument);
  993. begin
  994. FNodeType := ELEMENT_NODE;
  995. inherited Create(AOwner);
  996. FAttributes := TDOMNamedNodeMap.Create(AOwner);
  997. end;
  998. destructor TDOMElement.Destroy;
  999. var
  1000. i: Integer;
  1001. begin
  1002. {As the attributes are _not_ childs of the element node, we have to free
  1003. them manually here:}
  1004. for i := 0 to FAttributes.Count - 1 do
  1005. FAttributes[i].Free;
  1006. FAttributes.Free;
  1007. inherited Destroy;
  1008. end;
  1009. function TDOMElement.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
  1010. var
  1011. i: Integer;
  1012. begin
  1013. Result := TDOMElement.Create(ACloneOwner);
  1014. Result.FNodeName := FNodeName;
  1015. for i := 0 to FAttributes.Count - 1 do
  1016. TDOMElement(Result).FAttributes.Add(FAttributes[i].CloneNode(True, ACloneOwner));
  1017. if deep then
  1018. CloneChildren(Result, ACloneOwner);
  1019. end;
  1020. function TDOMElement.GetAttributes: TDOMNamedNodeMap;
  1021. begin
  1022. Result := FAttributes;
  1023. end;
  1024. function TDOMElement.GetAttribute(const name: DOMString): DOMString;
  1025. var
  1026. i: Integer;
  1027. begin
  1028. for i := 0 to FAttributes.Count - 1 do
  1029. if FAttributes[i].NodeName = name then
  1030. begin
  1031. Result := FAttributes[i].NodeValue;
  1032. exit;
  1033. end;
  1034. SetLength(Result, 0);
  1035. end;
  1036. procedure TDOMElement.SetAttribute(const name, value: DOMString);
  1037. var
  1038. i: Integer;
  1039. attr: TDOMAttr;
  1040. begin
  1041. for i := 0 to FAttributes.Count - 1 do
  1042. if FAttributes[i].NodeName = name then
  1043. begin
  1044. FAttributes[i].NodeValue := value;
  1045. exit;
  1046. end;
  1047. attr := TDOMAttr.Create(FOwnerDocument);
  1048. attr.FNodeName := name;
  1049. attr.NodeValue := value;
  1050. FAttributes.Add(attr);
  1051. end;
  1052. procedure TDOMElement.RemoveAttribute(const name: DOMString);
  1053. var
  1054. i: Integer;
  1055. begin
  1056. for i := 0 to FAttributes.Count - 1 do
  1057. if FAttributes[i].NodeName = name then
  1058. begin
  1059. FAttributes[i].Free;
  1060. FAttributes.Delete(i);
  1061. exit;
  1062. end;
  1063. end;
  1064. function TDOMElement.GetAttributeNode(const name: DOMString): TDOMAttr;
  1065. var
  1066. i: Integer;
  1067. begin
  1068. for i := 0 to FAttributes.Count - 1 do
  1069. if FAttributes[i].NodeName = name then
  1070. begin
  1071. Result := TDOMAttr(FAttributes[i]);
  1072. exit;
  1073. end;
  1074. Result := nil;
  1075. end;
  1076. procedure TDOMElement.SetAttributeNode(NewAttr: TDOMAttr);
  1077. var
  1078. i: Integer;
  1079. begin
  1080. for i := 0 to FAttributes.Count - 1 do
  1081. if FAttributes[i].NodeName = NewAttr.NodeName then
  1082. begin
  1083. FAttributes[i].Free;
  1084. FAttributes[i] := NewAttr;
  1085. exit;
  1086. end;
  1087. end;
  1088. function TDOMElement.RemoveAttributeNode(OldAttr: TDOMAttr): TDOMAttr;
  1089. var
  1090. i: Integer;
  1091. node: TDOMNode;
  1092. begin
  1093. for i := 0 to FAttributes.Count - 1 do
  1094. begin
  1095. node := FAttributes[i];
  1096. if node = OldAttr then
  1097. begin
  1098. FAttributes.Delete(i);
  1099. Result := TDOMAttr(node);
  1100. exit;
  1101. end;
  1102. end;
  1103. end;
  1104. function TDOMElement.GetElementsByTagName(const name: DOMString): TDOMNodeList;
  1105. begin
  1106. Result := TDOMNodeList.Create(Self, name);
  1107. end;
  1108. procedure TDOMElement.Normalize;
  1109. begin
  1110. // !!!: Not implemented
  1111. end;
  1112. // -------------------------------------------------------
  1113. // Text
  1114. // -------------------------------------------------------
  1115. constructor TDOMText.Create(AOwner: TDOMDocument);
  1116. begin
  1117. FNodeType := TEXT_NODE;
  1118. FNodeName := '#text';
  1119. inherited Create(AOwner);
  1120. end;
  1121. function TDOMText.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
  1122. begin
  1123. Result := TDOMText.Create(ACloneOwner);
  1124. Result.FNodeValue := FNodeValue;
  1125. end;
  1126. function TDOMText.SplitText(offset: LongWord): TDOMText;
  1127. var
  1128. nt: TDOMText;
  1129. begin
  1130. if offset > Length then
  1131. raise EDOMIndexSize.Create('Text.SplitText');
  1132. nt := TDOMText.Create(FOwnerDocument);
  1133. nt.FNodeValue := Copy(FNodeValue, offset + 1, Length);
  1134. FNodeValue := Copy(FNodeValue, 1, offset);
  1135. FParentNode.InsertBefore(nt, FNextSibling);
  1136. end;
  1137. // -------------------------------------------------------
  1138. // Comment
  1139. // -------------------------------------------------------
  1140. constructor TDOMComment.Create(AOwner: TDOMDocument);
  1141. begin
  1142. FNodeType := COMMENT_NODE;
  1143. FNodeName := '#comment';
  1144. inherited Create(AOwner);
  1145. end;
  1146. function TDOMComment.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
  1147. begin
  1148. Result := TDOMComment.Create(ACloneOwner);
  1149. Result.FNodeValue := FNodeValue;
  1150. end;
  1151. // -------------------------------------------------------
  1152. // CDATASection
  1153. // -------------------------------------------------------
  1154. constructor TDOMCDATASection.Create(AOwner: TDOMDocument);
  1155. begin
  1156. inherited Create(AOwner);
  1157. FNodeType := CDATA_SECTION_NODE;
  1158. FNodeName := '#cdata-section';
  1159. end;
  1160. function TDOMCDATASection.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
  1161. begin
  1162. Result := TDOMCDATASection.Create(ACloneOwner);
  1163. Result.FNodeValue := FNodeValue;
  1164. end;
  1165. // -------------------------------------------------------
  1166. // DocumentType
  1167. // -------------------------------------------------------
  1168. constructor TDOMDocumentType.Create(AOwner: TDOMDocument);
  1169. begin
  1170. FNodeType := DOCUMENT_TYPE_NODE;
  1171. inherited Create(AOwner);
  1172. end;
  1173. function TDOMDocumentType.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
  1174. begin
  1175. Result := TDOMDocumentType.Create(ACloneOwner);
  1176. Result.FNodeName := FNodeName;
  1177. end;
  1178. // -------------------------------------------------------
  1179. // Notation
  1180. // -------------------------------------------------------
  1181. constructor TDOMNotation.Create(AOwner: TDOMDocument);
  1182. begin
  1183. FNodeType := NOTATION_NODE;
  1184. inherited Create(AOwner);
  1185. end;
  1186. function TDOMNotation.CloneNode(deep: Boolean; ACloneOwner: TDOMDocument): TDOMNode;
  1187. begin
  1188. Result := TDOMNotation.Create(ACloneOwner);
  1189. Result.FNodeName := FNodeName;
  1190. end;
  1191. // -------------------------------------------------------
  1192. // Entity
  1193. // -------------------------------------------------------
  1194. constructor TDOMEntity.Create(AOwner: TDOMDocument);
  1195. begin
  1196. FNodeType := ENTITY_NODE;
  1197. inherited Create(AOwner);
  1198. end;
  1199. // -------------------------------------------------------
  1200. // EntityReference
  1201. // -------------------------------------------------------
  1202. constructor TDOMEntityReference.Create(AOwner: TDOMDocument);
  1203. begin
  1204. FNodeType := ENTITY_REFERENCE_NODE;
  1205. inherited Create(AOwner);
  1206. end;
  1207. // -------------------------------------------------------
  1208. // ProcessingInstruction
  1209. // -------------------------------------------------------
  1210. constructor TDOMProcessingInstruction.Create(AOwner: TDOMDocument);
  1211. begin
  1212. FNodeType := PROCESSING_INSTRUCTION_NODE;
  1213. inherited Create(AOwner);
  1214. end;
  1215. end.
  1216. {
  1217. $Log$
  1218. Revision 1.5 2000-09-12 14:07:58 sg
  1219. * Added fields "StylesheetType" and "StylesheetHRef" to TXMLDocument
  1220. Revision 1.4 2000/07/29 14:52:24 sg
  1221. * Modified the copyright notice to remove ambiguities
  1222. Revision 1.3 2000/07/25 09:20:08 sg
  1223. * Fixed some small bugs
  1224. - some methods where 'virtual' instead of 'override' in dom.pp
  1225. - corrections regaring wether NodeName or NodeValue is used, for
  1226. some node types (Entity, EntityReference)
  1227. Revision 1.2 2000/07/13 11:33:07 michael
  1228. + removed logs
  1229. }