Class TTreeNode

DescriptionHierarchyFieldsMethodsProperties

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. a 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

Public typ: TTreeNodeType;
Public value: string;
Public hash: cardinal;
Public attributes: TAttributeList;
Public next: TTreeNode;
Public previous: TTreeNode;
Public parent: TTreeNode;
Public document: TTreeNode;
Public reverse: TTreeNode;
Public namespace: INamespace;
Public offset: longint;

Methods

Public procedure deleteAll();
Public procedure changeEncoding(from,toe: TSystemCodePage; substituteEntities: boolean; trimText: boolean);
Public function findNext(withTyp: TTreeNodeType; const withText:string; findOptions: TTreeNodeFindOptions=[]; sequenceEnd: TTreeNode = nil):TTreeNode;
Public function findChild(withTyp: TTreeNodeType; const withText:string; findOptions: TTreeNodeFindOptions=[]): TTreeNode;
Public function deepNodeText(separator: string=''):string;
Public function outerXML(insertLineBreaks: boolean = false):string;
Public function innerXML(insertLineBreaks: boolean = false):string;
Public function outerHTML(insertLineBreaks: boolean = false):string;
Public function innerHTML(insertLineBreaks: boolean = false):string;
Public function getValue(): string;
Public function getValueTry(out valueout:string): boolean;
Public function hasAttribute(const a: string; const cmpFunction: TStringComparisonFunc = nil): boolean;
Public function getAttribute(const a: string):string; overload;
Public function getAttribute(const a: string; const cmpFunction: TStringComparisonFunc):string; overload;
Public function getAttribute(const a: string; const def: string; const cmpFunction: TStringComparisonFunc = nil):string; overload;
Public function getAttributeTry(const a: string; out valueout: string; const cmpFunction: TStringComparisonFunc = nil):boolean;
Public function getAttributeTry(a: string; out valueout: TTreeAttribute; cmpFunction: TStringComparisonFunc = nil):boolean;
Public function getAttributeCount(): integer;
Public function getPreviousSibling(): TTreeNode;
Public function getNextSibling(): TTreeNode;
Public function getFirstChild(): TTreeNode;
Public function getParent(): TTreeNode;
Public function getPrevious(): TTreeNode;
Public function getRootHighest(): TTreeNode;
Public function getRootElement(): TTreeNode;
Public function getDocument(): TTreeDocument;
Public function hasDocument(): boolean;
Public function getChildrenCount(types: TTreeNodeTypes): integer;
Public function getNodeName(): string;
Public function getNamespacePrefix(): string;
Public function getNamespaceURL(): string;
Public function getNamespaceURL(prefixOverride: string; cmpFunction: TStringComparisonFunc = nil): string;
Public procedure getOwnNamespaces(var list: TNamespaceList);
Public procedure getAllNamespaces(var list: TNamespaceList; first: boolean = true);
Public function isNamespaceUsed(const n: INamespace): boolean;
Public function isDeepEqual(cmpTo: TTreeNode; ignoredTypes: TTreeNodeTypes = [tetComment, tetProcessingInstruction]; cmpFunction: TStringComparisonFunc = nil): boolean;
Public procedure insert(el: TTreeNode);
Public procedure insertSurrounding(before, after: TTreeNode);
Public procedure insertSurrounding(basetag: TTreeNode);
Public procedure addAttribute(const aname, avalue: string; const anamespace: TNamespace = nil); inline;
Public procedure addAttributes(const props: array of THTMLProperty);
Public procedure addNamespaceDeclaration(n: INamespace; overridens: boolean );
Public procedure addChild(child: TTreeNode);
Public procedure removeElementFromDoubleLinkedList;
Public function deleteElementFromDoubleLinkedList: TTreeNode;
Public function clone: TTreeNode; virtual;
Public function toString(): string; reintroduce;
Public function toString(includeText: boolean; includeAttributes: array of string): string; reintroduce;
Public constructor create(); virtual;
Public constructor create(atyp: TTreeNodeType; avalue: string = ''); virtual;
Public class function createElementPair(const anodename: string): TTreeNode;
Public destructor destroy(); override;
Public procedure initialized; virtual;
Public function caseInsensitiveCompare(const a,b: string): boolean;
Public function caseSensitiveCompare(const a,b: string): boolean;
Public class function compareInDocumentOrder(const a,b: TTreeNode): integer; static;

Properties

Public property defaultProperty[name:string]: string read getAttribute;

Description

Fields

Public typ: TTreeNodeType;

open, close, text or comment node

Public value: string;

tag name for open/close nodes, text for text/comment nodes

Public hash: cardinal;

nodeNameHash(value)

Public attributes: TAttributeList;

nil if there are no attributes

Public next: TTreeNode;

next element as in the file (first child if there are childs, else next on lowest level), so elements form a linked list

Public previous: TTreeNode;

previous element (self.next.previous = self)

Public parent: TTreeNode;
 
Public document: TTreeNode;
 
Public reverse: TTreeNode;

element paired by open/closing, or corresponding attributes

Public namespace: INamespace;

Currently local namespace prefix. Might be changed to a pointer to a namespace map in future. (so use getNamespacePrefix and getNamespaceURL instead)

Public offset: longint;

count of characters in the document before this element (so document_pchar + offset begins with value)

Methods

Public procedure deleteAll();

deletes the tree

Public procedure changeEncoding(from,toe: TSystemCodePage; substituteEntities: boolean; trimText: boolean);

converts the tree encoding from encoding from to toe, and substitutes entities (e.g &auml;)

Public 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.
This function is nil-safe, so if you call TTreeNode(nil).findNext(...) it will return nil

Public 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)
A direct child of X is a node Y with Y.parent = X.
The options tefoNoChildren, tefoNoGrandChildren have of course no effect. (former is set to false, latter to true)

Public function deepNodeText(separator: string=''):string;

concatenates the text of all (including indirect) text children

Public function outerXML(insertLineBreaks: boolean = false):string;
 
Public function innerXML(insertLineBreaks: boolean = false):string;
 
Public function outerHTML(insertLineBreaks: boolean = false):string;
 
Public function innerHTML(insertLineBreaks: boolean = false):string;
 
Public function getValue(): string;

get the value of this element

Public function getValueTry(out valueout:string): boolean;

get the value of this element if the element exists

Public 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)

Public 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)

Public 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)

Public 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)

Public 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)

Public 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)

Public function getAttributeCount(): integer;
 
Public function getPreviousSibling(): TTreeNode;

Get the previous element on the same level or nil if there is none

Public function getNextSibling(): TTreeNode;

Get the next element on the same level or nil if there is none

Public function getFirstChild(): TTreeNode;

Get the first child, or nil if there is none

Public function getParent(): TTreeNode;

Searchs the parent, notice that this is a slow function (neither the parent nor previous elements are stored in the tree, so it has to search the last sibling)

Public function getPrevious(): TTreeNode;

Searchs the previous, notice that this is a slow function (neither the parent nor previous elements are stored in the tree, so it has to search the last sibling)

Public function getRootHighest(): TTreeNode;

Returns the highest node ancestor

Public function getRootElement(): TTreeNode;

Returns the highest element node ancestor

Public function getDocument(): TTreeDocument;

Returns the document node containing this node. Raises an exception if there is no associated document

Public function hasDocument(): boolean;

Returns if this node is contained in a document

Public function getChildrenCount(types: TTreeNodeTypes): integer;
 
Public function getNodeName(): string;

Returns the name as namespaceprefix:name if a namespace exists, or name otherwise. Only attributes, elements and PIs have names.

Public function getNamespacePrefix(): string;

Returns the namespace prefix. (i.e. 'a' for 'a:b', '' for 'b')

Public 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)

Public 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)

Public procedure getOwnNamespaces(var list: TNamespaceList);

Returns all namespaces declared or used in this element and its attributes

Public procedure getAllNamespaces(var list: TNamespaceList; first: boolean = true);

Returns all namespaces declared/used by this element and all ancestors

Public function isNamespaceUsed(const n: INamespace): boolean;

Tests if a namespace is used by this element or any child (same prefix + url)

Public function isDeepEqual(cmpTo: TTreeNode; ignoredTypes: TTreeNodeTypes = [tetComment, tetProcessingInstruction]; cmpFunction: TStringComparisonFunc = nil): boolean;
 
Public procedure insert(el: TTreeNode);

inserts el after the current element (does only change next+previous, not reverse+parent)

Public 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)

Public procedure insertSurrounding(basetag: TTreeNode);

inserts basetag before the current tag, and creates a matching closing tag after the closing tag of self (slow)

Public procedure addAttribute(const aname, avalue: string; const anamespace: TNamespace = nil); inline;
 
Public procedure addAttributes(const props: array of THTMLProperty);
 
Public procedure addNamespaceDeclaration(n: INamespace; overridens: boolean );
 
Public procedure addChild(child: TTreeNode);
 
Public procedure removeElementFromDoubleLinkedList;
 
Public function deleteElementFromDoubleLinkedList: TTreeNode;
 
Public function clone: TTreeNode; virtual;
 
Public function toString(): string; reintroduce;

converts the element to a string (not recursive)

Public function toString(includeText: boolean; includeAttributes: array of string): string; reintroduce;

converts the element to a string (not recursive)

Public constructor create(); virtual;
 
Public constructor create(atyp: TTreeNodeType; avalue: string = ''); virtual;
 
Public class function createElementPair(const anodename: string): TTreeNode;
 
Public destructor destroy(); override;
 
Public procedure initialized; virtual;

is called after an element is read, before the next one is read (therefore all fields are valid except next (and reverse for opening tags))

Public function caseInsensitiveCompare(const a,b: string): boolean;

returns true if a=b case insensitive. Can be passed to getAttribute

Public function caseSensitiveCompare(const a,b: string): boolean;

returns true if a=b case sensitive. Can be passed to getAttribute

Public class function compareInDocumentOrder(const a,b: TTreeNode): integer; static;
 

Properties

Public property defaultProperty[name:string]: string read getAttribute;
 

Generated by PasDoc 0.14.0.