Castle Game EngineIntroduction Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers
|
Class TDOMElementHelper
Unit
CastleXMLUtils
Declaration
type TDOMElementHelper = class helper(TObject) for TDOMElement
Description
Hierarchy
- TObject
- TDOMElementHelper
Overview
Methods
Description
Methods
 |
function AttributeString(const AttrName: string; var Value: string): boolean; overload; |
Read from Element attribute value and returns True , or (if there is no such attribute) returns False and does not modify Value. Value is a "var", not "out" param, because in the latter case it's guaranteed that the old Value will not be cleared.
Note that the returned Value may be empty, even when this returns True , if the value is explicitly set to empty in XML (by xxx="" in XML).
|
 |
function AttributeURL(const AttrName: string; const BaseUrl: string; var URL: string): boolean; overload; |
Read from Element attribute value as URL and returns True , or (if there is no such attribute) returns False and does not modify Value.
Returned URL is always absolute. The value in file may be a relative URL, it is resolved with respect to BaseUrl, that must be absolute.
|
 |
function AttributeCardinal(const AttrName: string; var Value: Cardinal): boolean; overload; |
Read from Element attribute value as Cardinal and returns True , or (if there is no such attribute) returns False and does not modify Value.
|
 |
function AttributeInteger(const AttrName: string; var Value: Integer): boolean; overload; |
Read from Element attribute value as Integer and returns True , or (if there is no such attribute) returns False and does not modify Value.
|
 |
function AttributeInt64(const AttrName: string; var Value: Int64): boolean; overload; |
Read from Element attribute value as Int64 and returns True , or (if there is no such attribute) returns False and does not modify Value.
|
 |
function AttributeSingle(const AttrName: string; var Value: Single): boolean; overload; |
Read from Element attribute value as Single and returns True , or (if there is no such attribute) returns False and does not modify Value.
|
 |
function AttributeFloat(const AttrName: string; var Value: Float): boolean; overload; |
Read from Element attribute value as Float and returns True , or (if there is no such attribute) returns False and does not modify Value.
Note: for powerful reading of float expressions, consider using AttributeFloatExpression instead of AttributeFloat . It can read expressions like "3.0 * 2.0" or "sin(2.0)" . Use CastleScriptXML unit to introduce necessary class helper for this, see TDOMElementScriptHelper.AttributeFloatExpression.
|
 |
function AttributeBoolean(const AttrName: string; var Value: boolean): boolean; overload; |
Read from Element attribute value as Boolean and returns True , or (if there is no such attribute) returns False and does not modify Value.
A boolean value is interpreted just like FPC's TXMLConfig objects: true is designated by word true , false by word false , case is ignored. If attribute exists but it's value is not true or false , then returns False and doesn't modify Value paramater. So behaves just like the attribute didn't exist.
|
 |
function AttributeColor(const AttrName: string; var Value: TCastleColor): boolean; overload; |
Read from Element attribute value as color and returns True , or (if there is no such attribute) returns False and does not modify Value.
|
 |
function AttributeColorRGB(const AttrName: string; var Value: TCastleColorRGB): boolean; overload; |
Read from Element attribute value as RGB color and returns True , or (if there is no such attribute) returns False and does not modify Value.
|
 |
function AttributeVector2(const AttrName: string; var Value: TVector2): boolean; overload; |
Read from Element attribute as a 2D vector (2 floats), and returns True , or (if there is no such attribute) returns False and does not modify Value.
Exceptions raised
EConvertError
- If the attribute exists in XML, but has invalid format.
|
 |
function AttributeVector3(const AttrName: string; var Value: TVector3): boolean; overload; |
Read from Element attribute as a 3D vector (3 floats), and returns True , or (if there is no such attribute) returns False and does not modify Value.
Exceptions raised
EConvertError
- If the attribute exists in XML, but has invalid format.
|
 |
function AttributeString(const AttrName: string): string; overload; |
Retrieves from Element given attribute as a string, raises EDOMAttributeMissing if missing.
Note that the attribute is required, but it's value may still be empty if it's explicitly set to empty in XML (by xxx="" in XML). This is different than TCastleConfig.GetStringNonEmpty method, that serves a similar purpose for TCastleConfig, but it requires non-empty value exists. Here, we only require that the value exists, but it may still be empty.
Exceptions raised
- EDOMAttributeMissing
|
 |
function AttributeURL(const AttrName: string; const BaseUrl: string): string; overload; |
Retrieves from Element given attribute as an absolute URL, raises EDOMAttributeMissing if missing. Returned URL is always absolute. The value in file may be a relative URL, it is resolved with respect to BaseUrl, that must be absolute.
Exceptions raised
- EDOMAttributeMissing
|
 |
function AttributeCardinal(const AttrName: string): Cardinal; overload; |
Retrieves from Element given attribute as a Cardinal, raises EDOMAttributeMissing if missing.
Exceptions raised
- EDOMAttributeMissing
|
 |
function AttributeInteger(const AttrName: string): Integer; overload; |
Retrieves from Element given attribute as an Integer, raises EDOMAttributeMissing if missing.
Exceptions raised
- EDOMAttributeMissing
|
 |
function AttributeBoolean(const AttrName: string): boolean; overload; |
Retrieves from Element given attribute as a boolean, raises EDOMAttributeMissing if missing or has invalid value. A boolean value is interpreted just like FPC's TXMLConfig objects: true is designated by word true , false by word false , case is ignored.
If attribute exists but it's value is not true or false , then raises EDOMAttributeMissing. So behaves just like the attribute didn't exist.
Exceptions raised
- EDOMAttributeMissing
|
 |
function AttributeStringDef(const AttrName: string; const DefaultValue: string): string; |
Retrieves from Element given attribute as a string, or a default value if the attribute was not explicitly given.
|
 |
function AttributeCardinalDef(const AttrName: string; const DefaultValue: Cardinal): Cardinal; |
Retrieves from Element given attribute as a Cardinal, or a default value.
|
 |
function AttributeIntegerDef(const AttrName: string; const DefaultValue: Integer): Integer; |
Retrieves from Element given attribute as an Integer, or a default value.
|
 |
function AttributeInt64Def(const AttrName: string; const DefaultValue: Int64): Int64; |
Retrieves from Element given attribute as an Int64, or a default value.
|
 |
function AttributeSingleDef(const AttrName: string; const DefaultValue: Single): Single; |
Retrieves from Element given attribute as a Single, or a default value.
|
 |
function AttributeFloatDef(const AttrName: string; const DefaultValue: Float): Float; |
Retrieves from Element given attribute as a Float, or a default value.
Note: for powerful reading of float expressions, consider using AttributeFloatExpressionDef instead of AttributeFloatDef . It can read expressions like "3.0 * 2.0" or "sin(2.0)" . Use CastleScriptXML unit to introduce necessary class helper for this, see TDOMElementScriptHelper.AttributeFloatExpressionDef.
|
 |
function AttributeBooleanDef(const AttrName: string; const DefaultValue: boolean): boolean; |
Retrieves from Element given attribute as a boolean, returns a default value if missing or has invalid value.
|
 |
function AttributeColorDef(const AttrName: string; const DefaultValue: TCastleColor): TCastleColor; |
Retrieves from Element given attribute as a color, or a default value.
|
 |
function AttributeColorRGBDef(const AttrName: string; const DefaultValue: TCastleColorRGB): TCastleColorRGB; |
Retrieves from Element given attribute as an RGB color, or a default value.
|
 |
function AttributeVector2Def(const AttrName: string; const DefaultValue: TVector2): TVector2; |
Retrieves from Element given attribute as a 2D vector (2 floats), or a default value.
Exceptions raised
EConvertError
- If the value exists in XML, but has invalid format.
|
 |
function AttributeVector3Def(const AttrName: string; const DefaultValue: TVector3): TVector3; |
Retrieves from Element given attribute as a 3D vector (3 floats), or a default value.
Exceptions raised
EConvertError
- If the value exists in XML, but has invalid format.
|
 |
procedure AttributeSet(const AttrName: string; const Value: string); overload; |
Set the attribute as string. Equivalent to standard SetAttribute in DOM unit, but provided here for consistency with other AttributeSet overloads.
|
 |
procedure AttributeSet(const AttrName: string; const Value: boolean); overload; |
Set the attribute as boolean, such that it's readable back by AttributeBoolean and AttributeBooleanDef.
|
 |
procedure AttributeSet(const AttrName: string; const Value: Integer); overload; |
Set the attribute as Integer, such that it's readable back by AttributeInteger and AttributeIntegerDef.
|
 |
procedure AttributeSet(const AttrName: string; const Value: Int64); overload; |
Set the attribute as Int64, such that it's readable back by AttributeInt64 and AttributeInt64Def.
|
 |
procedure AttributeSet(const AttrName: string; const Value: Cardinal); overload; |
Set the attribute as Cardinal, such that it's readable back by AttributeCardinal and AttributeCardinalDef.
|
 |
procedure AttributeSet(const AttrName: string; const Value: Single); overload; |
Set the attribute as Int64, such that it's readable back by AttributeSingle and AttributeSingleDef.
|
 |
function ChildElement(const ChildName: string; const Required: boolean = true): TDOMElement; |
Get child element with given ChildName.
For example use LevelElement.ChildElement('items') to get the <items> element within <level> element, as in example below.
<level>
<creatures>
...
</creatures>
<items>
...
</items>
</level>
There must be one and only one child element with this name. In case there's zero, or more than one such element, we will raise EDOMChildElementError (if Required is True , default) or return Nil (if Required is False ).
Exceptions raised
- EDOMChildElementError
- If child not found (or found more than once), and Required =
True .
|
 |
function ChildrenIterator: TXMLElementIterator; overload; |
Iterator over all children elements. Use like this:
var
I: TXMLElementIterator;
begin
I := Element.ChildrenIterator;
try
while I.GetNext do
begin
end;
finally FreeAndNil(I) end;
end;
|
 |
function ChildrenIterator(const ChildName: string): TXMLElementIterator; overload; |
Iterator over all children elements named ChildName. Use like this:
var
I: TXMLElementIterator;
begin
I := Element.ChildrenIterator('item');
try
while I.GetNext do
begin
end;
finally FreeAndNil(I) end;
end;
|
 |
function TextData: string; |
The text data contained in this element.
This is suitable if an element is supposed to contain only some text. Like <some_value>This is a text inside.</some_value> . It raises an error if an element contains anything else as child.
If there are no text data nodes, e.g. if the element is empty, it returns empty string without raising any error.
|
 |
function TagName8: string; |
Tag name (element name). Expressed as an 8-bit string (in UTF-8 encoding), contrary to the TagName from FPC DOM unit that is a WideString (DOMString).
|
Generated by PasDoc 0.15.0.
|