Class TTreeNode
Unit
Declaration
type TTreeNode = class(TObject)
Description
This class representates an element of the html file
It is stored in an unusual tree representation: All elements form a linked list and the next element is the first children, or if there is none, the next node on the same level, or if there is none, the closing tag of the current parent.
E.g. an XML file like <foo><bar>x</bar></foo>
is stored as a quadro-linked list:
/---------------------------------\ | | ----------- | link to parent (for faster access, it would work without it) \|/ | \|/ | | ' ' <foo> <---> <bar> <---> x <---> </bar> <---> </foo> double linked list of tags (previous link again for faster access, a single linked list would work as well) . . . . /|\ /|\ /|\ /|\ | ----------------------- | single linked of corresponding node ---------------------------------------------------
There are functions (getNextSibling, getFirstChild, findNext, ...) to access it like a regular tree, but it is easier and faster to work directly with the list.
Some invariants: (SO: set of opening tags in sequence)
∀a \in SO: a < a.reverse
∀a,b \in SO: a < b < a.reverse => a < b.reverse < a.reverse
Attributes should be accessed with the getAttribute or getAttributeTry method. Or you can enumerate them all for attrib in attributes
, if attributes is not nil.
#)
Hierarchy
- TObject
- TTreeNode
Overview
Fields
typ: TTreeNodeType; |
|
value: string; |
|
hash: TNodeNameHash; |
|
attributes: TTreeAttribute; |
|
next: TTreeNode; |
|
previous: TTreeNode; |
|
parent: TTreeNode; |
|
root: TTreeNode; |
|
reverse: TTreeNode; |
|
namespace: TNamespace; |
|
offset: TTreeNodeIntOffset; |
Methods
procedure freeAll(); |
|
function findNext(withTyp: TTreeNodeType; const withText:string; findOptions: TTreeNodeFindOptions=[]; sequenceEnd: TTreeNode = nil):TTreeNode; |
|
function findChild(withTyp: TTreeNodeType; const withText:string; findOptions: TTreeNodeFindOptions=[]): TTreeNode; |
|
function getEnumeratorAttributes: TTreeAttributeEnumerator; |
|
function getEnumeratorChildren: TTreeNodeEnumerator; |
|
function getEnumeratorDescendants: TTreeNodeEnumerator; |
|
function getEnumeratorAncestors: TTreeNodeEnumerator; |
|
function getEnumeratorPreceding: TTreeNodeEnumerator; |
|
function getEnumeratorFollowing: TTreeNodeEnumerator; |
|
function getEnumeratorPrecedingSiblings: TTreeNodeEnumerator; |
|
function getEnumeratorFollowingSiblings: TTreeNodeEnumerator; |
|
function deepNodeText(separator: string=''):string; |
|
function outerXML(insertLineBreaks: boolean = false):string; |
|
function innerXML(insertLineBreaks: boolean = false):string; |
|
function outerHTML(insertLineBreaks: boolean = false):string; |
|
function innerHTML(insertLineBreaks: boolean = false):string; |
|
function innerText():string; |
|
class function innerTextRangeInternal(from, till_excluding: TTreeNode): string; static; |
|
function getValue(): string; |
|
function getValueTry(out valueout:string): boolean; |
|
function getStringValue(): string; |
|
function hasAttribute(const a: string; const cmpFunction: TStringComparisonFunc = nil): boolean; |
|
function getAttribute(const a: string):string; overload; |
|
function getAttribute(const a: string; const cmpFunction: TStringComparisonFunc):string; overload; |
|
function getAttribute(const a: string; const def: string; const cmpFunction: TStringComparisonFunc = nil):string; overload; |
|
function getAttributeTry(const a: string; out valueout: string; const cmpFunction: TStringComparisonFunc = nil):boolean; |
|
function getAttributeTry(a: string; out valueout: TTreeAttribute; cmpFunction: TStringComparisonFunc = nil):boolean; |
|
function getPreviousSibling(): TTreeNode; |
|
function getNextSibling(): TTreeNode; |
|
function hasChildren(): boolean; inline; |
|
function getFirstChild(): TTreeNode; |
|
function getParent(): TTreeNode; |
|
function getPrevious(): TTreeNode; |
|
function getRootHighest(): TTreeNode; |
|
function getRootElement(): TTreeNode; |
|
function getDocument(): TTreeDocument; |
|
function getChildrenCount(types: TTreeNodeTypes): integer; |
|
function hasDocumentRoot(): boolean; |
|
function getNodeName(): string; |
|
function getNamespacePrefix(): string; |
|
function getNamespaceURL(): string; |
|
function getNamespaceURL(prefixOverride: string; cmpFunction: TStringComparisonFunc = nil): string; |
|
procedure getOwnNamespaces(var list: TNamespaceList); |
|
procedure getAllNamespaces(var list: TNamespaceList; first: boolean = true); |
|
function isNamespaceUsed(const n: TNamespace): boolean; |
|
function isDeepEqual(cmpTo: TTreeNode; ignoredTypes: TTreeNodeTypes = [tetComment, tetProcessingInstruction]; cmpFunction: TStringComparisonFunc = nil): boolean; |
|
procedure insert(el: TTreeNode); |
|
procedure insertSurrounding(before, after: TTreeNode); |
|
procedure insertSurrounding(basetag: TTreeNode); |
|
procedure addAttribute(a: TTreeAttribute); |
|
function addAttribute(const aname, avalue: string): TTreeAttribute; |
|
procedure addNamespaceDeclaration(n: TNamespace; overrides: boolean ); |
|
procedure addNamespaceDeclaration(const prefix, url: string; overrides: boolean ); |
|
procedure addChild(child: TTreeNode); |
|
procedure removeAttribute(a: TTreeAttribute); |
|
function cloneShallowNoAttributes(targetDocument: TTreeDocument; newRoot: TTreeNode; var newBaseOffset: TTreeNodeIntOffset): TTreeNode; |
|
function clone(targetDocument: TTreeDocument; newRoot: TTreeNode; var newBaseOffset: TTreeNodeIntOffset): TTreeNode; virtual; |
|
function clone(targetDocument: TTreeDocument): TTreeNode; |
|
function toString(): string; reintroduce; |
|
constructor Create; |
|
procedure FreeInstance; override; |
|
destructor destroy(); override; |
|
function caseInsensitiveCompare(const a,b: string): boolean; |
|
function caseSensitiveCompare(const a,b: string): boolean; |
|
class function compareInDocumentOrder(const a,b: TTreeNode): integer; static; |
Properties
property defaultProperty[name: string]: string read getAttribute; |
Description
Fields
typ: TTreeNodeType; |
|
open, close, text or comment node |
value: string; |
|
tag name for open/close nodes, text for text/comment nodes |
hash: TNodeNameHash; |
|
nodeNameHash(value) |
attributes: TTreeAttribute; |
|
nil if there are no attributes |
next: TTreeNode; |
|
|
previous: TTreeNode; |
|
|
parent: TTreeNode; |
|
root: TTreeNode; |
|
reverse: TTreeNode; |
|
element paired by open/closing, or corresponding attributes |
namespace: TNamespace; |
|
Currently local |
offset: TTreeNodeIntOffset; |
|
count of characters in the document before this element (so document_pchar + |
Methods
procedure freeAll(); |
|
deletes the tree |
function findNext(withTyp: TTreeNodeType; const withText:string; findOptions: TTreeNodeFindOptions=[]; sequenceEnd: TTreeNode = nil):TTreeNode; |
|
Returns the element with the given type and text which occurs before sequenceEnd. |
function findChild(withTyp: TTreeNodeType; const withText:string; findOptions: TTreeNodeFindOptions=[]): TTreeNode; |
|
Find a matching direct child (equivalent to findNext with certain parameters, but easier to use) |
function getEnumeratorAttributes: TTreeAttributeEnumerator; |
|
function getEnumeratorChildren: TTreeNodeEnumerator; |
|
function getEnumeratorDescendants: TTreeNodeEnumerator; |
|
function getEnumeratorAncestors: TTreeNodeEnumerator; |
|
function getEnumeratorPreceding: TTreeNodeEnumerator; |
|
function getEnumeratorFollowing: TTreeNodeEnumerator; |
|
function getEnumeratorPrecedingSiblings: TTreeNodeEnumerator; |
|
function getEnumeratorFollowingSiblings: TTreeNodeEnumerator; |
|
function deepNodeText(separator: string=''):string; |
|
function outerXML(insertLineBreaks: boolean = false):string; |
|
function innerXML(insertLineBreaks: boolean = false):string; |
|
function outerHTML(insertLineBreaks: boolean = false):string; |
|
function innerHTML(insertLineBreaks: boolean = false):string; |
|
function innerText():string; |
|
Returns a human readable text for an HTML node. The exact output might change in future version (e.g. more/less line breaks) |
class function innerTextRangeInternal(from, till_excluding: TTreeNode): string; static; |
|
function getValue(): string; |
|
get the value of this element |
function getValueTry(out valueout:string): boolean; |
|
get the value of this element if the element exists |
function getStringValue(): string; |
|
function hasAttribute(const a: string; const cmpFunction: TStringComparisonFunc = nil): boolean; |
|
returns if an attribute with that name exists. cmpFunction controls is used to compare the attribute name the searched string. (can be used to switch between case/in/sensitive) |
function getAttribute(const a: string):string; overload; |
|
get the value of an attribute of this element or '' if this attribute doesn't exist cmpFunction controls is used to compare the attribute name the searched string. (can be used to switch between case/in/sensitive) |
function getAttribute(const a: string; const cmpFunction: TStringComparisonFunc):string; overload; |
|
get the value of an attribute of this element or '' if this attribute doesn't exist cmpFunction controls is used to compare the attribute name the searched string. (can be used to switch between case/in/sensitive) |
function getAttribute(const a: string; const def: string; const cmpFunction: TStringComparisonFunc = nil):string; overload; |
|
get the value of an attribute of this element or '' if this attribute doesn't exist cmpFunction controls is used to compare the attribute name the searched string. (can be used to switch between case/in/sensitive) |
function getAttributeTry(const a: string; out valueout: string; const cmpFunction: TStringComparisonFunc = nil):boolean; |
|
get the value of an attribute of this element and returns false if it doesn't exist cmpFunction controls is used to compare the attribute name the searched string. (can be used to switch between case/in/sensitive) |
function getAttributeTry(a: string; out valueout: TTreeAttribute; cmpFunction: TStringComparisonFunc = nil):boolean; |
|
get the value of an attribute of this element and returns false if it doesn't exist cmpFunction controls is used to compare the attribute name the searched string. (can be used to switch between case/in/sensitive) |
function getPreviousSibling(): TTreeNode; |
|
Get the previous element on the same level or nil if there is none |
function getNextSibling(): TTreeNode; |
|
Get the next element on the same level or nil if there is none |
function hasChildren(): boolean; inline; |
|
function getFirstChild(): TTreeNode; |
|
Get the first child, or nil if there is none |
function getParent(): TTreeNode; |
|
Searchs the parent |
function getPrevious(): TTreeNode; |
|
Searchs the previous |
function getRootHighest(): TTreeNode; |
|
Returns the highest node ancestor |
function getRootElement(): TTreeNode; |
|
Returns the highest element node ancestor |
function getDocument(): TTreeDocument; |
|
Returns the document node containing this node. Raises an exception if there is no associated document |
function getChildrenCount(types: TTreeNodeTypes): integer; |
|
function hasDocumentRoot(): boolean; |
|
function getNodeName(): string; |
|
Returns the name as namespaceprefix:name if a namespace exists, or name otherwise. Only attributes, elements and PIs have names. |
function getNamespacePrefix(): string; |
|
Returns the namespace prefix. (i.e. 'a' for 'a:b', '' for 'b') |
function getNamespaceURL(): string; |
|
Returns the namespace url. (very slow, it searches the parents for a matching xmlns attribute) cmpFunction controls is used to compare the xmlns: attribute name the searched string. (can be used to switch between case/in/sensitive) |
function getNamespaceURL(prefixOverride: string; cmpFunction: TStringComparisonFunc = nil): string; |
|
Returns the url of a namespace prefix, defined in this element or one of his parents cmpFunction controls is used to compare the xmlns: attribute name the searched string. (can be used to switch between case/in/sensitive) |
procedure getOwnNamespaces(var list: TNamespaceList); |
|
Returns all namespaces declared or used in this element and its attributes |
procedure getAllNamespaces(var list: TNamespaceList; first: boolean = true); |
|
Returns all namespaces declared/used by this element and all ancestors |
function isNamespaceUsed(const n: TNamespace): boolean; |
|
Tests if a namespace is used by this element or any child (same prefix + url) |
function isDeepEqual(cmpTo: TTreeNode; ignoredTypes: TTreeNodeTypes = [tetComment, tetProcessingInstruction]; cmpFunction: TStringComparisonFunc = nil): boolean; |
|
procedure insert(el: TTreeNode); |
|
inserts el after the current element (does only change next+previous, not reverse+parent) |
procedure insertSurrounding(before, after: TTreeNode); |
|
Surrounds self by before and after, i.e. inserts "before" directly before the element and "after" directly after its closing tag (slow) |
procedure insertSurrounding(basetag: TTreeNode); |
|
inserts basetag before the current tag, and creates a matching closing tag after the closing tag of self (slow) |
procedure addAttribute(a: TTreeAttribute); |
|
function addAttribute(const aname, avalue: string): TTreeAttribute; |
|
procedure addNamespaceDeclaration(n: TNamespace; overrides: boolean ); |
|
procedure addNamespaceDeclaration(const prefix, url: string; overrides: boolean ); |
|
procedure addChild(child: TTreeNode); |
|
procedure removeAttribute(a: TTreeAttribute); |
|
function cloneShallowNoAttributes(targetDocument: TTreeDocument; newRoot: TTreeNode; var newBaseOffset: TTreeNodeIntOffset): TTreeNode; |
|
function clone(targetDocument: TTreeDocument; newRoot: TTreeNode; var newBaseOffset: TTreeNodeIntOffset): TTreeNode; virtual; |
|
function clone(targetDocument: TTreeDocument): TTreeNode; |
|
function toString(): string; reintroduce; |
|
converts the element to a string (not recursive) |
constructor Create; |
|
procedure FreeInstance; override; |
|
destructor destroy(); override; |
|
function caseInsensitiveCompare(const a,b: string): boolean; |
|
returns true if a=b case insensitive. Can be passed to getAttribute |
function caseSensitiveCompare(const a,b: string): boolean; |
|
returns true if a=b case sensitive. Can be passed to getAttribute |
class function compareInDocumentOrder(const a,b: TTreeNode): integer; static; |
|
Properties
property defaultProperty[name: string]: string read getAttribute; |
|
Generated by PasDoc 0.16.0.